From c52f75c9e3a1fdbf48cf21aa207264701ab991bc Mon Sep 17 00:00:00 2001 From: Keagan McClelland Date: Wed, 24 Feb 2021 15:19:44 -0700 Subject: [PATCH] adds lanEnabled, and unconditionally returns lan address --- agent/src/Handler/Apps.hs | 35 +++++++++++++++------------------ agent/src/Handler/Types/Apps.hs | 4 ++++ 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/agent/src/Handler/Apps.hs b/agent/src/Handler/Apps.hs index 4ddf9ea39..802a4124f 100644 --- a/agent/src/Handler/Apps.hs +++ b/agent/src/Handler/Apps.hs @@ -250,25 +250,22 @@ getInstalledAppsLogic = do , appInstalledPreviewVersionInstalled = storeAppVersionInfoVersion , appInstalledPreviewTorAddress = Nothing , appInstalledPreviewLanAddress = Nothing + , appInstalledPreviewLanEnabled = Nothing , appInstalledPreviewUi = False } installedPreviews = flip HML.mapWithKey remapped - \appId (s, v, AppMgr2.InfoRes {..}) -> AppInstalledPreview - { appInstalledPreviewBase = AppBase appId infoResTitle (iconUrl appId v) - , appInstalledPreviewStatus = s - , appInstalledPreviewVersionInstalled = v - , appInstalledPreviewTorAddress = infoResTorAddress - , appInstalledPreviewLanAddress = if appId `HM.member` lanCache - then - LanAddress - . (".onion" `Text.replace` ".local") - . unTorAddress - <$> infoResTorAddress - else Nothing - , appInstalledPreviewUi = AppManifest.uiAvailable infoResManifest - } + \appId (s, v, AppMgr2.InfoRes {..}) -> + let lanAddress = LanAddress . (".onion" `Text.replace` ".local") . unTorAddress <$> infoResTorAddress + in AppInstalledPreview { appInstalledPreviewBase = AppBase appId infoResTitle (iconUrl appId v) + , appInstalledPreviewStatus = s + , appInstalledPreviewVersionInstalled = v + , appInstalledPreviewTorAddress = infoResTorAddress + , appInstalledPreviewLanAddress = lanAddress + , appInstalledPreviewLanEnabled = lanAddress $> HM.member appId lanCache + , appInstalledPreviewUi = AppManifest.uiAvailable infoResManifest + } pure $ HML.elems $ HML.union installingPreviews installedPreviews @@ -300,6 +297,7 @@ getInstalledAppByIdLogic appId = do , appInstalledFullLastBackup = backupTime , appInstalledFullTorAddress = Nothing , appInstalledFullLanAddress = Nothing + , appInstalledFullLanEnabled = Nothing , appInstalledFullConfiguredRequirements = [] , appInstalledFullUninstallAlert = Nothing , appInstalledFullRestoreAlert = Nothing @@ -334,11 +332,8 @@ getInstalledAppByIdLogic appId = do manifest <- lift $ LAsync.wait manifest' instructions <- lift $ LAsync.wait instructions' backupTime <- lift $ LAsync.wait backupTime' - lans <- asks appLanThreads - lanEnabled <- liftIO $ HM.member appId <$> readTVarIO lans - let lanAddress = if lanEnabled - then LanAddress . (".onion" `Text.replace` ".local") . unTorAddress <$> infoResTorAddress - else Nothing + lanCache <- asks appLanThreads >>= liftIO . readTVarIO + let lanAddress = LanAddress . (".onion" `Text.replace` ".local") . unTorAddress <$> infoResTorAddress pure AppInstalledFull { appInstalledFullBase = AppBase appId infoResTitle (iconUrl appId version) , appInstalledFullStatus = status , appInstalledFullVersionInstalled = version @@ -346,6 +341,7 @@ getInstalledAppByIdLogic appId = do , appInstalledFullLastBackup = backupTime , appInstalledFullTorAddress = infoResTorAddress , appInstalledFullLanAddress = lanAddress + , appInstalledFullLanEnabled = lanAddress $> HM.member appId lanCache , appInstalledFullConfiguredRequirements = HM.elems requirements , appInstalledFullUninstallAlert = manifest >>= AppManifest.appManifestUninstallAlert , appInstalledFullRestoreAlert = manifest >>= AppManifest.appManifestRestoreAlert @@ -800,6 +796,7 @@ postEnableLanLogic :: (Has (Reader AgentCtx) sig m, Has AppMgr2.AppMgr sig m, Mo -> m () postEnableLanLogic appId = do cache <- asks appLanThreads + action <- const () <<$>> LAsync.async (AppMgr2.lanEnable appId) -- unconditionally drops monad state from the action liftIO $ atomically $ modifyTVar' cache (HM.insert appId action) diff --git a/agent/src/Handler/Types/Apps.hs b/agent/src/Handler/Types/Apps.hs index da9d5a3e8..35598c68a 100644 --- a/agent/src/Handler/Types/Apps.hs +++ b/agent/src/Handler/Types/Apps.hs @@ -47,6 +47,7 @@ data AppInstalledPreview = AppInstalledPreview , appInstalledPreviewVersionInstalled :: Version , appInstalledPreviewTorAddress :: Maybe TorAddress , appInstalledPreviewLanAddress :: Maybe LanAddress + , appInstalledPreviewLanEnabled :: Maybe Bool , appInstalledPreviewUi :: Bool } deriving (Eq, Show) @@ -56,6 +57,7 @@ instance ToJSON AppInstalledPreview where , "versionInstalled" .= appInstalledPreviewVersionInstalled , "torAddress" .= (unTorAddress <$> appInstalledPreviewTorAddress) , "lanAddress" .= (unLanAddress <$> appInstalledPreviewLanAddress) + , "lanEnabled" .= appInstalledPreviewLanEnabled , "ui" .= appInstalledPreviewUi ] @@ -133,6 +135,7 @@ data AppInstalledFull = AppInstalledFull , appInstalledFullVersionInstalled :: Version , appInstalledFullTorAddress :: Maybe TorAddress , appInstalledFullLanAddress :: Maybe LanAddress + , appInstalledFullLanEnabled :: Maybe Bool , appInstalledFullInstructions :: Maybe Text , appInstalledFullLastBackup :: Maybe UTCTime , appInstalledFullConfiguredRequirements :: [Stripped AppDependencyRequirement] @@ -147,6 +150,7 @@ instance ToJSON AppInstalledFull where , "configuredRequirements" .= appInstalledFullConfiguredRequirements , "torAddress" .= (unTorAddress <$> appInstalledFullTorAddress) , "lanAddress" .= (unLanAddress <$> appInstalledFullLanAddress) + , "lanEnabled" .= appInstalledFullLanEnabled , "id" .= appBaseId appInstalledFullBase , "title" .= appBaseTitle appInstalledFullBase , "iconURL" .= appBaseIconUrl appInstalledFullBase