threepenny-gui 0.8.1.0 → 0.8.2.0
raw patch · 7 files changed
+43/−17 lines, 7 filesdep ~file-embedPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: file-embed
API changes (from Hackage documentation)
+ Foreign.JavaScript: getCookies :: Window -> [Cookie]
Files
- CHANGELOG.md +10/−0
- js/index.html +5/−0
- src/Foreign/JavaScript.hs +1/−1
- src/Foreign/JavaScript/EventLoop.hs +3/−2
- src/Foreign/JavaScript/Server.hs +9/−7
- src/Foreign/JavaScript/Types.hs +13/−5
- threepenny-gui.cabal +2/−2
CHANGELOG.md view
@@ -1,5 +1,15 @@ ## Changelog for the `threepenny-gui` package +**0.8.2.0** — Snapshot release++* Add `getCookies` function that retrieves the cookies sent with the HTTP request when the browser window connects (to the websocket). [#137][]+* Allow Electron process to be accessed from JavaScript FFI. [#200][] This means that Threepenny is now more useful when used with the [Electron][] framework, see [doc/electron.md](doc/electron.md) for more information on that.+* Bump dependencies to allow `file-embed` 0.0.10.1++ [#137]: https://github.com/HeinrichApfelmus/threepenny-gui/issues/137+ [#200]: https://github.com/HeinrichApfelmus/threepenny-gui/issues/200+ [electron]: https://electron.atom.io+ **0.8.1.0** — Snapshot release * Improve documentation and handling of call buffering (`CallBufferMode`). The default call buffer mode was documented incorrectly, it was `BufferRun` and is now `FlushOften`. [#163][], [#191][], [#192][]
js/index.html view
@@ -3,7 +3,12 @@ <meta charset="UTF-8"> <title></title> <link rel="stylesheet" type="text/css" href="haskell.css"/>++ <!-- See https://stackoverflow.com/a/37480521 -->+ <script>if (typeof module === 'object') {window.module = module; module = undefined;}</script> <script src="haskell.js"></script>+ <script>if (window.module) module = window.module;</script>+ <script type="text/javascript" charset="utf-8"> Haskell.initFFI(); </script>
src/Foreign/JavaScript.hs view
@@ -18,7 +18,7 @@ , jsCustomHTML, jsStatic, jsLog , jsWindowReloadOnDisconnect, jsCallBufferMode), Server, MimeType, URI, loadFile, loadDirectory,- Window, getServer, root,+ Window, getServer, getCookies, root, -- * JavaScript FFI ToJS(..), FromJS, JSFunction, JSObject, JavaScriptException,
src/Foreign/JavaScript/EventLoop.hs view
@@ -46,8 +46,8 @@ -- | Event loop for a browser window. -- Supports concurrent invocations of `runEval` and `callEval`.-eventLoop :: (Window -> IO void) -> (Server -> Comm -> IO ())-eventLoop init server comm = void $ do+eventLoop :: (Window -> IO void) -> EventLoop+eventLoop init server info comm = void $ do -- To support concurrent FFI calls, we need three threads. -- A fourth thread supports --@@ -91,6 +91,7 @@ w0 <- newPartialWindow let w = w0 { getServer = server+ , getCookies = info , runEval = run . RunEval , callEval = call . CallEval , debug = debug
src/Foreign/JavaScript/Server.hs view
@@ -25,7 +25,7 @@ import qualified Data.Aeson as JSON import qualified Network.WebSockets as WS import qualified Network.WebSockets.Snap as WS-import Snap.Core+import Snap.Core as Snap import qualified Snap.Http.Server as Snap import Snap.Util.FileServe @@ -37,7 +37,7 @@ HTTP Server using WebSockets ------------------------------------------------------------------------------} -- | Run a HTTP server that creates a 'Comm' channel.-httpComm :: Config -> (Server -> Comm -> IO ()) -> IO ()+httpComm :: Config -> EventLoop -> IO () httpComm Config{..} worker = do env <- getEnvironment let portEnv = Safe.readMay =<< Prelude.lookup "PORT" env@@ -56,13 +56,15 @@ ++ routeWebsockets (worker server) -- | Route the communication between JavaScript and the server-routeWebsockets :: (Comm -> IO void) -> Routes+routeWebsockets :: (RequestInfo -> Comm -> IO void) -> Routes routeWebsockets worker = [("websocket", response)] where- response = WS.runWebSocketsSnap $ \ws -> void $ do- comm <- communicationFromWebSocket ws- worker comm- -- error "Foreign.JavaScript: unreachable code path."+ response = do+ requestInfo <- Snap.getRequest+ WS.runWebSocketsSnap $ \ws -> void $ do+ comm <- communicationFromWebSocket ws+ worker (rqCookies requestInfo) comm+ -- error "Foreign.JavaScript: unreachable code path." -- | Create 'Comm' channel from WebSocket request. communicationFromWebSocket :: WS.PendingConnection -> IO Comm
src/Foreign/JavaScript/Types.hs view
@@ -15,6 +15,7 @@ import Data.String import Data.Text import Data.Typeable+import Snap.Core (Cookie(..)) import System.IO (stderr) import Foreign.RemotePtr@@ -223,14 +224,14 @@ {----------------------------------------------------------------------------- Window & Event Loop ------------------------------------------------------------------------------}-data Consistency = Consistent | Inconsistent-type Event = (Coupon, JSON.Value, Consistency)+-- | An event sent from the browser window to the server.+type Event = (Coupon, JSON.Value) -- | An event handler that can be passed to the JavaScript client. type HsEvent = RemotePtr (JSON.Value -> IO ()) quit :: Event-quit = ("quit", JSON.Null, Consistent)+quit = ("quit", JSON.Null) -- | Specification of how JavaScript functions should be called. data CallBufferMode@@ -256,10 +257,17 @@ flushPeriod = 300 :: Int +-- | Action that the server will run when a browser window connects.+type EventLoop = Server -> RequestInfo -> Comm -> IO ()+type RequestInfo = [Cookie]+ -- | Representation of a browser window. data Window = Window { getServer :: Server- -- ^ Server that tbe browser window communicates with.+ -- ^ Server that the browser window communicates with.+ , getCookies :: [Cookie]+ -- ^ Cookies that the browser window has sent to the server when connecting.+ , runEval :: String -> IO () , callEval :: String -> IO JSON.Value @@ -284,7 +292,7 @@ b1 <- newTVarIO id b2 <- newTVarIO NoBuffering let nop = const $ return ()- Window undefined nop undefined b1 b2 (return ()) nop nop ptr <$> newVendor <*> newVendor+ Window undefined [] nop undefined b1 b2 (return ()) nop nop ptr <$> newVendor <*> newVendor -- | For the purpose of controlling garbage collection, -- every 'Window' as an associated 'RemotePtr' that is alive
threepenny-gui.cabal view
@@ -1,5 +1,5 @@ Name: threepenny-gui-Version: 0.8.1.0+Version: 0.8.2.0 Synopsis: GUI framework that uses the web browser as a display. Description: Threepenny-GUI is a GUI framework that uses the web browser as a display.@@ -116,7 +116,7 @@ ,deepseq >= 1.3.0 && < 1.5 ,exceptions >= 0.6 && < 0.9 ,filepath >= 1.3.0 && < 1.5.0- ,file-embed == 0.0.10+ ,file-embed >= 0.0.10 && < 0.1 ,hashable >= 1.1.0 && < 1.3 ,safe == 0.3.* ,snap-server >= 0.9.0 && < 1.1