@@ -9,7 +9,6 @@ module Language.Javascript.JSaddle.WKWebView
9 , runHTMLWithBaseURL
9 , runHTMLWithBaseURL
11 , mainBundleResourcePath
11 , mainBundleResourcePath
12− , ApplicationState (..)
13 , AppDelegateConfig (..)
12 , AppDelegateConfig (..)
14 , AppDelegateNotificationConfig (..)
13 , AppDelegateNotificationConfig (..)
15 , AuthorizationOption (..)
14 , AuthorizationOption (..)
@@ -25,7 +24,6 @@ import Language.Javascript.JSaddle.WKWebView.Internal
25 (jsaddleMain, jsaddleMainHTMLWithBaseURL, jsaddleMainFile, WKWebView(..), mainBundleResourcePath)
24 (jsaddleMain, jsaddleMainHTMLWithBaseURL, jsaddleMainFile, WKWebView(..), mainBundleResourcePath)
26import System.Environment (getProgName)
25import System.Environment (getProgName)
27import Foreign.C.String (CString, withCString)
26import Foreign.C.String (CString, withCString)
28−import Foreign.C.Types (CBool, CInt)
29import Foreign.StablePtr (StablePtr, newStablePtr)
27import Foreign.StablePtr (StablePtr, newStablePtr)
30import Language.Javascript.JSaddle (JSM)
28import Language.Javascript.JSaddle (JSM)
@@ -41,7 +39,6 @@ foreign import ccall runInWKWebView
41 -> StablePtr (IO ()) -- applicationWillTerminate
39 -> StablePtr (IO ()) -- applicationWillTerminate
42 -> StablePtr (IO ()) -- applicationSignificantTimeChange
40 -> StablePtr (IO ()) -- applicationSignificantTimeChange
43 -> StablePtr (CString -> IO ()) -- applicationUniversalLink
41 -> StablePtr (CString -> IO ()) -- applicationUniversalLink
44− -> StablePtr (CInt -> CString -> IO ()) -- applicationDidReceiveRemoteNotification
45 -> Word64 -- whether to run requestAuthorizationWithOptions
42 -> Word64 -- whether to run requestAuthorizationWithOptions
46 -> Word64 -- Ask for Badge authorization
43 -> Word64 -- Ask for Badge authorization
47 -> Word64 -- Ask for Sound authorization
44 -> Word64 -- Ask for Sound authorization
@@ -50,8 +47,6 @@ foreign import ccall runInWKWebView
50 -> Word64 -- registerForRemoteNotifications
47 -> Word64 -- registerForRemoteNotifications
51 -> StablePtr (CString -> IO ()) -- didRegisterForRemoteNotificationsWithDeviceToken
48 -> StablePtr (CString -> IO ()) -- didRegisterForRemoteNotificationsWithDeviceToken
52 -> StablePtr (CString -> IO ()) -- didFailToRegisterForRemoteNotificationsWithError
49 -> StablePtr (CString -> IO ()) -- didFailToRegisterForRemoteNotificationsWithError
53− -> Word64 -- developerExtrasEnabled
54− -> StablePtr (CString -> IO CBool) -- applicationOpenFile
57data AppDelegateConfig = AppDelegateConfig
52data AppDelegateConfig = AppDelegateConfig
@@ -64,25 +59,7 @@ data AppDelegateConfig = AppDelegateConfig
64 , _appDelegateConfig_applicationWillTerminate :: IO ()
59 , _appDelegateConfig_applicationWillTerminate :: IO ()
65 , _appDelegateConfig_applicationSignificantTimeChange :: IO ()
60 , _appDelegateConfig_applicationSignificantTimeChange :: IO ()
66 , _appDelegateConfig_applicationUniversalLink :: CString -> IO ()
61 , _appDelegateConfig_applicationUniversalLink :: CString -> IO ()
67− -- ^ Called when the app is launched from a URL. 'CString' contains the URL.
69− -- The Core Foundation plist key CFBundleURLTypes controls which URL schemes
70− -- the app should respond to.
71− , _appDelegateConfig_applicationDidReceiveRemoteNotification :: ApplicationState -> CString -> IO ()
72− -- ^ Called when the application receives a remote notification.
73− -- 'ApplicationState' is the current state of the app.
74− -- The 'CString' JSON-encoded user info contained in the notification.
75− -- For more information see https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623117-application?language=objc
76 , _appDelegateConfig_appDelegateNotificationConfig :: AppDelegateNotificationConfig
62 , _appDelegateConfig_appDelegateNotificationConfig :: AppDelegateNotificationConfig
77− , _appDelegateConfig_developerExtrasEnabled :: Bool
78− -- ^ Allow devtools in the app. Defaults to 'True'
79− , _appDelegateConfig_applicationOpenFile :: CString -> IO Bool
80− -- ^ Called when the app is launched by opening a file. 'CString' contains
81− -- the file path. Return value is 'True' if the file was successfully
82− -- opened. Defaults to ignoring the file and returning 'False'.
84− -- The Core Foundation plist key CFBundleDocumentTypes controls which file
85− -- types should be associated with the app.
88instance Default AppDelegateConfig where
65instance Default AppDelegateConfig where
@@ -96,10 +73,7 @@ instance Default AppDelegateConfig where
96 , _appDelegateConfig_applicationWillTerminate = return ()
73 , _appDelegateConfig_applicationWillTerminate = return ()
97 , _appDelegateConfig_applicationSignificantTimeChange = return ()
74 , _appDelegateConfig_applicationSignificantTimeChange = return ()
98 , _appDelegateConfig_applicationUniversalLink = \_ -> return ()
75 , _appDelegateConfig_applicationUniversalLink = \_ -> return ()
99− , _appDelegateConfig_applicationDidReceiveRemoteNotification = \_ _ -> return ()
100 , _appDelegateConfig_appDelegateNotificationConfig = def
76 , _appDelegateConfig_appDelegateNotificationConfig = def
101− , _appDelegateConfig_developerExtrasEnabled = True
102− , _appDelegateConfig_applicationOpenFile = \_ -> return False
105data AuthorizationOption = AuthorizationOption_Badge
79data AuthorizationOption = AuthorizationOption_Badge
@@ -108,12 +82,6 @@ data AuthorizationOption = AuthorizationOption_Badge
108 | AuthorizationOption_CarPlay
82 | AuthorizationOption_CarPlay
109 deriving (Show, Read, Eq, Ord)
83 deriving (Show, Read, Eq, Ord)
111−data ApplicationState = ApplicationState_Active
112− | ApplicationState_Inactive
113− | ApplicationState_Background
114− | ApplicationState_Unknown CInt
115− deriving (Show, Read, Eq, Ord)
117data AppDelegateNotificationConfig = AppDelegateNotificationConfig
85data AppDelegateNotificationConfig = AppDelegateNotificationConfig
118 { _appDelegateNotificationConfig_requestAuthorizationWithOptions :: Maybe (Set AuthorizationOption)
86 { _appDelegateNotificationConfig_requestAuthorizationWithOptions :: Maybe (Set AuthorizationOption)
119 , _appDelegateNotificationConfig_registerForRemoteNotifications :: Bool
87 , _appDelegateNotificationConfig_registerForRemoteNotifications :: Bool
@@ -176,14 +144,6 @@ run' cfg main = do
176 applicationWillTerminate <- newStablePtr $ _appDelegateConfig_applicationWillTerminate cfg
144 applicationWillTerminate <- newStablePtr $ _appDelegateConfig_applicationWillTerminate cfg
177 applicationSignificantTimeChange <- newStablePtr $ _appDelegateConfig_applicationSignificantTimeChange cfg
145 applicationSignificantTimeChange <- newStablePtr $ _appDelegateConfig_applicationSignificantTimeChange cfg
178 applicationUniversalLink <- newStablePtr $ _appDelegateConfig_applicationUniversalLink cfg
146 applicationUniversalLink <- newStablePtr $ _appDelegateConfig_applicationUniversalLink cfg
179− applicationDidReceiveRemoteNotification <- newStablePtr $ \n s -> do
180− let appState = case n of
181− 0 -> ApplicationState_Active
182− 1 -> ApplicationState_Inactive
183− 2 -> ApplicationState_Background
184− _ -> ApplicationState_Unknown n
185− _appDelegateConfig_applicationDidReceiveRemoteNotification cfg appState s
186− applicationOpenFile <- newStablePtr $ fmap fromBool . _appDelegateConfig_applicationOpenFile cfg
188 -- AppDelegate notification configuration
148 -- AppDelegate notification configuration
189 let ncfg = _appDelegateConfig_appDelegateNotificationConfig cfg
149 let ncfg = _appDelegateConfig_appDelegateNotificationConfig cfg
@@ -206,7 +166,6 @@ run' cfg main = do
206 applicationWillTerminate
166 applicationWillTerminate
207 applicationSignificantTimeChange
167 applicationSignificantTimeChange
208 applicationUniversalLink
168 applicationUniversalLink
209− applicationDidReceiveRemoteNotification
210 (fromBool requestAuthorizationWithOptions)
169 (fromBool requestAuthorizationWithOptions)
211 (fromBool $ Set.member AuthorizationOption_Badge authorizationOptions)
170 (fromBool $ Set.member AuthorizationOption_Badge authorizationOptions)
212 (fromBool $ Set.member AuthorizationOption_Sound authorizationOptions)
171 (fromBool $ Set.member AuthorizationOption_Sound authorizationOptions)
@@ -215,5 +174,3 @@ run' cfg main = do
215 (fromBool registerForRemoteNotifications)
174 (fromBool registerForRemoteNotifications)
216 didRegisterForRemoteNotificationsWithDeviceToken
175 didRegisterForRemoteNotificationsWithDeviceToken
217 didFailToRegisterForRemoteNotificationsWithError
176 didFailToRegisterForRemoteNotificationsWithError
218− (fromBool $ _appDelegateConfig_developerExtrasEnabled cfg)