@@ -21,16 +21,18 @@ import Foreign.C.Types
21import Foreign.StablePtr (StablePtr, newStablePtr)
21import Foreign.StablePtr (StablePtr, newStablePtr)
22import Language.Javascript.JSaddle (JSM)
22import Language.Javascript.JSaddle (JSM)
24−foreign import ccall runInWKWebView :: StablePtr (WKWebView -> IO ())
24+foreign import ccall runInWKWebView
25+ :: StablePtr (WKWebView -> IO ())
25− -> CString
26+ -> CString
26− -> CChar -- whether to run requestAuthorizationWithOptions
27+ -> CChar -- whether to run requestAuthorizationWithOptions
27− -> CChar -- Ask for Badge authorization
28+ -> CChar -- Ask for Badge authorization
28− -> CChar -- Ask for Sound authorization
29+ -> CChar -- Ask for Sound authorization
29− -> CChar -- Ask for Alert authorization
30+ -> CChar -- Ask for Alert authorization
30− -> CChar -- Ask for CarPlay authorization
31+ -> CChar -- Ask for CarPlay authorization
31− -> CChar -- registerForRemoteNotifications
32+ -> CChar -- registerForRemoteNotifications
32− -> StablePtr (CString -> IO ()) -- didRegisterForRemoteNotificationsWithDeviceToken
33+ -> StablePtr (CString -> IO ()) -- didRegisterForRemoteNotificationsWithDeviceToken
34+ -> StablePtr (CString -> IO ()) -- didFailToRegisterForRemoteNotificationsWithError
36data AppDelegateConfig = AppDelegateConfig
38data AppDelegateConfig = AppDelegateConfig
@@ -52,6 +54,7 @@ data AppDelegateNotificationConfig = AppDelegateNotificationConfig
52 { _appDelegateNotificationConfig_requestAuthorizationWithOptions :: Maybe (Set AuthorizationOption)
54 { _appDelegateNotificationConfig_requestAuthorizationWithOptions :: Maybe (Set AuthorizationOption)
53 , _appDelegateNotificationConfig_registerForRemoteNotifications :: Bool
55 , _appDelegateNotificationConfig_registerForRemoteNotifications :: Bool
54 , _appDelegateNotificationConfig_didRegisterForRemoteNotificationsWithDeviceToken :: CString -> IO ()
56 , _appDelegateNotificationConfig_didRegisterForRemoteNotificationsWithDeviceToken :: CString -> IO ()
57+ , _appDelegateNotificationConfig_didFailToRegisterForRemoteNotificationsWithError :: CString -> IO ()
57instance Default AppDelegateNotificationConfig where
60instance Default AppDelegateNotificationConfig where
@@ -59,16 +62,13 @@ instance Default AppDelegateNotificationConfig where
59 { _appDelegateNotificationConfig_requestAuthorizationWithOptions = Nothing
62 { _appDelegateNotificationConfig_requestAuthorizationWithOptions = Nothing
60 , _appDelegateNotificationConfig_registerForRemoteNotifications = False
63 , _appDelegateNotificationConfig_registerForRemoteNotifications = False
61 , _appDelegateNotificationConfig_didRegisterForRemoteNotificationsWithDeviceToken = \_ -> return ()
64 , _appDelegateNotificationConfig_didRegisterForRemoteNotificationsWithDeviceToken = \_ -> return ()
65+ , _appDelegateNotificationConfig_didFailToRegisterForRemoteNotificationsWithError = \_ -> return ()
65-- | Run JSaddle in a WKWebView
69-- | Run JSaddle in a WKWebView
66−run :: (CString -> IO ()) -> JSM () -> IO ()
70+run :: AppDelegateConfig -> JSM () -> IO ()
67−run didRegisterForRemoteNotificationsWithDeviceToken f = do
71+run = run' Nothing
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
73-- | Run JSaddle in a WKWebView first loading the specified file
73-- | Run JSaddle in a WKWebView first loading the specified file
74-- from the mainBundle (relative to the resourcePath).
74-- from the mainBundle (relative to the resourcePath).
@@ -77,8 +77,16 @@ runFile :: ByteString -- ^ The file to navigate to.
77 -> AppDelegateConfig
77 -> AppDelegateConfig
80−runFile url allowing cfg f = do
80+runFile url allowing = run' $ Just (url, allowing)
82+run' :: Maybe (ByteString, ByteString)
87+ handler <- case mUrl of
81− handler <- newStablePtr (jsaddleMainFile url allowing f)
88+ Just (url, allowing) -> newStablePtr (jsaddleMainFile url allowing f)
89+ Nothing -> newStablePtr (jsaddleMain f)
82 progName <- getProgName
90 progName <- getProgName
83 let ncfg = _appDelegateConfig_appDelegateNotificationConfig cfg
91 let ncfg = _appDelegateConfig_appDelegateNotificationConfig cfg
84 (requestAuthorizationWithOptions, authorizationOptions) =
92 (requestAuthorizationWithOptions, authorizationOptions) =
@@ -87,6 +95,7 @@ runFile url allowing cfg f = do
87 Just opts -> (True, opts)
95 Just opts -> (True, opts)
88 registerForRemoteNotifications = _appDelegateNotificationConfig_registerForRemoteNotifications ncfg
96 registerForRemoteNotifications = _appDelegateNotificationConfig_registerForRemoteNotifications ncfg
89 didRegisterForRemoteNotificationsWithDeviceToken <- newStablePtr $ _appDelegateNotificationConfig_didRegisterForRemoteNotificationsWithDeviceToken ncfg
97 didRegisterForRemoteNotificationsWithDeviceToken <- newStablePtr $ _appDelegateNotificationConfig_didRegisterForRemoteNotificationsWithDeviceToken ncfg
98+ didFailToRegisterForRemoteNotificationsWithError <- newStablePtr $ _appDelegateNotificationConfig_didFailToRegisterForRemoteNotificationsWithError ncfg
90 withCString progName $ \pn -> runInWKWebView
99 withCString progName $ \pn -> runInWKWebView
@@ -97,3 +106,4 @@ runFile url allowing cfg f = do
97 (boolToCChar $ Set.member AuthorizationOption_CarPlay authorizationOptions)
106 (boolToCChar $ Set.member AuthorizationOption_CarPlay authorizationOptions)
98 (boolToCChar registerForRemoteNotifications)
107 (boolToCChar registerForRemoteNotifications)
99 didRegisterForRemoteNotificationsWithDeviceToken
108 didRegisterForRemoteNotificationsWithDeviceToken
109+ didFailToRegisterForRemoteNotificationsWithError