improve android upgrade interface

and refactor
This commit is contained in:
Joey Hess 2013-11-23 22:12:36 -04:00
parent e563c7e6f4
commit fda641d27b
3 changed files with 42 additions and 29 deletions

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,9 @@
<div .span9 .hero-unit>
<h2>
Upgrading git-annex
<p>
To start the upgrade #
<a .btn .btn-primary href="#{url}">
Download #{takeFileName url}
<p>
Once the download is complete, open the file to upgrade git-annex.