From d4309864037bf135e9ecc5b057c07948f20c531e Mon Sep 17 00:00:00 2001 From: Keagan McClelland Date: Fri, 5 Mar 2021 17:20:37 -0700 Subject: [PATCH] adds availability to installed full --- agent/src/Handler/Apps.hs | 34 +++++++++++++++++++++------------ agent/src/Handler/Types/Apps.hs | 6 +++++- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/agent/src/Handler/Apps.hs b/agent/src/Handler/Apps.hs index e6548f550..eb2f40a15 100644 --- a/agent/src/Handler/Apps.hs +++ b/agent/src/Handler/Apps.hs @@ -303,6 +303,8 @@ getInstalledAppByIdLogic appId = do , appInstalledFullLastBackup = backupTime , appInstalledFullTorAddress = Nothing , appInstalledFullLanAddress = Nothing + , appInstalledFullTorUi = False + , appInstalledFullLanUi = False , appInstalledFullConfiguredRequirements = [] , appInstalledFullUninstallAlert = Nothing , appInstalledFullRestoreAlert = Nothing @@ -335,22 +337,30 @@ getInstalledAppByIdLogic appId = do (HM.lookup depId installCache $> AppStatusTmp Installing) <|> (view _1 <$> HM.lookup depId remapped) pure $ dependencyInfoToDependencyRequirement (AsInstalled STrue) (base, depStatus, depInfo) - manifest <- lift $ LAsync.wait manifest' + manifest <- (lift $ LAsync.wait manifest') >>= \case + Nothing -> throwError $ NotFoundE "manifest" (show appId) + Just x -> pure x instructions <- lift $ LAsync.wait instructions' backupTime <- lift $ LAsync.wait backupTime' - let lanAddress = LanAddress . (".onion" `Text.replace` ".local") . unTorAddress <$> infoResTorAddress + let lanAddress = do + addrBase <- infoResTorAddress + let lanConfs = mapMaybe AppManifest.portMapEntryLan $ AppManifest.appManifestPortMapping manifest + guard (not . null $ lanConfs) + pure $ LanAddress . (".onion" `Text.replace` ".local") . unTorAddress $ addrBase pure AppInstalledFull { appInstalledFullBase = AppBase appId infoResTitle (iconUrl appId version) - , appInstalledFullStatus = status - , appInstalledFullVersionInstalled = version - , appInstalledFullInstructions = instructions - , appInstalledFullLastBackup = backupTime - , appInstalledFullTorAddress = infoResTorAddress - , appInstalledFullLanAddress = lanAddress + , appInstalledFullStatus = status + , appInstalledFullVersionInstalled = version + , appInstalledFullInstructions = instructions + , appInstalledFullLastBackup = backupTime + , appInstalledFullTorAddress = infoResTorAddress + , appInstalledFullLanAddress = lanAddress + , appInstalledFullTorUi = AppManifest.torUiAvailable manifest + , appInstalledFullLanUi = AppManifest.lanUiAvailable manifest , appInstalledFullConfiguredRequirements = HM.elems requirements - , appInstalledFullUninstallAlert = manifest >>= AppManifest.appManifestUninstallAlert - , appInstalledFullRestoreAlert = manifest >>= AppManifest.appManifestRestoreAlert - , appInstalledFullStartAlert = manifest >>= AppManifest.appManifestStartAlert - , appInstalledFullActions = fromMaybe [] $ AppManifest.appManifestActions <$> manifest + , appInstalledFullUninstallAlert = AppManifest.appManifestUninstallAlert manifest + , appInstalledFullRestoreAlert = AppManifest.appManifestRestoreAlert manifest + , appInstalledFullStartAlert = AppManifest.appManifestStartAlert manifest + , appInstalledFullActions = AppManifest.appManifestActions manifest } runMaybeT (installing <|> installed) `orThrowM` NotFoundE "appId" (show appId) diff --git a/agent/src/Handler/Types/Apps.hs b/agent/src/Handler/Types/Apps.hs index a9b2396f2..c12ed4aee 100644 --- a/agent/src/Handler/Types/Apps.hs +++ b/agent/src/Handler/Types/Apps.hs @@ -9,12 +9,12 @@ import Data.Aeson import Data.Aeson.Flatten import Data.Singletons +import qualified Lib.External.AppManifest as Manifest import Lib.TyFam.ConditionalData import Lib.Types.Core import Lib.Types.Emver import Lib.Types.Emver.Orphans ( ) import Lib.Types.NetAddress -import qualified Lib.External.AppManifest as Manifest data AppBase = AppBase { appBaseId :: AppId , appBaseTitle :: Text @@ -135,6 +135,8 @@ data AppInstalledFull = AppInstalledFull , appInstalledFullVersionInstalled :: Version , appInstalledFullTorAddress :: Maybe TorAddress , appInstalledFullLanAddress :: Maybe LanAddress + , appInstalledFullTorUi :: Bool + , appInstalledFullLanUi :: Bool , appInstalledFullInstructions :: Maybe Text , appInstalledFullLastBackup :: Maybe UTCTime , appInstalledFullConfiguredRequirements :: [Stripped AppDependencyRequirement] @@ -150,6 +152,8 @@ instance ToJSON AppInstalledFull where , "configuredRequirements" .= appInstalledFullConfiguredRequirements , "torAddress" .= (unTorAddress <$> appInstalledFullTorAddress) , "lanAddress" .= (unLanAddress <$> appInstalledFullLanAddress) + , "torUi" .= appInstalledFullTorUi + , "lanUi" .= appInstalledFullLanUi , "id" .= appBaseId appInstalledFullBase , "title" .= appBaseTitle appInstalledFullBase , "iconURL" .= appBaseIconUrl appInstalledFullBase