diff --git a/reflex-dom/src-android/Reflex/Dom/Android/MainWidget.hsc b/reflex-dom/src-android/Reflex/Dom/Android/MainWidget.hsc index 55a908a8..fada5b84 100644 --- a/reflex-dom/src-android/Reflex/Dom/Android/MainWidget.hsc +++ b/reflex-dom/src-android/Reflex/Dom/Android/MainWidget.hsc @@ -20,12 +20,15 @@ import Foreign.Marshal.Utils import Foreign.Marshal.Array import Foreign.Ptr import Foreign.Storable -import Language.Javascript.JSaddle (JSM) +import Language.Javascript.JSaddle (JSM, runJSM) import Language.Javascript.JSaddle.Run (runJavaScript) -import Language.Javascript.JSaddle.Run.Files (initState, runBatch, ghcjsHelpers) +import Language.Javascript.JSaddle.Run.Files (jsaddleCoreJs, ghcjsHelpers) #include "MainWidget.h" +-- TODO: Fix this in jsaddle +jsaddleCoreJsRenamed = "function jsaddleCoreJs" <> rem + where (Just rem) = LBS.stripPrefix "function jsaddle" jsaddleCoreJs startMainWidget :: HaskellActivity -> ByteString -> JSM () -> IO () startMainWidget a url jsm = do @@ -35,9 +38,9 @@ startMainWidget a url jsm = do executor <- readIORef executorRef BSU.unsafeUseAsCStringLen (LBS.toStrict $ "runJSaddleBatch(" <> encode batch <> ");") $ \(cstr, len) -> do runJS executor cstr (fromIntegral len) - (processResult, processSyncResult, start) <- runJavaScript go jsm + (processResult, processSyncResult, env) <- runJavaScript go callbacks <- new <=< jsaddleCallbacksToPtrs $ JSaddleCallbacks - { _jsaddleCallbacks_jsaddleStart = void $ forkIO start + { _jsaddleCallbacks_jsaddleStart = void $ forkIO $ runJSM jsm env , _jsaddleCallbacks_jsaddleResult = \s -> do case decode $ LBS.fromStrict s of Nothing -> error $ "jsaddle message decode failed: " <> show s @@ -46,12 +49,15 @@ startMainWidget a url jsm = do case decode $ LBS.fromStrict s of Nothing -> error $ "jsaddle message decode failed: " <> show s Just r -> LBS.toStrict . encode <$> processSyncResult r - , _jsaddleCallbacks_jsaddleJsData = LBS.toStrict $ ghcjsHelpers <> "\ + , _jsaddleCallbacks_jsaddleJsData = LBS.toStrict $ jsaddleCoreJsRenamed <> ghcjsHelpers <> "\ \runJSaddleBatch = (function() {\n\ - \ " <> initState <> "\n\ + \ var core = jsaddleCoreJs(window, function(a) {\n\ + \ jsaddle.postMessage(JSON.stringify(a));\n\ + \ }, function(a) {\n\ + \ return JSON.parse(jsaddle.syncMessage(JSON.stringify(a)));\n\ + \ });\n\ \ return function(batch) {\n\ - \ " <> runBatch (\a -> "jsaddle.postMessage(JSON.stringify(" <> a <> "));") - (Just (\a -> "JSON.parse(jsaddle.syncMessage(JSON.stringify(" <> a <> ")))")) <> "\ + \ for (req of batch) { core.processReq(req); }\n\ \ };\n\ \})();\n\ \jsaddle.postReady();\n"