|
{-# LANGUAGE OverloadedStrings #-} |
|
|
|
module Server where |
|
|
|
import Control.Applicative |
|
import Control.Concurrent (forkIO) |
|
import Control.Monad (void) |
|
import qualified Data.String as S |
|
import Data.Text (pack) |
|
import Graphics.UI.Thrust |
|
import qualified Graphics.UI.Thrust.Window as W |
|
import Haste.App |
|
import Network.Wai.Application.Static (defaultFileServerSettings, |
|
staticApp) |
|
import Network.Wai.Handler.Warp (defaultSettings, runSettings, |
|
setPort) |
|
|
|
import API (API (API)) |
|
import Client (client) |
|
|
|
setTitle :: Window -> String -> Server () |
|
setTitle w hede = liftIO . runUI w . W.setTitle . pack $ hede |
|
|
|
setup :: Window -> UI () |
|
setup w = void $ |
|
do W.create |
|
W.show |
|
W.setFocus True |
|
liftIO . forkIO . runApp def $ |
|
do api <- API <$> remote (setTitle w) |
|
runClient $ client api |
|
|
|
main :: IO () |
|
main = |
|
do forkIO . runSettings serverSettings $ staticApp staticSettings |
|
startGUI config setup |
|
where serverSettings = |
|
setPort 8000 defaultSettings |
|
staticSettings = |
|
defaultFileServerSettings $ |
|
S.fromString "examples/thrust-haste/resources" |
|
config = |
|
defaultConfig {url = "http://localhost:8000"} |