mirror of
https://github.com/typeable/wai.git
synced 2025-01-07 06:36:36 +03:00
Merge branch 'wai-0.4'
Conflicts: wai-handler-launch/wai-handler-launch.cabal
This commit is contained in:
commit
e08ae69baa
@ -4,6 +4,7 @@
|
||||
module Network.Wai.Handler.Launch
|
||||
( run
|
||||
, runUrl
|
||||
, runUrlPort
|
||||
) where
|
||||
|
||||
import Network.Wai
|
||||
@ -105,32 +106,35 @@ foreign import ccall "launch"
|
||||
launch' :: Int -> CString -> IO ()
|
||||
#endif
|
||||
|
||||
launch :: String -> IO ()
|
||||
launch :: Int -> String -> IO ()
|
||||
|
||||
#if WINDOWS
|
||||
launch s = withCString s $ launch' 4587
|
||||
launch port s = withCString s $ launch' port
|
||||
#else
|
||||
launch s = forkIO (rawSystem
|
||||
launch port s = forkIO (rawSystem
|
||||
#if MAC
|
||||
"open"
|
||||
#else
|
||||
"xdg-open"
|
||||
#endif
|
||||
["http://127.0.0.1:4587/" ++ s] >> return ()) >> return ()
|
||||
["http://127.0.0.1:" ++ show port ++ "/" ++ s] >> return ()) >> return ()
|
||||
#endif
|
||||
|
||||
run :: Application -> IO ()
|
||||
run = runUrl ""
|
||||
|
||||
runUrl :: String -> Application -> IO ()
|
||||
runUrl url app = do
|
||||
runUrl = runUrlPort 4587
|
||||
|
||||
runUrlPort :: Int -> String -> Application -> IO ()
|
||||
runUrlPort port url app = do
|
||||
x <- newIORef True
|
||||
_ <- forkIO $ Warp.runSettings Warp.defaultSettings
|
||||
{ Warp.settingsPort = 4587
|
||||
{ Warp.settingsPort = port
|
||||
, Warp.settingsOnException = const $ return ()
|
||||
, Warp.settingsHost = "127.0.0.1"
|
||||
} $ ping x app
|
||||
launch url
|
||||
launch port url
|
||||
loop x
|
||||
|
||||
loop :: IORef Bool -> IO ()
|
||||
|
@ -1,4 +1,3 @@
|
||||
Name: wai-handler-launch
|
||||
Version: 1.0.0
|
||||
Synopsis: Launch a web app in the default browser.
|
||||
Description: This handles cross-platform launching and inserts Javascript code to ping the server. When the server no longer receives pings, it shuts down.
|
||||
|
Loading…
Reference in New Issue
Block a user