@@ -1,9 +1,12 @@
1module Language.Javascript.JSaddle.WKWebView
1module Language.Javascript.JSaddle.WKWebView
2 ( jsaddleMain
2 ( jsaddleMain
3+ , jsaddleMainHTMLWithBaseURL
3 , jsaddleMainFile
4 , jsaddleMainFile
4 , WKWebView(..)
5 , WKWebView(..)
6 , runWithAppConfig
8 , runWithAppConfig
8 , mainBundleResourcePath
11 , mainBundleResourcePath
9 , AppDelegateConfig (..)
12 , AppDelegateConfig (..)
@@ -17,7 +20,8 @@ import Data.Set (Set)
17import qualified Data.Set as Set
20import qualified Data.Set as Set
18import Data.Word
21import Data.Word
19import Foreign.Marshal.Utils (fromBool)
22import 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)
21import System.Environment (getProgName)
25import System.Environment (getProgName)
22import Foreign.C.String (CString, withCString)
26import Foreign.C.String (CString, withCString)
23import Foreign.StablePtr (StablePtr, newStablePtr)
27import Foreign.StablePtr (StablePtr, newStablePtr)
@@ -96,29 +100,38 @@ instance Default AppDelegateNotificationConfig where
97-- | Run JSaddle in a WKWebView
101-- | Run JSaddle in a WKWebView
98run :: JSM () -> IO ()
102run :: JSM () -> IO ()
99−run = run' Nothing def
103+run f = run' def (jsaddleMain f)
101-- | Run JSaddle in a WKWebView
105-- | Run JSaddle in a WKWebView
102runWithAppConfig :: AppDelegateConfig -> JSM () -> IO ()
106runWithAppConfig :: AppDelegateConfig -> JSM () -> IO ()
103−runWithAppConfig = run' Nothing
107+runWithAppConfig cfg = run' cfg . jsaddleMain
105-- | Run JSaddle in a WKWebView first loading the specified file
109-- | Run JSaddle in a WKWebView first loading the specified file
106-- from the mainBundle (relative to the resourcePath).
110-- from the mainBundle (relative to the resourcePath).
107−runFile :: ByteString -- ^ The file to navigate to.
112+ :: ByteString -- ^ The file to navigate to.
108− -> ByteString -- ^ The path to allow read access to.
113+ -> ByteString -- ^ The path to allow read access to.
109− -> AppDelegateConfig
114+ -> AppDelegateConfig
110− -> JSM ()
115+ -> JSM ()
111− -> IO ()
116+ -> IO ()
112−runFile url allowing = run' $ Just (url, allowing)
117+runFile url allowing cfg = run' cfg . jsaddleMainFile url allowing
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).
114−run' :: Maybe (ByteString, ByteString)
123+ :: ByteString -- ^ HTML to load.
124+ -> ByteString -- ^ pretend it came from this URL.
115− -> AppDelegateConfig
125+ -> AppDelegateConfig
116− -> JSM ()
126+ -> JSM ()
128+runHTMLWithBaseURL url allowing cfg = run' cfg . jsaddleMainHTMLWithBaseURL url allowing
130+run' :: AppDelegateConfig
131+ -> (WKWebView -> IO ())
118−run' mUrl cfg f = do
133+run' cfg main = do
119− handler <- case mUrl of
134+ handler <- newStablePtr main
120− Just (url, allowing) -> newStablePtr (jsaddleMainFile url allowing f)
121− Nothing -> newStablePtr (jsaddleMain f)
122 progName <- getProgName
135 progName <- getProgName
124 -- AppDelegate callbacks
137 -- AppDelegate callbacks