summaryrefslogtreecommitdiff
path: root/Assistant/WebApp.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Assistant/WebApp.hs')
-rw-r--r--Assistant/WebApp.hs12
1 files changed, 11 insertions, 1 deletions
diff --git a/Assistant/WebApp.hs b/Assistant/WebApp.hs
index fc40ca5bf..f7fb7bb6e 100644
--- a/Assistant/WebApp.hs
+++ b/Assistant/WebApp.hs
@@ -30,7 +30,7 @@ staticFiles "static"
mkYesodData "WebApp" $(parseRoutesFile "Assistant/WebApp/routes")
data WebApp = WebApp
- { threadState :: ThreadState
+ { threadState :: Maybe ThreadState
, daemonStatus :: DaemonStatusHandle
, transferQueue :: TransferQueue
, secretToken :: Text
@@ -104,6 +104,16 @@ modifyWebAppState a = go =<< webAppState <$> getYesod
v <- takeTMVar s
putTMVar s $ a v
+{- Runs an Annex action from the webapp.
+ -
+ - When the webapp is run outside a git-annex repository, the fallback
+ - value is returned.
+ -}
+runAnnex :: forall sub a. a -> Annex a -> GHandler sub WebApp a
+runAnnex fallback a = maybe (return fallback) go =<< threadState <$> getYesod
+ where
+ go st = liftIO $ runThreadState st a
+
waitNotifier :: forall sub. (DaemonStatus -> NotificationBroadcaster) -> NotificationId -> GHandler sub WebApp ()
waitNotifier selector nid = do
notifier <- getNotifier selector