on master help sign in
Set title, exit when server dies
commitbf065757b338f1a72f6d66880b7f3732f762855b authorMichael Snoyman <michael@snoyman.com> dateThu 24 Jun 2010, 09:57 (16 years ago) parentf42afef
2 files changed+14−8
Network/Wai/Handler/Webkit.hs+13−6 webkit.cpp+1−2
Network/Wai/Handler/Webkit.hs+13−6
@@ -3,12 +3,19 @@ module Network.Wai.Handler.Webkit (run) where
33
44import Network.Wai (Application)
55import qualified Network.Wai.Handler.SimpleServer as S
6−import Control.Concurrent (forkIO)
6+import Control.Concurrent (forkOS, myThreadId, killThread)
7+import Control.Concurrent.MVar
8+import Foreign.C.String (CString, withCString)
9+import Control.Exception (finally)
710
8−run :: Application -> IO ()
9−run app = do
10− forkIO $ S.run 3000 app
11− startBrowser
11+run :: String -- ^ Title to show in titlebar
12+ -> Application -> IO ()
13+run title app = do
14+ mvar <- newEmptyMVar
15+ _ <- forkOS $ finally (S.run 3000 app) (putMVar mvar ())
16+ _ <- forkOS $ finally (withCString title startBrowser) (putMVar mvar ())
17+ _ <- takeMVar mvar
18+ return ()
1219
1320foreign import ccall "start_browser"
14− startBrowser :: IO ()
21+ startBrowser :: CString -> IO ()
webkit.cpp+1−2
@@ -3,9 +3,8 @@
33#include <QtWebKit>
44
55extern "C" {
6− int start_browser()
6+ int start_browser(char *title)
77 {
8− char title[80] = "My Application";
98 char *argv[1];
109 argv[0] = title;
1110 int argc = 1;