From 5d4a987bb9d0796af6597c307739482a4a8e1898 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 6 Feb 2013 15:38:41 -0400 Subject: fix build with webapp disabled Broken by recent thread manager and restarting improvements. --- Assistant.hs | 6 ++++-- Assistant/NamedThread.hs | 42 +++++++++++++++++++++++++++--------------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/Assistant.hs b/Assistant.hs index 45c0e9f03..8a3816f4d 100644 --- a/Assistant.hs +++ b/Assistant.hs @@ -196,8 +196,10 @@ startDaemon assistant foreground startbrowser = do #ifdef WITH_WEBAPP d <- getAssistant id urlrenderer <- liftIO newUrlRenderer + mapM_ (startthread $ Just urlrenderer) +#else + mapM_ (startthread Nothing) #endif - mapM_ (startthread urlrenderer) [ watch $ commitThread #ifdef WITH_WEBAPP , assist $ webAppThread d urlrenderer False Nothing webappwaiter @@ -230,5 +232,5 @@ startDaemon assistant foreground startbrowser = do watch a = (True, a) assist a = (False, a) startthread urlrenderer (watcher, t) - | watcher || assistant = startNamedThread (Just urlrenderer) t + | watcher || assistant = startNamedThread urlrenderer t | otherwise = noop diff --git a/Assistant/NamedThread.hs b/Assistant/NamedThread.hs index fd710cf54..0a090d0d2 100644 --- a/Assistant/NamedThread.hs +++ b/Assistant/NamedThread.hs @@ -5,6 +5,8 @@ - Licensed under the GNU GPL version 3 or higher. -} +{-# LANGUAGE CPP #-} + module Assistant.NamedThread where import Common.Annex @@ -12,23 +14,31 @@ import Assistant.Types.NamedThread import Assistant.Types.ThreadName import Assistant.Types.DaemonStatus import Assistant.DaemonStatus -import Assistant.Alert import Assistant.Monad -import Assistant.WebApp -import Assistant.WebApp.Types import Control.Concurrent import Control.Concurrent.Async import qualified Data.Map as M -import qualified Data.Text as T import qualified Control.Exception as E +#ifdef WITH_WEBAPP +import Assistant.WebApp +import Assistant.WebApp.Types +import Assistant.Alert +import qualified Data.Text as T +#endif + {- Starts a named thread, if it's not already running. - - Named threads are run by a management thread, so if they crash - an alert is displayed, allowing the thread to be restarted. -} +#ifdef WITH_WEBAPP startNamedThread :: Maybe UrlRenderer -> NamedThread -> Assistant () startNamedThread urlrenderer namedthread@(NamedThread name a) = do +#else +startNamedThread :: Maybe Bool -> NamedThread -> Assistant () +startNamedThread urlrenderer namedthread@(NamedThread name a) = do +#endif m <- startedThreads <$> getDaemonStatus case M.lookup name m of Nothing -> start @@ -58,20 +68,22 @@ startNamedThread urlrenderer namedthread@(NamedThread name a) = do , "crashed:", show e ] hPutStrLn stderr msg - button <- runAssistant d mkbutton +#ifdef WITH_WEBAPP + button <- runAssistant d $ + case urlrenderer of + Nothing -> return Nothing + Just renderer -> do + close <- asIO1 removeAlert + url <- liftIO $ renderUrl renderer (RestartThreadR name) [] + return $ Just $ AlertButton + { buttonLabel = T.pack "Restart Thread" + , buttonUrl = url + , buttonAction = Just close + } runAssistant d $ void $ addAlert $ (warningAlert (fromThreadName name) msg) { alertButton = button } - mkbutton = case urlrenderer of - Nothing -> return Nothing - Just renderer -> do - close <- asIO1 removeAlert - url <- liftIO $ renderUrl renderer (RestartThreadR name) [] - return $ Just $ AlertButton - { buttonLabel = T.pack "Restart Thread" - , buttonUrl = url - , buttonAction = Just close - } +#endif namedThreadId :: NamedThread -> Assistant (Maybe ThreadId) namedThreadId (NamedThread name _) = do -- cgit v1.2.3