diff options
author | Joey Hess <joey@kitenet.net> | 2013-10-26 12:42:58 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-10-26 12:42:58 -0400 |
commit | 956694b88fff7bc151bad6196ed429e0db7b23cb (patch) | |
tree | 07237216bb2c9854d19a3664413b1311f472ad27 /Command/Assistant.hs | |
parent | fdec6d27c4d32b9d641d17336b6be4a91c1d3fc4 (diff) |
assistant: When autostarted, wait 5 seconds before running the startup scan, to avoid contending with the user's desktop login process.
Diffstat (limited to 'Command/Assistant.hs')
-rw-r--r-- | Command/Assistant.hs | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/Command/Assistant.hs b/Command/Assistant.hs index f65bed736..521a88571 100644 --- a/Command/Assistant.hs +++ b/Command/Assistant.hs @@ -14,43 +14,55 @@ import qualified Command.Watch import Init import Config.Files import qualified Build.SysConfig +import Utility.HumanTime import System.Environment def :: [Command] -def = [noRepo checkAutoStart $ dontCheck repoExists $ - withOptions [Command.Watch.foregroundOption, Command.Watch.stopOption, autoStartOption] $ +def = [noRepo checkAutoStart $ dontCheck repoExists $ withOptions options $ command "assistant" paramNothing seek SectionCommon "automatically handle changes"] +options :: [Option] +options = + [ Command.Watch.foregroundOption + , Command.Watch.stopOption + , autoStartOption + , startDelayOption + ] + autoStartOption :: Option autoStartOption = Option.flag [] "autostart" "start in known repositories" +startDelayOption :: Option +startDelayOption = Option.field [] "startdelay" paramNumber "delay before running startup scan" + seek :: [CommandSeek] seek = [withFlag Command.Watch.stopOption $ \stopdaemon -> withFlag Command.Watch.foregroundOption $ \foreground -> withFlag autoStartOption $ \autostart -> - withNothing $ start foreground stopdaemon autostart] + withField startDelayOption (pure . maybe Nothing parseDuration) $ \startdelay -> + withNothing $ start foreground stopdaemon autostart startdelay] -start :: Bool -> Bool -> Bool -> CommandStart -start foreground stopdaemon autostart +start :: Bool -> Bool -> Bool -> Maybe Duration -> CommandStart +start foreground stopdaemon autostart startdelay | autostart = do - liftIO autoStart + liftIO $ autoStart startdelay stop | otherwise = do ensureInitialized - Command.Watch.start True foreground stopdaemon + Command.Watch.start True foreground stopdaemon startdelay {- Run outside a git repository. Check to see if any parameter is - --autostart and enter autostart mode. -} checkAutoStart :: IO () checkAutoStart = ifM (elem "--autostart" <$> getArgs) - ( autoStart + ( autoStart Nothing , error "Not in a git repository." ) -autoStart :: IO () -autoStart = do +autoStart :: Maybe Duration -> IO () +autoStart startdelay = do dirs <- liftIO readAutoStartFile when (null dirs) $ do f <- autoStartFile @@ -67,5 +79,10 @@ autoStart = do go haveionice program dir = do setCurrentDirectory dir if haveionice - then boolSystem "ionice" [Param "-c3", Param program, Param "assistant"] - else boolSystem program [Param "assistant"] + then boolSystem "ionice" (Param "-c3" : Param program : baseparams) + else boolSystem program baseparams + where + baseparams = + [ Param "assistant" + , Param $ "--startdelay=" ++ fromDuration (fromMaybe (Duration 5) startdelay) + ] |