assistant: When autostarted, wait 5 seconds before running the startup scan, to avoid contending with the user's desktop login process.

This commit is contained in:
Joey Hess 2013-10-26 12:42:58 -04:00
parent 4830c0d830
commit 2233ddd5a2
7 changed files with 61 additions and 32 deletions

View file

@ -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)
]