add some alerts

This commit is contained in:
Joey Hess 2012-07-29 13:22:08 -04:00
parent 2dc5697a0a
commit 09e77a0cf0
3 changed files with 34 additions and 10 deletions

View file

@ -15,6 +15,7 @@ import Assistant.ThreadedMonad
import Assistant.DaemonStatus import Assistant.DaemonStatus
import Assistant.ScanRemotes import Assistant.ScanRemotes
import Assistant.Threads.Pusher (pushToRemotes) import Assistant.Threads.Pusher (pushToRemotes)
import Assistant.Alert
import qualified Annex import qualified Annex
import qualified Git import qualified Git
import Utility.ThreadScheduler import Utility.ThreadScheduler
@ -158,17 +159,29 @@ handleMounts st dstatus scanremotes wasmounted nowmounted = mapM_ (handleMount s
handleMount :: ThreadState -> DaemonStatusHandle -> ScanRemoteMap -> Mntent -> IO () handleMount :: ThreadState -> DaemonStatusHandle -> ScanRemoteMap -> Mntent -> IO ()
handleMount st dstatus scanremotes mntent = do handleMount st dstatus scanremotes mntent = do
debug thisThread ["detected mount of", mnt_dir mntent] debug thisThread ["detected mount of", dir]
rs <- remotesUnder st dstatus mntent rs <- remotesUnder st dstatus mntent
unless (null rs) $ do unless (null rs) $ do
branch <- runThreadState st $ Command.Sync.currentBranch branch <- runThreadState st $ Command.Sync.currentBranch
let nonspecial = filter (Git.repoIsLocal . Remote.repo) rs let nonspecial = filter (Git.repoIsLocal . Remote.repo) rs
unless (null nonspecial) $ do unless (null nonspecial) $
debug thisThread ["pulling from", show nonspecial] alertWhile dstatus (syncalert nonspecial) $ do
debug thisThread ["syncing with", show nonspecial]
runThreadState st $ manualPull branch nonspecial runThreadState st $ manualPull branch nonspecial
now <- getCurrentTime now <- getCurrentTime
pushToRemotes thisThread now st Nothing nonspecial pushToRemotes thisThread now st Nothing nonspecial
addScanRemotes scanremotes rs addScanRemotes scanremotes rs
where
dir = mnt_dir mntent
syncalert rs = Alert
{ alertClass = Activity
, alertHeader = Just $ "Syncing with " ++ unwords (map Remote.name rs)
, alertMessage = StringAlert $ unwords
["I noticed you plugged in", dir,
" -- let's get it in sync!"]
, alertBlockDisplay = True
}
{- Finds remotes located underneath the mount point. {- Finds remotes located underneath the mount point.
- -

View file

@ -12,6 +12,7 @@ import Assistant.ScanRemotes
import Assistant.TransferQueue import Assistant.TransferQueue
import Assistant.ThreadedMonad import Assistant.ThreadedMonad
import Assistant.DaemonStatus import Assistant.DaemonStatus
import Assistant.Alert
import Logs.Transfer import Logs.Transfer
import Logs.Location import Logs.Location
import qualified Remote import qualified Remote
@ -31,9 +32,18 @@ transferScannerThread st dstatus scanremotes transferqueue = do
runEvery (Seconds 2) $ do runEvery (Seconds 2) $ do
r <- getScanRemote scanremotes r <- getScanRemote scanremotes
liftIO $ debug thisThread ["starting scan of", show r] liftIO $ debug thisThread ["starting scan of", show r]
alertWhile dstatus (scanalert r) $
scan st dstatus transferqueue r scan st dstatus transferqueue r
liftIO $ debug thisThread ["finished scan of", show r] liftIO $ debug thisThread ["finished scan of", show r]
where where
scanalert r = Alert
{ alertClass = Activity
, alertHeader = Just $ "Scanning " ++ Remote.name r
, alertMessage = StringAlert $ unwords
[ "Ensuring that ", Remote.name r
, "is fully in sync." ]
, alertBlockDisplay = True
}
{- This is a naive scan through the git work tree. {- This is a naive scan through the git work tree.
- -

View file

@ -74,9 +74,7 @@ watchThread st dstatus transferqueue changechan = do
{- Initial scartup scan. The action should return once the scan is complete. -} {- Initial scartup scan. The action should return once the scan is complete. -}
startupScan :: ThreadState -> DaemonStatusHandle -> IO a -> IO a startupScan :: ThreadState -> DaemonStatusHandle -> IO a -> IO a
startupScan st dstatus scanner = do startupScan st dstatus scanner = do
runThreadState st $ runThreadState st $ showAction "scanning"
showAction "scanning"
let alert = activityAlert Nothing "Performing startup scan"
r <- alertWhile dstatus alert scanner r <- alertWhile dstatus alert scanner
modifyDaemonStatus_ dstatus $ \s -> s { scanComplete = True } modifyDaemonStatus_ dstatus $ \s -> s { scanComplete = True }
@ -87,6 +85,9 @@ startupScan st dstatus scanner = do
return r return r
where
alert = activityAlert Nothing "Performing startup scan"
ignored :: FilePath -> Bool ignored :: FilePath -> Bool
ignored = ig . takeFileName ignored = ig . takeFileName
where where