Saving files
bradrn opened this issue · comments
When I try to save a file, I get a ConnectionClosed
error. Here's my code:
module Main where
import qualified Graphics.UI.Threepenny as UI
import Graphics.UI.Threepenny.Core
import System.Environment (getArgs)
import System.IO
main :: IO ()
main = do
hSetBuffering stdout LineBuffering
[port] <- getArgs
startGUI defaultConfig
{ jsPort = Just $ read port
, jsStatic = Just "static"
, jsCustomHTML = Just "index.html"
} setup
setup :: Window -> UI ()
setup window = do
saveBtn <- UI.button # set text "Save file"
on UI.click saveBtn $ const $ do
liftIO $ writeFile "~/test.txt" "Lorem ipsum dolor sit amet"
getBody window #+ [element saveBtn]
return ()
And the console log:
bradn@ubuntu:~/Documents/Haskell/hsTextEdit$ bin/hsTextEdit 8023
Listening on http://127.0.0.1:8023
127.0.0.1 - - [07/May/2017:18:27:02 +1000] "GET / HTTP/1.1" 304 0 - "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"
127.0.0.1 - - [07/May/2017:18:27:03 +1000] "GET /haskell.css HTTP/1.1" 200 80 "http://127.0.0.1:8023/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"
127.0.0.1 - - [07/May/2017:18:27:03 +1000] "GET /static/styles.css HTTP/1.1" 304 0 "http://127.0.0.1:8023/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"
127.0.0.1 - - [07/May/2017:18:27:03 +1000] "GET /haskell.js HTTP/1.1" 200 99184 "http://127.0.0.1:8023/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"
hsTextEdit: ConnectionClosed
^C
Shutting down..
As of version 0.8, Threepenny tries to be more forthcoming about error messages. I get the following console messages:
[...]
Foreign.JavaScript: Browser window disconnected.
~/test.txt: openFile: does not exist (No such file or directory)
In other words, your code throws an exception. This is because a directory named "~" does not exist — Shells like bash
or csh
will treat this character as the user's home directory, but it's not an actual directory in the file tree.
Which version of Threepenny did you use? If it's 0.8 or higher, then the exception message should be there.
Thank you!