@@ -15,6 +15,8 @@ import Data.ByteString (useAsCString, packCString)
15import qualified Data.ByteString as BS (ByteString)
15import qualified Data.ByteString as BS (ByteString)
16import Data.ByteString.Lazy (ByteString, toStrict, fromStrict)
16import Data.ByteString.Lazy (ByteString, toStrict, fromStrict)
17import Data.Aeson (encode, decode)
17import Data.Aeson (encode, decode)
18+import qualified Data.Text as T (pack)
19+import Data.Text.Encoding (encodeUtf8)
19import Foreign.C.String (CString)
21import Foreign.C.String (CString)
20import Foreign.Ptr (Ptr, nullPtr)
22import Foreign.Ptr (Ptr, nullPtr)
@@ -24,6 +26,8 @@ import Language.Javascript.JSaddle (Results, Batch, JSM)
24import Language.Javascript.JSaddle.Run (runJavaScript)
26import Language.Javascript.JSaddle.Run (runJavaScript)
25import Language.Javascript.JSaddle.Run.Files (initState, runBatch, ghcjsHelpers)
27import Language.Javascript.JSaddle.Run.Files (initState, runBatch, ghcjsHelpers)
29+import System.Directory (getCurrentDirectory)
27newtype WKWebView = WKWebView (Ptr WKWebView)
31newtype WKWebView = WKWebView (Ptr WKWebView)
28newtype JSaddleHandler = JSaddleHandler (Ptr JSaddleHandler)
32newtype JSaddleHandler = JSaddleHandler (Ptr JSaddleHandler)
@@ -34,7 +38,7 @@ foreign export ccall callWithWebView :: WKWebView -> StablePtr (WKWebView -> IO
34foreign export ccall callWithCString :: CString -> StablePtr (CString -> IO ()) -> IO ()
38foreign export ccall callWithCString :: CString -> StablePtr (CString -> IO ()) -> IO ()
35foreign export ccall callIO :: StablePtr (IO ()) -> IO ()
39foreign export ccall callIO :: StablePtr (IO ()) -> IO ()
36foreign import ccall addJSaddleHandler :: WKWebView -> StablePtr (IO ()) -> StablePtr (Results -> IO ()) -> StablePtr (Results -> IO Batch) -> IO ()
40foreign import ccall addJSaddleHandler :: WKWebView -> StablePtr (IO ()) -> StablePtr (Results -> IO ()) -> StablePtr (Results -> IO Batch) -> IO ()
37−foreign import ccall loadHTMLString :: WKWebView -> CString -> IO ()
41+foreign import ccall loadHTMLStringWithBaseURL :: WKWebView -> CString -> CString -> IO ()
38foreign import ccall loadBundleFile :: WKWebView -> CString -> CString -> IO ()
42foreign import ccall loadBundleFile :: WKWebView -> CString -> CString -> IO ()
39foreign import ccall evaluateJavaScript :: WKWebView -> CString -> IO ()
43foreign import ccall evaluateJavaScript :: WKWebView -> CString -> IO ()
40foreign import ccall completeSync :: JSaddleHandler -> CString -> IO ()
44foreign import ccall completeSync :: JSaddleHandler -> CString -> IO ()
@@ -42,9 +46,13 @@ foreign import ccall mainBundleResourcePathC :: IO CString
43-- | Run JSaddle in WKWebView
47-- | Run JSaddle in WKWebView
44jsaddleMain :: JSM () -> WKWebView -> IO ()
48jsaddleMain :: JSM () -> WKWebView -> IO ()
45−jsaddleMain f webView =
49+jsaddleMain f webView = do
50+ pwd <- getCurrentDirectory
51+ let baseURL = encodeUtf8 $ "file://" <> T.pack pwd <> "/index.html"
46 jsaddleMain' f webView $
52 jsaddleMain' f webView $
53+ useAsCString baseURL $ \url ->
47− useAsCString (toStrict indexHtml) $ loadHTMLString webView
54+ useAsCString (toStrict indexHtml) $ \html ->
55+ loadHTMLStringWithBaseURL webView html url
49-- | Run JSaddle in a WKWebView first loading the specified file
57-- | Run JSaddle in a WKWebView first loading the specified file
50-- from the mainBundle (relative to the resourcePath).
58-- from the mainBundle (relative to the resourcePath).
@@ -140,4 +148,3 @@ mainBundleResourcePath = do
140 if bs == nullPtr
148 if bs == nullPtr
141 then return Nothing
149 then return Nothing
142 else Just <$> packCString bs
150 else Just <$> packCString bs