diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-02-23 17:05:59 +0100 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-02-23 17:05:59 +0100 |
commit | db80fcad9ffe47cc0349a01eb38093b3c4ad6862 (patch) | |
tree | cea0e212fc9f141d4e1e7b3005bfb3a5aba4c3f2 /webgui | |
parent | 2c55c6f2afabde93a3579d1042f189f34e821753 (diff) | |
download | thermoprint-db80fcad9ffe47cc0349a01eb38093b3c4ad6862.tar thermoprint-db80fcad9ffe47cc0349a01eb38093b3c4ad6862.tar.gz thermoprint-db80fcad9ffe47cc0349a01eb38093b3c4ad6862.tar.bz2 thermoprint-db80fcad9ffe47cc0349a01eb38093b3c4ad6862.tar.xz thermoprint-db80fcad9ffe47cc0349a01eb38093b3c4ad6862.zip |
Added stability to websockets
Diffstat (limited to 'webgui')
-rw-r--r-- | webgui/src/Main.hs | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/webgui/src/Main.hs b/webgui/src/Main.hs index 7ead572..92aba0e 100644 --- a/webgui/src/Main.hs +++ b/webgui/src/Main.hs | |||
@@ -87,11 +87,11 @@ setup Config{..} window (split -> (socketErr, dataUpdate)) = void $ do | |||
87 | prntBtn <- UI.button #+ [string "Print"] | 87 | prntBtn <- UI.button #+ [string "Print"] |
88 | 88 | ||
89 | getBody window #+ [ row [ column [ UI.h1 #+ [string "Current draft"] | 89 | getBody window #+ [ row [ column [ UI.h1 #+ [string "Current draft"] |
90 | , row [UI.label # set text "Title" # set UI.for "title", element title # set style [("width", "100%")]] | 90 | , row [UI.label # set text "Title" # set UI.for "title", element title] |
91 | , element content # set style [("width", "100%")] | 91 | , element content |
92 | , row [ element saveBtn # set style [("width", "100%")] | 92 | , row [ element saveBtn |
93 | , element prntBtn # set style [("width", "100%")] | 93 | , element prntBtn |
94 | , element discBtn # set style [("width", "100%")] | 94 | , element discBtn |
95 | ] | 95 | ] |
96 | ] | 96 | ] |
97 | , column [ UI.h1 #+ [string "Saved drafts"] | 97 | , column [ UI.h1 #+ [string "Saved drafts"] |
@@ -102,11 +102,10 @@ setup Config{..} window (split -> (socketErr, dataUpdate)) = void $ do | |||
102 | 102 | ||
103 | where | 103 | where |
104 | handleSocketErr InvalidMessage = debug "Received unparseable message from websocket" | 104 | handleSocketErr InvalidMessage = debug "Received unparseable message from websocket" |
105 | handleSocketErr e@(UnknownException e') = void $ do | 105 | handleSocketErr e@(Unhandled e') = void $ fatalError (show e') >> liftIO (throwIO e) |
106 | getBody window #+ [UI.p # set text (show e') # set UI.id_ "error"] | 106 | fatalError str = (getBody window #) . set children =<< sequence [UI.p # set text str # set UI.id_ "fatal-error"] |
107 | liftIO $ throwIO e | ||
108 | 107 | ||
109 | data WebSocketException = InvalidMessage | UnknownException SomeException | 108 | data WebSocketException = ProcessDied | InvalidMessage | Unhandled SomeException |
110 | deriving (Show) | 109 | deriving (Show) |
111 | 110 | ||
112 | instance Exception WebSocketException | 111 | instance Exception WebSocketException |
@@ -115,7 +114,7 @@ withWebSocket :: (Config -> Window -> Event (Either WebSocketException URI) -> U | |||
115 | withWebSocket setup c@(Config{..}) w = do | 114 | withWebSocket setup c@(Config{..}) w = do |
116 | (dataUpdate, triggerData) <- liftIO newEvent | 115 | (dataUpdate, triggerData) <- liftIO newEvent |
117 | let | 116 | let |
118 | rcvEvents = runClient (baseUrlHost server) (baseUrlPort server) "" $ forever . (triggerData . maybe (Left InvalidMessage) Right . parseURI . T.unpack <=< receiveData) | 117 | rcvEvents = runClient (baseUrlHost server) (baseUrlPort server) "/" $ forever . (triggerData . maybe (Left InvalidMessage) Right . parseURI . T.unpack <=< receiveData) |
119 | liftIO . forkIO $ rcvEvents `catchAll` (triggerData . Left . UnknownException) | 118 | liftIOLater . void $ forkFinally (rcvEvents `catchAll` (triggerData . Left . Unhandled)) (triggerData $ Left ProcessDied) |
120 | void $ setup c w dataUpdate | 119 | void $ setup c w dataUpdate |
121 | 120 | ||