@@ -24,6 +24,7 @@ import Language.Javascript.JSaddle.WKWebView.Internal
24 (jsaddleMain, jsaddleMainHTMLWithBaseURL, jsaddleMainFile, WKWebView(..), mainBundleResourcePath)
24 (jsaddleMain, jsaddleMainHTMLWithBaseURL, jsaddleMainFile, WKWebView(..), mainBundleResourcePath)
25import System.Environment (getProgName)
25import System.Environment (getProgName)
26import Foreign.C.String (CString, withCString)
26import Foreign.C.String (CString, withCString)
27+import Foreign.C.Types (CBool)
27import Foreign.StablePtr (StablePtr, newStablePtr)
28import Foreign.StablePtr (StablePtr, newStablePtr)
28import Language.Javascript.JSaddle (JSM)
29import Language.Javascript.JSaddle (JSM)
@@ -47,7 +48,8 @@ foreign import ccall runInWKWebView
47 -> Word64 -- registerForRemoteNotifications
48 -> Word64 -- registerForRemoteNotifications
48 -> StablePtr (CString -> IO ()) -- didRegisterForRemoteNotificationsWithDeviceToken
49 -> StablePtr (CString -> IO ()) -- didRegisterForRemoteNotificationsWithDeviceToken
49 -> StablePtr (CString -> IO ()) -- didFailToRegisterForRemoteNotificationsWithError
50 -> StablePtr (CString -> IO ()) -- didFailToRegisterForRemoteNotificationsWithError
50− -> Word64 -- Allow developer tools
51+ -> Word64 -- developerExtrasEnabled
52+ -> StablePtr (CString -> IO CBool) -- applicationOpenFile
53data AppDelegateConfig = AppDelegateConfig
55data AppDelegateConfig = AppDelegateConfig
@@ -60,8 +62,20 @@ data AppDelegateConfig = AppDelegateConfig
60 , _appDelegateConfig_applicationWillTerminate :: IO ()
62 , _appDelegateConfig_applicationWillTerminate :: IO ()
61 , _appDelegateConfig_applicationSignificantTimeChange :: IO ()
63 , _appDelegateConfig_applicationSignificantTimeChange :: IO ()
62 , _appDelegateConfig_applicationUniversalLink :: CString -> IO ()
64 , _appDelegateConfig_applicationUniversalLink :: CString -> IO ()
65+ -- ^ Called when the app is launched from a URL. 'CString' contains the URL.
67+ -- The Core Foundation plist key CFBundleURLTypes controls which URL schemes
68+ -- the app should respond to.
63 , _appDelegateConfig_appDelegateNotificationConfig :: AppDelegateNotificationConfig
69 , _appDelegateConfig_appDelegateNotificationConfig :: AppDelegateNotificationConfig
64 , _appDelegateConfig_developerExtrasEnabled :: Bool
70 , _appDelegateConfig_developerExtrasEnabled :: Bool
71+ -- ^ Allow devtools in the app. Defaults to 'True'
72+ , _appDelegateConfig_applicationOpenFile :: CString -> IO Bool
73+ -- ^ Called when the app is launched by opening a file. 'CString' contains
74+ -- the file path. Return value is 'True' if the file was successfully
75+ -- opened. Defaults to ignoring the file and returning 'False'.
77+ -- The Core Foundation plist key CFBundleDocumentTypes controls which file
78+ -- types should be associated with the app.
67instance Default AppDelegateConfig where
81instance Default AppDelegateConfig where
@@ -77,6 +91,7 @@ instance Default AppDelegateConfig where
77 , _appDelegateConfig_applicationUniversalLink = \_ -> return ()
91 , _appDelegateConfig_applicationUniversalLink = \_ -> return ()
78 , _appDelegateConfig_appDelegateNotificationConfig = def
92 , _appDelegateConfig_appDelegateNotificationConfig = def
79 , _appDelegateConfig_developerExtrasEnabled = True
93 , _appDelegateConfig_developerExtrasEnabled = True
94+ , _appDelegateConfig_applicationOpenFile = \_ -> return False
82data AuthorizationOption = AuthorizationOption_Badge
97data AuthorizationOption = AuthorizationOption_Badge
@@ -147,6 +162,7 @@ run' cfg main = do
147 applicationWillTerminate <- newStablePtr $ _appDelegateConfig_applicationWillTerminate cfg
162 applicationWillTerminate <- newStablePtr $ _appDelegateConfig_applicationWillTerminate cfg
148 applicationSignificantTimeChange <- newStablePtr $ _appDelegateConfig_applicationSignificantTimeChange cfg
163 applicationSignificantTimeChange <- newStablePtr $ _appDelegateConfig_applicationSignificantTimeChange cfg
149 applicationUniversalLink <- newStablePtr $ _appDelegateConfig_applicationUniversalLink cfg
164 applicationUniversalLink <- newStablePtr $ _appDelegateConfig_applicationUniversalLink cfg
165+ applicationOpenFile <- newStablePtr $ fmap fromBool . _appDelegateConfig_applicationOpenFile cfg
151 -- AppDelegate notification configuration
167 -- AppDelegate notification configuration
152 let ncfg = _appDelegateConfig_appDelegateNotificationConfig cfg
168 let ncfg = _appDelegateConfig_appDelegateNotificationConfig cfg
@@ -178,3 +194,4 @@ run' cfg main = do
178 didRegisterForRemoteNotificationsWithDeviceToken
194 didRegisterForRemoteNotificationsWithDeviceToken
179 didFailToRegisterForRemoteNotificationsWithError
195 didFailToRegisterForRemoteNotificationsWithError
180 (fromBool $ _appDelegateConfig_developerExtrasEnabled cfg)
196 (fromBool $ _appDelegateConfig_developerExtrasEnabled cfg)