From a34323685bcd6d786bdf13d53e5c1e70fa611b88 Mon Sep 17 00:00:00 2001 From: Joachim Breitner Date: Sat, 7 Sep 2019 16:47:12 +0200 Subject: [PATCH] Experiments with writing files from android more progress needs some way to request for permissions at runtime see https://github.com/reflex-frp/reflex-platform/issues/524 --- default.nix | 3 +++ kaleidogen.cabal | 2 ++ src/CanvasSave.hs | 8 ++++++++ 3 files changed, 13 insertions(+) diff --git a/default.nix b/default.nix index dbd8a35..a89dd6f 100644 --- a/default.nix +++ b/default.nix @@ -42,6 +42,9 @@ let executableName = "kaleidogen-android-clib"; applicationId = "de.nomeata.kaleidogen"; displayName = "Kaleidogen"; + permissions = '' + + ''; }; diff --git a/kaleidogen.cabal b/kaleidogen.cabal index 2681a12..896a48d 100644 --- a/kaleidogen.cabal +++ b/kaleidogen.cabal @@ -211,6 +211,8 @@ executable kaleidogen-android-clib build-depends: jsaddle build-depends: reflex-dom + build-depends: directory + if flag(android) build-depends: jsaddle-clib diff --git a/src/CanvasSave.hs b/src/CanvasSave.hs index 4839188..2cc2caf 100644 --- a/src/CanvasSave.hs +++ b/src/CanvasSave.hs @@ -15,6 +15,11 @@ import Language.Javascript.JSaddle (toJSVal) import Language.Javascript.JSaddle.Object import Control.Lens ((^.)) +import System.Directory +import System.IO +import System.IO.Error +import Control.Monad.Trans + src :: BS.ByteString src = $(embedFile "vendor/FileSaver.1.3.8.min.js") @@ -30,6 +35,9 @@ save :: MonadJSM m => T.Text -> HTMLCanvasElement -> m () save name e = liftJSM $ do domEl <- toJSVal e _ <- domEl ^. js1 "toBlob" (fun $ \_ _ [blob] -> () <$ jsg2 "saveAs" blob name ) + liftIO $ (`catchIOError` print) $ + createDirectory "/sdcard/Kaleidogen" + writeFile "/sdcard/Kaleidogen/test.txt" "hi" return () {-