2013-11-21 21:49:56 +00:00
|
|
|
{- git-annex assistant webapp upgrade UI
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2013 Joey Hess <id@joeyh.name>
|
2013-11-21 21:49:56 +00:00
|
|
|
-
|
|
|
|
- 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 04:54:08 +00:00
|
|
|
import Config
|
2013-11-21 21:49:56 +00:00
|
|
|
|
2013-11-24 02:12:36 +00:00
|
|
|
{- On Android, just point the user at the apk file to download.
|
|
|
|
- Installation will be handled by selecting the downloaded file.
|
2013-11-23 21:21:04 +00:00
|
|
|
-
|
2013-11-24 03:45:49 +00:00
|
|
|
- Otherwise, start the upgrade process, which will run fully
|
|
|
|
- noninteractively.
|
2013-11-23 21:21:04 +00:00
|
|
|
- -}
|
2013-11-23 03:12:06 +00:00
|
|
|
getConfigStartUpgradeR :: GitAnnexDistribution -> Handler Html
|
2013-11-23 21:21:04 +00:00
|
|
|
getConfigStartUpgradeR d = do
|
2013-11-25 17:01:53 +00:00
|
|
|
#ifdef ANDROID_SPLICES
|
2013-11-24 02:12:36 +00:00
|
|
|
let url = distributionUrl d
|
|
|
|
page "Upgrade" (Just Configuration) $
|
|
|
|
$(widgetFile "configurators/upgrade/android")
|
2013-11-23 21:21:04 +00:00
|
|
|
#else
|
2013-11-24 02:12:36 +00:00
|
|
|
liftAssistant $ startDistributionDownload d
|
2013-11-23 21:21:04 +00:00
|
|
|
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
|