From fda641d27bb1a59771c4de426276c9caa3f52cce Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 23 Nov 2013 22:12:36 -0400 Subject: [PATCH] improve android upgrade interface and refactor --- Assistant/Upgrade.hs | 26 ++++++++++++++ Assistant/WebApp/Configurators/Upgrade.hs | 36 ++++--------------- .../configurators/upgrade/android.hamlet | 9 +++++ 3 files changed, 42 insertions(+), 29 deletions(-) create mode 100644 templates/configurators/upgrade/android.hamlet diff --git a/Assistant/Upgrade.hs b/Assistant/Upgrade.hs index a5d80569c4..2ee52c30bc 100644 --- a/Assistant/Upgrade.hs +++ b/Assistant/Upgrade.hs @@ -20,6 +20,11 @@ import Annex.Content import qualified Backend import qualified Types.Backend import qualified Types.Key +import Assistant.TransferQueue +import Assistant.TransferSlots +import Remote + +import qualified Data.Map as M {- Upgrade without interaction in the webapp. -} unattendedUpgrade :: Assistant () @@ -46,6 +51,27 @@ checkSuccessfulUpgrade = isJust <$> getEnv upgradedEnv upgradedEnv :: String upgradedEnv = "GIT_ANNEX_UPGRADED" +{- Start downloading the distribution key from the web. + - Install a hook that will be run once the download is complete. -} +startDistributionDownload :: GitAnnexDistribution -> Assistant () +startDistributionDownload d = do + liftAnnex $ setUrlPresent k u + hook <- asIO1 $ distributionDownloadComplete d + modifyDaemonStatus_ $ \status -> status + { transferHook = M.insert k hook (transferHook status) } + maybe noop (queueTransfer "upgrade" Next (Just f) t) + =<< liftAnnex (remoteFromUUID webUUID) + startTransfer t + where + k = distributionKey d + u = distributionUrl d + f = takeFileName u ++ " (for upgrade)" + t = Transfer + { transferDirection = Download + , transferUUID = webUUID + , transferKey = k + } + {- Fsck the key to verify the download. -} distributionDownloadComplete :: GitAnnexDistribution -> Transfer -> Assistant () distributionDownloadComplete d t diff --git a/Assistant/WebApp/Configurators/Upgrade.hs b/Assistant/WebApp/Configurators/Upgrade.hs index 53798565ed..77bed966ed 100644 --- a/Assistant/WebApp/Configurators/Upgrade.hs +++ b/Assistant/WebApp/Configurators/Upgrade.hs @@ -13,43 +13,21 @@ import Assistant.WebApp.Common import Types.Distribution import Assistant.Upgrade import Assistant.Restart -import Assistant.DaemonStatus import Config -import Assistant.TransferQueue -import Assistant.TransferSlots -import Logs.Transfer -import Logs.Web -import Remote -import qualified Data.Map as M - -{- On Android, just redirect the user's web browser to the apk file - - to download it. +{- On Android, just point the user at the apk file to download. + - Installation will be handled by selecting the downloaded file. - - - Otherwise, register a hook action that will be called once the key - - is downloaded, and start downloading the key. + - Otherwise, start the download. - -} getConfigStartUpgradeR :: GitAnnexDistribution -> Handler Html getConfigStartUpgradeR d = do #ifdef __ANDROID__ - redirect (distributionUrl d) + let url = distributionUrl d + page "Upgrade" (Just Configuration) $ + $(widgetFile "configurators/upgrade/android") #else - liftAssistant $ do - let k = distributionKey d - let u = distributionUrl d - liftAnnex $ setUrlPresent k u - hook <- asIO1 $ distributionDownloadComplete d - modifyDaemonStatus_ $ \status -> status - { transferHook = M.insert k hook (transferHook status) } - let t = Transfer - { transferDirection = Download - , transferUUID = webUUID - , transferKey = k - } - let f = takeFileName u ++ " (for upgrade)" - maybe noop (queueTransfer "upgrade" Next (Just f) t) - =<< liftAnnex (remoteFromUUID webUUID) - startTransfer t + liftAssistant $ startDistributionDownload d redirect DashboardR #endif diff --git a/templates/configurators/upgrade/android.hamlet b/templates/configurators/upgrade/android.hamlet new file mode 100644 index 0000000000..5ece1b42fb --- /dev/null +++ b/templates/configurators/upgrade/android.hamlet @@ -0,0 +1,9 @@ +
+

+ Upgrading git-annex +

+ To start the upgrade # + + Download #{takeFileName url} +

+ Once the download is complete, open the file to upgrade git-annex.