@@ -1,9 +1,12 @@
11module Language.Javascript.JSaddle.WKWebView
22 ( jsaddleMain
3+ , jsaddleMainHTMLWithBaseURL
34 , jsaddleMainFile
45 , WKWebView(..)
56 , run
7+ , run'
68 , runWithAppConfig
9+ , runHTMLWithBaseURL
710 , runFile
811 , mainBundleResourcePath
912 , AppDelegateConfig (..)
@@ -17,7 +20,8 @@ import Data.Set (Set)
1720import qualified Data.Set as Set
1821import Data.Word
1922import Foreign.Marshal.Utils (fromBool)
20−import Language.Javascript.JSaddle.WKWebView.Internal (jsaddleMain, jsaddleMainFile, WKWebView(..), mainBundleResourcePath)
23+import Language.Javascript.JSaddle.WKWebView.Internal
24+ (jsaddleMain, jsaddleMainHTMLWithBaseURL, jsaddleMainFile, WKWebView(..), mainBundleResourcePath)
2125import System.Environment (getProgName)
2226import Foreign.C.String (CString, withCString)
2327import Foreign.StablePtr (StablePtr, newStablePtr)
@@ -96,29 +100,38 @@ instance Default AppDelegateNotificationConfig where
96100
97101-- | Run JSaddle in a WKWebView
98102run :: JSM () -> IO ()
99−run = run' Nothing def
103+run f = run' def (jsaddleMain f)
100104
101105-- | Run JSaddle in a WKWebView
102106runWithAppConfig :: AppDelegateConfig -> JSM () -> IO ()
103−runWithAppConfig = run' Nothing
107+runWithAppConfig cfg = run' cfg . jsaddleMain
104108
105109-- | Run JSaddle in a WKWebView first loading the specified file
106110-- from the mainBundle (relative to the resourcePath).
107−runFile :: ByteString -- ^ The file to navigate to.
108− -> ByteString -- ^ The path to allow read access to.
109− -> AppDelegateConfig
110− -> JSM ()
111− -> IO ()
112−runFile url allowing = run' $ Just (url, allowing)
111+runFile
112+ :: ByteString -- ^ The file to navigate to.
113+ -> ByteString -- ^ The path to allow read access to.
114+ -> AppDelegateConfig
115+ -> JSM ()
116+ -> IO ()
117+runFile url allowing cfg = run' cfg . jsaddleMainFile url allowing
113118
114−run' :: Maybe (ByteString, ByteString)
115− -> AppDelegateConfig
116− -> JSM ()
119+-- | Run JSaddle in a WKWebView first loading the specified html
120+-- as though it came from the specified URL
121+-- (calls WKWebKit function loadHTMLString).
122+runHTMLWithBaseURL
123+ :: ByteString -- ^ HTML to load.
124+ -> ByteString -- ^ pretend it came from this URL.
125+ -> AppDelegateConfig
126+ -> JSM ()
127+ -> IO ()
128+runHTMLWithBaseURL url allowing cfg = run' cfg . jsaddleMainHTMLWithBaseURL url allowing
129+
130+run' :: AppDelegateConfig
131+ -> (WKWebView -> IO ())
117132 -> IO ()
118−run' mUrl cfg f = do
119− handler <- case mUrl of
120− Just (url, allowing) -> newStablePtr (jsaddleMainFile url allowing f)
121− Nothing -> newStablePtr (jsaddleMain f)
133+run' cfg main = do
134+ handler <- newStablePtr main
122135 progName <- getProgName
123136
124137 -- AppDelegate callbacks