Skip to content

Commit b6f7984

Browse files
committed
Show pretty language names for help
1 parent 7989558 commit b6f7984

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

executables/MainCLI.hs

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ import Traduisons.Client
1212
import Traduisons.API
1313
import Traduisons.Types
1414

15+
1516
main :: IO ()
1617
main = do
17-
eitherAppState <- runExceptT createAppState
18+
eitherAppState <- runExceptT $ do
19+
emptyAppState <- createAppState
20+
-- Get an auth token before we do anything else.
21+
authAppState <- snd <$> runStateT renewToken emptyAppState
22+
updateLanguageMap authAppState
1823
case eitherAppState of
1924
Left err -> putStrLn ("Failed to initialize: " ++ renderError err)
20-
Right appState -> do
21-
-- Immediately get an auth token. This lowers our initial response time.
22-
void $ runExceptT (runStateT renewToken appState)
23-
runInputT defaultSettings (loop appState)
25+
Right appState -> runInputT defaultSettings (loop appState)
2426
where
2527
loop appState = do
2628
let promptString = renderAppState appState

executables/UI/QML.hs

+12-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ defaultGUIAppState = GAS False (Right "")
3939
runGUI :: AppState -> IO ()
4040
runGUI initialAppState = do
4141
qmlPath <- getDataFileName "executables/UI/ui.qml"
42-
asyncRenewToken initialAppState
4342
guiAppState <- newIORef (defaultGUIAppState [initialAppState])
43+
asyncInitAppState guiAppState
4444
langPairSignal <- newSignalKey
4545
gasResultSignal <- newSignalKey
4646
gasIsLoadingSignal <- newSignalKey
@@ -71,8 +71,17 @@ runGUI initialAppState = do
7171
where
7272
fireSignals keys obj = mapM_ (`fireSignal` obj) keys
7373

74-
asyncRenewToken :: AppState -> IO ()
75-
asyncRenewToken = void . forkIO . void . runExceptT . runStateT renewToken
74+
asyncInitAppState :: IORef GUIAppState -> IO ()
75+
asyncInitAppState gsRef = void . forkIO $ do
76+
gAS <- readIORef gsRef
77+
let (old:olds) = gasAppStates gAS
78+
new <- runExceptT $ do
79+
authed <- snd <$> runStateT renewToken old
80+
lift $ writeIORef gsRef gAS { gasAppStates = authed:olds }
81+
updateLanguageMap authed
82+
case new of
83+
Left err -> writeIORef gsRef gAS { gasResult = Left err }
84+
Right appState -> writeIORef gsRef gAS {gasAppStates = appState:olds}
7685

7786
clipboardContentsProperty :: IORef GUIAppState -> IO T.Text
7887
clipboardContentsProperty guiAppState = render <$> readIORef guiAppState

0 commit comments

Comments
 (0)