summaryrefslogtreecommitdiff
path: root/Command/WebApp.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-07-31 12:17:31 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-07-31 12:17:31 -0400
commit04794eafc0f0fd09e645247136fe557fd80bfb55 (patch)
tree92ca3260821cdc99c0d47907765ee862c6d23782 /Command/WebApp.hs
parentb9b009787662cda4948b3c9706b8897587d05d8a (diff)
webapp now starts up when run not in a git repo
Diffstat (limited to 'Command/WebApp.hs')
-rw-r--r--Command/WebApp.hs31
1 files changed, 24 insertions, 7 deletions
diff --git a/Command/WebApp.hs b/Command/WebApp.hs
index ee1274f97..6755763b3 100644
--- a/Command/WebApp.hs
+++ b/Command/WebApp.hs
@@ -10,12 +10,19 @@ module Command.WebApp where
import Common.Annex
import Command
import Assistant
+import Assistant.DaemonStatus
+import Assistant.TransferQueue
+import Assistant.Threads.WebApp
import Utility.WebApp
+import Utility.ThreadScheduler
import Utility.Daemon (checkDaemon)
import qualified Command.Watch
+import Control.Concurrent.STM
+
def :: [Command]
-def = [withOptions [Command.Watch.foregroundOption, Command.Watch.stopOption] $
+def = [oneShot $ noRepo firstRun $ dontCheck repoExists $
+ withOptions [Command.Watch.foregroundOption, Command.Watch.stopOption] $
command "webapp" paramNothing seek "launch webapp"]
seek :: [CommandSeek]
@@ -30,8 +37,8 @@ start foreground stopdaemon = notBareRepo $ do
else do
f <- liftIO . absPath =<< fromRepo gitAnnexHtmlShim
ifM (checkpid <&&> checkshim f) $
- ( liftIO $ go f
- , startDaemon True foreground $ Just $ go f
+ ( liftIO $ openBrowser f
+ , startDaemon True foreground $ Just openBrowser
)
stop
where
@@ -39,7 +46,17 @@ start foreground stopdaemon = notBareRepo $ do
pidfile <- fromRepo gitAnnexPidFile
liftIO $ isJust <$> checkDaemon pidfile
checkshim f = liftIO $ doesFileExist f
- go f = unlessM (runBrowser url) $
- error $ "failed to start web browser on url " ++ url
- where
- url = "file://" ++ f
+
+openBrowser :: FilePath -> IO ()
+openBrowser htmlshim = unlessM (runBrowser url) $
+ error $ "failed to start web browser on url " ++ url
+ where
+ url = "file://" ++ htmlshim
+
+firstRun :: IO ()
+firstRun = do
+ dstatus <- atomically . newTMVar =<< newDaemonStatus
+ transferqueue <- newTransferQueue
+ webAppThread Nothing dstatus transferqueue $ Just $ \f -> do
+ openBrowser f
+ waitForTermination