@@ -15,6 +15,8 @@ import Data.ByteString (useAsCString, packCString)
1515import qualified Data.ByteString as BS (ByteString)
1616import Data.ByteString.Lazy (ByteString, toStrict, fromStrict)
1717import Data.Aeson (encode, decode)
18+import qualified Data.Text as T (pack)
19+import Data.Text.Encoding (encodeUtf8)
1820
1921import Foreign.C.String (CString)
2022import Foreign.Ptr (Ptr, nullPtr)
@@ -24,6 +26,8 @@ import Language.Javascript.JSaddle (Results, Batch, JSM)
2426import Language.Javascript.JSaddle.Run (runJavaScript)
2527import Language.Javascript.JSaddle.Run.Files (initState, runBatch, ghcjsHelpers)
2628
29+import System.Directory (getCurrentDirectory)
30+
2731newtype WKWebView = WKWebView (Ptr WKWebView)
2832newtype JSaddleHandler = JSaddleHandler (Ptr JSaddleHandler)
2933
@@ -34,7 +38,7 @@ foreign export ccall callWithWebView :: WKWebView -> StablePtr (WKWebView -> IO
3438foreign export ccall callWithCString :: CString -> StablePtr (CString -> IO ()) -> IO ()
3539foreign export ccall callIO :: StablePtr (IO ()) -> IO ()
3640foreign 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 ()
3842foreign import ccall loadBundleFile :: WKWebView -> CString -> CString -> IO ()
3943foreign import ccall evaluateJavaScript :: WKWebView -> CString -> IO ()
4044foreign import ccall completeSync :: JSaddleHandler -> CString -> IO ()
@@ -42,9 +46,13 @@ foreign import ccall mainBundleResourcePathC :: IO CString
4246
4347-- | Run JSaddle in WKWebView
4448jsaddleMain :: 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"
4652 jsaddleMain' f webView $
47− useAsCString (toStrict indexHtml) $ loadHTMLString webView
53+ useAsCString baseURL $ \url ->
54+ useAsCString (toStrict indexHtml) $ \html ->
55+ loadHTMLStringWithBaseURL webView html url
4856
4957-- | Run JSaddle in a WKWebView first loading the specified file
5058-- from the mainBundle (relative to the resourcePath).
@@ -140,4 +148,3 @@ mainBundleResourcePath = do
140148 if bs == nullPtr
141149 then return Nothing
142150 else Just <$> packCString bs
143−