@@ -21,16 +21,18 @@ import Foreign.C.Types
2121import Foreign.StablePtr (StablePtr, newStablePtr)
2222import Language.Javascript.JSaddle (JSM)
2323
24−foreign import ccall runInWKWebView :: StablePtr (WKWebView -> IO ())
25− -> CString
26− -> CChar -- whether to run requestAuthorizationWithOptions
27− -> CChar -- Ask for Badge authorization
28− -> CChar -- Ask for Sound authorization
29− -> CChar -- Ask for Alert authorization
30− -> CChar -- Ask for CarPlay authorization
31− -> CChar -- registerForRemoteNotifications
32− -> StablePtr (CString -> IO ()) -- didRegisterForRemoteNotificationsWithDeviceToken
33− -> IO ()
24+foreign import ccall runInWKWebView
25+ :: StablePtr (WKWebView -> IO ())
26+ -> CString
27+ -> CChar -- whether to run requestAuthorizationWithOptions
28+ -> CChar -- Ask for Badge authorization
29+ -> CChar -- Ask for Sound authorization
30+ -> CChar -- Ask for Alert authorization
31+ -> CChar -- Ask for CarPlay authorization
32+ -> CChar -- registerForRemoteNotifications
33+ -> StablePtr (CString -> IO ()) -- didRegisterForRemoteNotificationsWithDeviceToken
34+ -> StablePtr (CString -> IO ()) -- didFailToRegisterForRemoteNotificationsWithError
35+ -> IO ()
3436
3537
3638data AppDelegateConfig = AppDelegateConfig
@@ -52,6 +54,7 @@ data AppDelegateNotificationConfig = AppDelegateNotificationConfig
5254 { _appDelegateNotificationConfig_requestAuthorizationWithOptions :: Maybe (Set AuthorizationOption)
5355 , _appDelegateNotificationConfig_registerForRemoteNotifications :: Bool
5456 , _appDelegateNotificationConfig_didRegisterForRemoteNotificationsWithDeviceToken :: CString -> IO ()
57+ , _appDelegateNotificationConfig_didFailToRegisterForRemoteNotificationsWithError :: CString -> IO ()
5558 }
5659
5760instance Default AppDelegateNotificationConfig where
@@ -59,16 +62,13 @@ instance Default AppDelegateNotificationConfig where
5962 { _appDelegateNotificationConfig_requestAuthorizationWithOptions = Nothing
6063 , _appDelegateNotificationConfig_registerForRemoteNotifications = False
6164 , _appDelegateNotificationConfig_didRegisterForRemoteNotificationsWithDeviceToken = \_ -> return ()
65+ , _appDelegateNotificationConfig_didFailToRegisterForRemoteNotificationsWithError = \_ -> return ()
6266 }
6367
6468
6569-- | Run JSaddle in a WKWebView
66−run :: (CString -> IO ()) -> JSM () -> IO ()
67−run didRegisterForRemoteNotificationsWithDeviceToken f = do
68− handler <- newStablePtr (jsaddleMain f)
69− progName <- getProgName
70− deviceTokenHandler <- newStablePtr didRegisterForRemoteNotificationsWithDeviceToken
71− withCString progName $ \pn -> runInWKWebView handler pn 1 1 1 1 1 1 deviceTokenHandler
70+run :: AppDelegateConfig -> JSM () -> IO ()
71+run = run' Nothing
7272
7373-- | Run JSaddle in a WKWebView first loading the specified file
7474-- from the mainBundle (relative to the resourcePath).
@@ -77,8 +77,16 @@ runFile :: ByteString -- ^ The file to navigate to.
7777 -> AppDelegateConfig
7878 -> JSM ()
7979 -> IO ()
80−runFile url allowing cfg f = do
81− handler <- newStablePtr (jsaddleMainFile url allowing f)
80+runFile url allowing = run' $ Just (url, allowing)
81+
82+run' :: Maybe (ByteString, ByteString)
83+ -> AppDelegateConfig
84+ -> JSM ()
85+ -> IO ()
86+run' mUrl cfg f = do
87+ handler <- case mUrl of
88+ Just (url, allowing) -> newStablePtr (jsaddleMainFile url allowing f)
89+ Nothing -> newStablePtr (jsaddleMain f)
8290 progName <- getProgName
8391 let ncfg = _appDelegateConfig_appDelegateNotificationConfig cfg
8492 (requestAuthorizationWithOptions, authorizationOptions) =
@@ -87,6 +95,7 @@ runFile url allowing cfg f = do
8795 Just opts -> (True, opts)
8896 registerForRemoteNotifications = _appDelegateNotificationConfig_registerForRemoteNotifications ncfg
8997 didRegisterForRemoteNotificationsWithDeviceToken <- newStablePtr $ _appDelegateNotificationConfig_didRegisterForRemoteNotificationsWithDeviceToken ncfg
98+ didFailToRegisterForRemoteNotificationsWithError <- newStablePtr $ _appDelegateNotificationConfig_didFailToRegisterForRemoteNotificationsWithError ncfg
9099 withCString progName $ \pn -> runInWKWebView
91100 handler
92101 pn
@@ -97,3 +106,4 @@ runFile url allowing cfg f = do
97106 (boolToCChar $ Set.member AuthorizationOption_CarPlay authorizationOptions)
98107 (boolToCChar registerForRemoteNotifications)
99108 didRegisterForRemoteNotificationsWithDeviceToken
109+ didFailToRegisterForRemoteNotificationsWithError