2013-11-21 21:49:56 +00:00
|
|
|
{- git-annex assistant webapp upgrade UI
|
|
|
|
-
|
|
|
|
- Copyright 2013 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2013-11-23 21:21:04 +00:00
|
|
|
{-# LANGUAGE CPP, QuasiQuotes, TemplateHaskell, OverloadedStrings #-}
|
2013-11-21 21:49:56 +00:00
|
|
|
|
|
|
|
module Assistant.WebApp.Configurators.Upgrade where
|
|
|
|
|
|
|
|
import Assistant.WebApp.Common
|
|
|
|
import Types.Distribution
|
2013-11-23 04:54:08 +00:00
|
|
|
import Assistant.Upgrade
|
2013-11-23 19:50:17 +00:00
|
|
|
import Assistant.Restart
|
2013-11-23 21:21:04 +00:00
|
|
|
import Assistant.DaemonStatus
|
2013-11-23 04:54:08 +00:00
|
|
|
import Config
|
2013-11-23 21:21:04 +00:00
|
|
|
import Assistant.TransferQueue
|
|
|
|
import Assistant.TransferSlots
|
|
|
|
import Logs.Transfer
|
|
|
|
import Logs.Web
|
|
|
|
import Remote
|
2013-11-21 21:49:56 +00:00
|
|
|
|
2013-11-23 21:21:04 +00:00
|
|
|
import qualified Data.Map as M
|
2013-11-21 21:49:56 +00:00
|
|
|
|
2013-11-23 21:21:04 +00:00
|
|
|
{- On Android, just redirect the user's web browser to the apk file
|
|
|
|
- to download it.
|
|
|
|
-
|
|
|
|
- Otherwise, register a hook action that will be called once the key
|
|
|
|
- is downloaded, and start downloading the key.
|
|
|
|
- -}
|
2013-11-23 03:12:06 +00:00
|
|
|
getConfigStartUpgradeR :: GitAnnexDistribution -> Handler Html
|
2013-11-23 21:21:04 +00:00
|
|
|
getConfigStartUpgradeR d = do
|
|
|
|
#ifdef __ANDROID__
|
|
|
|
redirect (distributionUrl d)
|
|
|
|
#else
|
|
|
|
liftAssistant $ do
|
|
|
|
let k = distributionKey d
|
|
|
|
let u = distributionUrl d
|
|
|
|
liftAnnex $ setUrlPresent k u
|
2013-11-24 01:58:39 +00:00
|
|
|
hook <- asIO1 $ distributionDownloadComplete d
|
2013-11-23 21:21:04 +00:00
|
|
|
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
|
|
|
|
redirect DashboardR
|
|
|
|
#endif
|
|
|
|
|
2013-11-23 03:12:06 +00:00
|
|
|
{- Finish upgrade by starting the new assistant in the same repository this
|
global webapp redirects, to finish upgrades
When an automatic upgrade completes, or when the user clicks on the upgrade
button in one webapp, but also has it open in another browser window/tab,
we have a problem: The current web server is going to stop running in
minutes, but there is no way to send a redirect to the web browser to the
new url.
To solve this, used long polling, so the webapp is always listening for
urls it should redirect to. This allows globally redirecting every open
webapp. Works great! Tested with 2 web browsers with 2 tabs each.
May be useful for other purposes later too, dunno.
The overhead is 2 http requests per page load in the webapp. Due to yesod's
speed, this does not seem to noticibly delay it. Only 1 of the requests
could possibly block the page load, the other is async.
2013-11-23 18:47:38 +00:00
|
|
|
- one is running in, and redirecting to it. -}
|
2013-11-23 16:39:36 +00:00
|
|
|
getConfigFinishUpgradeR :: Handler Html
|
|
|
|
getConfigFinishUpgradeR = do
|
2013-11-23 04:54:08 +00:00
|
|
|
liftAssistant prepUpgrade
|
2013-11-23 19:50:17 +00:00
|
|
|
url <- liftAssistant runRestart
|
global webapp redirects, to finish upgrades
When an automatic upgrade completes, or when the user clicks on the upgrade
button in one webapp, but also has it open in another browser window/tab,
we have a problem: The current web server is going to stop running in
minutes, but there is no way to send a redirect to the web browser to the
new url.
To solve this, used long polling, so the webapp is always listening for
urls it should redirect to. This allows globally redirecting every open
webapp. Works great! Tested with 2 web browsers with 2 tabs each.
May be useful for other purposes later too, dunno.
The overhead is 2 http requests per page load in the webapp. Due to yesod's
speed, this does not seem to noticibly delay it. Only 1 of the requests
could possibly block the page load, the other is async.
2013-11-23 18:47:38 +00:00
|
|
|
liftAssistant $ postUpgrade url
|
|
|
|
redirect url
|
2013-11-23 16:39:36 +00:00
|
|
|
|
|
|
|
getConfigEnableAutomaticUpgradeR :: Handler Html
|
|
|
|
getConfigEnableAutomaticUpgradeR = do
|
|
|
|
liftAnnex $ setConfig (annexConfig "autoupgrade")
|
|
|
|
(fromAutoUpgrade AutoUpgrade)
|
|
|
|
redirect DashboardR
|