@@ -39,8 +39,8 @@ defaultGUIAppState = GAS False (Right "")
39
39
runGUI :: AppState -> IO ()
40
40
runGUI initialAppState = do
41
41
qmlPath <- getDataFileName " executables/UI/ui.qml"
42
- asyncRenewToken initialAppState
43
42
guiAppState <- newIORef (defaultGUIAppState [initialAppState])
43
+ asyncInitAppState guiAppState
44
44
langPairSignal <- newSignalKey
45
45
gasResultSignal <- newSignalKey
46
46
gasIsLoadingSignal <- newSignalKey
@@ -71,8 +71,17 @@ runGUI initialAppState = do
71
71
where
72
72
fireSignals keys obj = mapM_ (`fireSignal` obj) keys
73
73
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}
76
85
77
86
clipboardContentsProperty :: IORef GUIAppState -> IO T. Text
78
87
clipboardContentsProperty guiAppState = render <$> readIORef guiAppState
0 commit comments