2013-11-22 22:46:45 +00:00
|
|
|
{- git-annex assistant thread to detect when upgrade is available
|
2013-11-21 21:49:56 +00:00
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2013 Joey Hess <id@joeyh.name>
|
2013-11-21 21:49:56 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2013-11-21 21:49:56 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
|
|
|
module Assistant.Threads.Upgrader (
|
|
|
|
upgraderThread
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Assistant.Common
|
2013-11-24 17:20:58 +00:00
|
|
|
import Assistant.Upgrade
|
|
|
|
|
2013-11-21 21:49:56 +00:00
|
|
|
import Assistant.Types.UrlRenderer
|
|
|
|
import Assistant.DaemonStatus
|
|
|
|
import Assistant.Alert
|
|
|
|
import Utility.NotificationBroadcaster
|
2013-11-22 20:04:20 +00:00
|
|
|
import qualified Annex
|
2017-12-14 16:46:57 +00:00
|
|
|
import qualified BuildInfo
|
2016-04-21 18:32:42 +00:00
|
|
|
import qualified Utility.DottedVersion as DottedVersion
|
2013-11-21 21:49:56 +00:00
|
|
|
import Types.Distribution
|
|
|
|
#ifdef WITH_WEBAPP
|
|
|
|
import Assistant.WebApp.Types
|
|
|
|
#endif
|
|
|
|
|
|
|
|
import Data.Time.Clock
|
|
|
|
import qualified Data.Text as T
|
|
|
|
|
|
|
|
upgraderThread :: UrlRenderer -> NamedThread
|
2013-11-24 17:20:58 +00:00
|
|
|
upgraderThread urlrenderer = namedThread "Upgrader" $
|
2017-12-14 16:46:57 +00:00
|
|
|
when (isJust BuildInfo.upgradelocation) $ do
|
2013-11-24 17:20:58 +00:00
|
|
|
{- Check for upgrade on startup, unless it was just
|
|
|
|
- upgraded. -}
|
|
|
|
unlessM (liftIO checkSuccessfulUpgrade) $
|
|
|
|
checkUpgrade urlrenderer
|
2013-11-21 21:49:56 +00:00
|
|
|
h <- liftIO . newNotificationHandle False . networkConnectedNotifier =<< getDaemonStatus
|
2013-11-24 17:20:58 +00:00
|
|
|
go h =<< liftIO getCurrentTime
|
2013-11-21 21:49:56 +00:00
|
|
|
where
|
2014-10-09 18:53:13 +00:00
|
|
|
{- Wait for a network connection event. Then see if it's been
|
2013-11-21 21:49:56 +00:00
|
|
|
- half a day since the last upgrade check. If so, proceed with
|
|
|
|
- check. -}
|
|
|
|
go h lastchecked = do
|
|
|
|
liftIO $ waitNotification h
|
2013-11-22 20:04:20 +00:00
|
|
|
autoupgrade <- liftAnnex $ annexAutoUpgrade <$> Annex.getGitConfig
|
|
|
|
if autoupgrade == NoAutoUpgrade
|
|
|
|
then go h lastchecked
|
|
|
|
else do
|
|
|
|
now <- liftIO getCurrentTime
|
2013-11-24 17:20:58 +00:00
|
|
|
if diffUTCTime now lastchecked > halfday
|
2013-11-22 20:04:20 +00:00
|
|
|
then do
|
|
|
|
checkUpgrade urlrenderer
|
2013-11-24 17:20:58 +00:00
|
|
|
go h =<< liftIO getCurrentTime
|
2013-11-22 20:04:20 +00:00
|
|
|
else go h lastchecked
|
2013-11-21 21:49:56 +00:00
|
|
|
halfday = 12 * 60 * 60
|
|
|
|
|
|
|
|
checkUpgrade :: UrlRenderer -> Assistant ()
|
|
|
|
checkUpgrade urlrenderer = do
|
|
|
|
debug [ "Checking if an upgrade is available." ]
|
2014-04-23 17:30:30 +00:00
|
|
|
go =<< downloadDistributionInfo
|
2013-11-21 21:49:56 +00:00
|
|
|
where
|
|
|
|
go Nothing = debug [ "Failed to check if upgrade is available." ]
|
|
|
|
go (Just d) = do
|
2017-12-14 16:46:57 +00:00
|
|
|
let installed = DottedVersion.normalize BuildInfo.packageversion
|
2016-04-21 18:32:42 +00:00
|
|
|
let avail = DottedVersion.normalize $ distributionVersion d
|
|
|
|
let old = DottedVersion.normalize <$> distributionUrgentUpgrade d
|
2013-11-21 21:49:56 +00:00
|
|
|
if Just installed <= old
|
2013-11-22 19:10:56 +00:00
|
|
|
then canUpgrade High urlrenderer d
|
|
|
|
else if installed < avail
|
|
|
|
then canUpgrade Low urlrenderer d
|
|
|
|
else debug [ "No new version found." ]
|
2013-11-21 21:49:56 +00:00
|
|
|
|
|
|
|
canUpgrade :: AlertPriority -> UrlRenderer -> GitAnnexDistribution -> Assistant ()
|
2013-11-24 17:20:58 +00:00
|
|
|
canUpgrade urgency urlrenderer d = ifM autoUpgradeEnabled
|
|
|
|
( startDistributionDownload d
|
|
|
|
, do
|
2013-11-21 21:49:56 +00:00
|
|
|
#ifdef WITH_WEBAPP
|
2013-11-24 17:20:58 +00:00
|
|
|
button <- mkAlertButton True (T.pack "Upgrade") urlrenderer (ConfigStartUpgradeR d)
|
2013-11-24 17:28:34 +00:00
|
|
|
void $ addAlert (canUpgradeAlert urgency (distributionVersion d) button)
|
2013-11-21 21:49:56 +00:00
|
|
|
#else
|
2013-11-24 17:20:58 +00:00
|
|
|
noop
|
2013-11-21 21:49:56 +00:00
|
|
|
#endif
|
2013-11-24 17:20:58 +00:00
|
|
|
)
|