on ca29b24 help sign in
jsaddle-wkwebview/cbits-uikit/AppDelegate.m+109−2
since splitsnapshots
unifiedsplit
@@ -1,55 +1,162 @@
1#import "AppDelegate.h"
1#import "AppDelegate.h"
2#import "ViewController.h"
2#import "ViewController.h"
3+#import <UserNotifications/UserNotifications.h>
4+#import <stdint.h>
3
5
4−@interface AppDelegate ()
6+extern void callIO(HsStablePtr);
7+extern void callWithCString(const char * _Nonnull, HsStablePtr);
5
8
9+@interface AppDelegate ()
6
10
7@end
11@end
8
12
9HsStablePtr globalHandler = 0;
13HsStablePtr globalHandler = 0;
14+HsStablePtr global_willFinishLaunchingWithOptions = 0;
15+HsStablePtr global_didFinishLaunchingWithOptions = 0;
16+HsStablePtr global_applicationDidBecomeActive = 0;
17+HsStablePtr global_applicationWillResignActive = 0;
18+HsStablePtr global_applicationDidEnterBackground = 0;
19+HsStablePtr global_applicationWillEnterForeground = 0;
20+HsStablePtr global_applicationWillTerminate = 0;
21+HsStablePtr global_applicationSignificantTimeChange = 0;
22+uint64_t global_requestAuthorizationWithOptions = 0;
23+uint64_t global_requestAuthorizationOptionBadge = 0;
24+uint64_t global_requestAuthorizationOptionSound = 0;
25+uint64_t global_requestAuthorizationOptionAlert = 0;
26+uint64_t global_requestAuthorizationOptionCarPlay = 0;
27+uint64_t global_registerForRemoteNotifications = 0;
28+HsStablePtr global_didRegisterForRemoteNotificationsWithDeviceToken = 0;
29+HsStablePtr global_didFailToRegisterForRemoteNotificationsWithError = 0;
10
30
11@implementation AppDelegate
31@implementation AppDelegate
12
32
33+- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
34+ // Tells the delegate that the launch process has begun but that state restoration has not yet occurred.
35+ callIO(global_willFinishLaunchingWithOptions);
36+ return YES;
37+}
38+
13- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
39- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
40+ // Tells the delegate that the launch process is almost done and the app is almost ready to run.
14 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
41 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
15 // Override point for customization after application launch.
42 // Override point for customization after application launch.
16 self.window.rootViewController = [[ViewController alloc] initWithHandler:globalHandler];
43 self.window.rootViewController = [[ViewController alloc] initWithHandler:globalHandler];
17 self.window.backgroundColor = [UIColor whiteColor];
44 self.window.backgroundColor = [UIColor whiteColor];
18 [self.window makeKeyAndVisible];
45 [self.window makeKeyAndVisible];
46+ UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
47+ center.delegate = self;
48+ if (global_requestAuthorizationWithOptions) {
49+ UNAuthorizationOptions options = (UNAuthorizationOptions)0;
50+ if (global_requestAuthorizationOptionBadge) {
51+ options = options | UNAuthorizationOptionBadge;
52+ }
53+ if (global_requestAuthorizationOptionSound) {
54+ options = options | UNAuthorizationOptionSound;
55+ }
56+ if (global_requestAuthorizationOptionAlert) {
57+ options = options | UNAuthorizationOptionAlert;
58+ }
59+ if (global_requestAuthorizationOptionCarPlay) {
60+ options = options | UNAuthorizationOptionCarPlay;
61+ }
62+ [center requestAuthorizationWithOptions:(options)
63+ completionHandler:^(BOOL granted, NSError * _Nullable error) {
64+ // Handler used to alter application behavior based on types of notifications authorized
65+ }];
66+ if (global_registerForRemoteNotifications) {
67+ [application registerForRemoteNotifications];
68+ }
69+ }
70+ callIO(global_didFinishLaunchingWithOptions);
19 return YES;
71 return YES;
20}
72}
21
73
22- (void)applicationWillResignActive:(UIApplication *)application {
74- (void)applicationWillResignActive:(UIApplication *)application {
23 // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
75 // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24 // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
76 // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
77+ callIO(global_applicationWillResignActive);
25}
78}
26
79
27
80
28- (void)applicationDidEnterBackground:(UIApplication *)application {
81- (void)applicationDidEnterBackground:(UIApplication *)application {
29 // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
82 // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
30 // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
83 // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
84+ callIO(global_applicationDidEnterBackground);
31}
85}
32
86
33
87
34- (void)applicationWillEnterForeground:(UIApplication *)application {
88- (void)applicationWillEnterForeground:(UIApplication *)application {
35 // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
89 // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
90+ callIO(global_applicationWillEnterForeground);
36}
91}
37
92
38
93
39- (void)applicationDidBecomeActive:(UIApplication *)application {
94- (void)applicationDidBecomeActive:(UIApplication *)application {
40 // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
95 // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
96+ callIO(global_applicationDidBecomeActive);
41}
97}
42
98
43
99
44- (void)applicationWillTerminate:(UIApplication *)application {
100- (void)applicationWillTerminate:(UIApplication *)application {
45 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
101 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
102+ callIO(global_applicationWillTerminate);
103+}
104+
105+- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
106+ // Tells the delegate that the app successfully registered with Apple Push Notification service (APNs).
107+ NSString *deviceTokenString = [deviceToken base64EncodedStringWithOptions: 0];
108+ callWithCString([deviceTokenString UTF8String], global_didRegisterForRemoteNotificationsWithDeviceToken);
109+}
110+
111+- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
112+ // Sent to the delegate when Apple Push Notification service cannot successfully complete the registration process.
113+ NSString *errorString = [error localizedDescription];
114+ callWithCString([errorString UTF8String], global_didFailToRegisterForRemoteNotificationsWithError);
115+}
116+
117+- (void)applicationSignificantTimeChange:(UIApplication *)application {
118+ // Tells the delegate when there is a significant change in the time.
119+ callIO(global_applicationSignificantTimeChange);
46}
120}
47
121
48@end
122@end
49
123
50−void runInWKWebView(HsStablePtr handler, const char * _Nonnull progName) {
124+void runInWKWebView(HsStablePtr handler,
125+ const char * _Nonnull progName,
126+ HsStablePtr hs_willFinishLaunchingWithOptions,
127+ HsStablePtr hs_didFinishLaunchingWithOptions,
128+ HsStablePtr hs_applicationDidBecomeActive,
129+ HsStablePtr hs_applicationWillResignActive,
130+ HsStablePtr hs_applicationDidEnterBackground,
131+ HsStablePtr hs_applicationWillEnterForeground,
132+ HsStablePtr hs_applicationWillTerminate,
133+ HsStablePtr hs_applicationSignificantTimeChange,
134+ const uint64_t hs_requestAuthorizationWithOptions,
135+ const uint64_t hs_requestAuthorizationOptionBadge,
136+ const uint64_t hs_requestAuthorizationOptionSound,
137+ const uint64_t hs_requestAuthorizationOptionAlert,
138+ const uint64_t hs_requestAuthorizationOptionCarPlay,
139+ const uint64_t hs_registerForRemoteNotifications,
140+ HsStablePtr hs_didRegisterForRemoteNotificationsWithDeviceToken,
141+ HsStablePtr hs_didFailToRegisterForRemoteNotificationsWithError) {
51 @autoreleasepool {
142 @autoreleasepool {
52 globalHandler = handler;
143 globalHandler = handler;
144+ global_willFinishLaunchingWithOptions = hs_willFinishLaunchingWithOptions;
145+ global_didFinishLaunchingWithOptions = hs_didFinishLaunchingWithOptions;
146+ global_applicationDidBecomeActive = hs_applicationDidBecomeActive;
147+ global_applicationWillResignActive = hs_applicationWillResignActive;
148+ global_applicationDidEnterBackground = hs_applicationDidEnterBackground;
149+ global_applicationWillEnterForeground = hs_applicationWillEnterForeground;
150+ global_applicationWillTerminate = hs_applicationWillTerminate;
151+ global_applicationSignificantTimeChange = hs_applicationSignificantTimeChange;
152+ global_requestAuthorizationWithOptions = hs_requestAuthorizationWithOptions;
153+ global_requestAuthorizationOptionBadge = hs_requestAuthorizationOptionBadge;
154+ global_requestAuthorizationOptionSound = hs_requestAuthorizationOptionSound;
155+ global_requestAuthorizationOptionAlert = hs_requestAuthorizationOptionAlert;
156+ global_requestAuthorizationOptionCarPlay = hs_requestAuthorizationOptionCarPlay;
157+ global_registerForRemoteNotifications = hs_registerForRemoteNotifications;
158+ global_didRegisterForRemoteNotificationsWithDeviceToken = hs_didRegisterForRemoteNotificationsWithDeviceToken;
159+ global_didFailToRegisterForRemoteNotificationsWithError = hs_didFailToRegisterForRemoteNotificationsWithError;
53 const char * _Nonnull argv [] = {"", 0};
160 const char * _Nonnull argv [] = {"", 0};
54 UIApplicationMain(0, argv, nil, NSStringFromClass([AppDelegate class]));
161 UIApplicationMain(0, argv, nil, NSStringFromClass([AppDelegate class]));
55 }
162 }
jsaddle-wkwebview/cbits-uikit/ViewController.m+2−2
@@ -1,6 +1,6 @@
1#import "ViewController.h"
1#import "ViewController.h"
2
2
3−extern void withWebView(WKWebView *, HsStablePtr);
3+extern void callWithWebView(WKWebView *, HsStablePtr);
4
4
5@interface ViewController ()
5@interface ViewController ()
6
6
@@ -27,7 +27,7 @@ extern void withWebView(WKWebView *, HsStablePtr);
27
27
28- (void)viewDidLoad {
28- (void)viewDidLoad {
29 [super viewDidLoad];
29 [super viewDidLoad];
30− withWebView(_webView, _handler);
30+ callWithWebView(_webView, _handler);
31}
31}
32
32
33
33
jsaddle-wkwebview/default.nix+2−2
@@ -1,4 +1,4 @@
1−{ mkDerivation, stdenv, aeson, base, bytestring, jsaddle
1+{ mkDerivation, stdenv, aeson, base, bytestring, jsaddle, data-default
2, buildPackages
2, buildPackages
3}:
3}:
4
4
@@ -6,7 +6,7 @@ mkDerivation {
6 pname = "jsaddle-wkwebview";
6 pname = "jsaddle-wkwebview";
7 version = "0.8.3.2";
7 version = "0.8.3.2";
8 src = ./.;
8 src = ./.;
9− libraryHaskellDepends = [ aeson base bytestring jsaddle ]
9+ libraryHaskellDepends = [ aeson base bytestring jsaddle data-default ]
10 # should use `librarySystemDepends` but it is not propagated
10 # should use `librarySystemDepends` but it is not propagated
11 ++ (with buildPackages; [
11 ++ (with buildPackages; [
12 darwin.libobjc
12 darwin.libobjc
jsaddle-wkwebview/jsaddle-wkwebview.cabal+15−7
@@ -14,6 +14,10 @@ description:
14category: Web, Javascript
14category: Web, Javascript
15author: Hamish Mackenzie
15author: Hamish Mackenzie
16
16
17+flag include-app-delegate
18+ description: Include default AppDelegate C sources.
19+ default: True
20+
17source-repository head
21source-repository head
18 type: git
22 type: git
19 location: https://github.com/ghcjs/jsaddle
23 location: https://github.com/ghcjs/jsaddle
@@ -26,7 +30,9 @@ library
26 aeson >=0.8.0.2 && <1.3,
30 aeson >=0.8.0.2 && <1.3,
27 base <5,
31 base <5,
28 bytestring >=0.10.6.0 && <0.11,
32 bytestring >=0.10.6.0 && <0.11,
29− jsaddle >= 0.8.0.0 && <0.9
33+ jsaddle >= 0.8.0.0 && <0.9,
34+ data-default,
35+ containers
30 default-language: Haskell2010
36 default-language: Haskell2010
31 hs-source-dirs: src
37 hs-source-dirs: src
32 frameworks: Foundation, WebKit
38 frameworks: Foundation, WebKit
@@ -38,11 +44,13 @@ library
38 else
44 else
39 hs-source-dirs: src-ghc
45 hs-source-dirs: src-ghc
40 if os(ios)
46 if os(ios)
41− frameworks: UIKit
47+ frameworks: UIKit, UserNotifications
48+ if flag(include-app-delegate)
42− c-sources:
49+ c-sources:
43− cbits-uikit/AppDelegate.m
50+ cbits-uikit/AppDelegate.m
44− cbits-uikit/ViewController.m
51+ cbits-uikit/ViewController.m
45 else
52 else
46 frameworks: Cocoa
53 frameworks: Cocoa
54+ if flag(include-app-delegate)
47− c-sources:
55+ c-sources:
48− cbits-cocoa/AppDelegate.m
56+ cbits-cocoa/AppDelegate.m
jsaddle-wkwebview/src-ghc/Language/Javascript/JSaddle/WKWebView.hs+133−9
@@ -3,32 +3,156 @@ module Language.Javascript.JSaddle.WKWebView
3 , jsaddleMainFile
3 , jsaddleMainFile
4 , WKWebView(..)
4 , WKWebView(..)
5 , run
5 , run
6+ , runWithAppConfig
6 , runFile
7 , runFile
7 , mainBundleResourcePath
8 , mainBundleResourcePath
9+ , AppDelegateConfig (..)
10+ , AppDelegateNotificationConfig (..)
11+ , AuthorizationOption (..)
8 ) where
12 ) where
9
13
10import Data.ByteString (ByteString)
14import Data.ByteString (ByteString)
15+import Data.Default (Default, def)
16+import Data.Set (Set)
17+import qualified Data.Set as Set
18+import Data.Word
19+import Foreign.Marshal.Utils (fromBool)
11import Language.Javascript.JSaddle.WKWebView.Internal (jsaddleMain, jsaddleMainFile, WKWebView(..), mainBundleResourcePath)
20import Language.Javascript.JSaddle.WKWebView.Internal (jsaddleMain, jsaddleMainFile, WKWebView(..), mainBundleResourcePath)
12import System.Environment (getProgName)
21import System.Environment (getProgName)
13import Foreign.C.String (CString, withCString)
22import Foreign.C.String (CString, withCString)
14import Foreign.StablePtr (StablePtr, newStablePtr)
23import Foreign.StablePtr (StablePtr, newStablePtr)
15import Language.Javascript.JSaddle (JSM)
24import Language.Javascript.JSaddle (JSM)
16
25
17−foreign import ccall runInWKWebView :: StablePtr (WKWebView -> IO ()) -> CString -> IO ()
26+foreign import ccall runInWKWebView
27+ :: StablePtr (WKWebView -> IO ())
28+ -> CString
29+ -> StablePtr (IO ()) -- willFinishLaunchingWithOptions
30+ -> StablePtr (IO ()) -- didFinishLaunchingWithOptions
31+ -> StablePtr (IO ()) -- applicationDidBecomeActive
32+ -> StablePtr (IO ()) -- applicationWillResignActive
33+ -> StablePtr (IO ()) -- applicationDidEnterBackground
34+ -> StablePtr (IO ()) -- applicationWillEnterForeground
35+ -> StablePtr (IO ()) -- applicationWillTerminate
36+ -> StablePtr (IO ()) -- applicationSignificantTimeChange
37+ -> Word64 -- whether to run requestAuthorizationWithOptions
38+ -> Word64 -- Ask for Badge authorization
39+ -> Word64 -- Ask for Sound authorization
40+ -> Word64 -- Ask for Alert authorization
41+ -> Word64 -- Ask for CarPlay authorization
42+ -> Word64 -- registerForRemoteNotifications
43+ -> StablePtr (CString -> IO ()) -- didRegisterForRemoteNotificationsWithDeviceToken
44+ -> StablePtr (CString -> IO ()) -- didFailToRegisterForRemoteNotificationsWithError
45+ -> IO ()
46+
47+data AppDelegateConfig = AppDelegateConfig
48+ { _appDelegateConfig_willFinishLaunchingWithOptions :: IO ()
49+ , _appDelegateConfig_didFinishLaunchingWithOptions :: IO ()
50+ , _appDelegateConfig_applicationDidBecomeActive :: IO ()
51+ , _appDelegateConfig_applicationWillResignActive :: IO ()
52+ , _appDelegateConfig_applicationDidEnterBackground :: IO ()
53+ , _appDelegateConfig_applicationWillEnterForeground :: IO ()
54+ , _appDelegateConfig_applicationWillTerminate :: IO ()
55+ , _appDelegateConfig_applicationSignificantTimeChange :: IO ()
56+ , _appDelegateConfig_appDelegateNotificationConfig :: AppDelegateNotificationConfig
57+ }
58+
59+instance Default AppDelegateConfig where
60+ def = AppDelegateConfig
61+ { _appDelegateConfig_willFinishLaunchingWithOptions = return ()
62+ , _appDelegateConfig_didFinishLaunchingWithOptions = return ()
63+ , _appDelegateConfig_applicationDidBecomeActive = return ()
64+ , _appDelegateConfig_applicationWillResignActive = return ()
65+ , _appDelegateConfig_applicationDidEnterBackground = return ()
66+ , _appDelegateConfig_applicationWillEnterForeground = return ()
67+ , _appDelegateConfig_applicationWillTerminate = return ()
68+ , _appDelegateConfig_applicationSignificantTimeChange = return ()
69+ , _appDelegateConfig_appDelegateNotificationConfig = def
70+ }
71+
72+data AuthorizationOption = AuthorizationOption_Badge
73+ | AuthorizationOption_Sound
74+ | AuthorizationOption_Alert
75+ | AuthorizationOption_CarPlay
76+ deriving (Show, Read, Eq, Ord)
77+
78+data AppDelegateNotificationConfig = AppDelegateNotificationConfig
79+ { _appDelegateNotificationConfig_requestAuthorizationWithOptions :: Maybe (Set AuthorizationOption)
80+ , _appDelegateNotificationConfig_registerForRemoteNotifications :: Bool
81+ , _appDelegateNotificationConfig_didRegisterForRemoteNotificationsWithDeviceToken :: CString -> IO ()
82+ , _appDelegateNotificationConfig_didFailToRegisterForRemoteNotificationsWithError :: CString -> IO ()
83+ }
84+
85+instance Default AppDelegateNotificationConfig where
86+ def = AppDelegateNotificationConfig
87+ { _appDelegateNotificationConfig_requestAuthorizationWithOptions = Nothing
88+ , _appDelegateNotificationConfig_registerForRemoteNotifications = False
89+ , _appDelegateNotificationConfig_didRegisterForRemoteNotificationsWithDeviceToken = \_ -> return ()
90+ , _appDelegateNotificationConfig_didFailToRegisterForRemoteNotificationsWithError = \_ -> return ()
91+ }
92+
18
93
19-- | Run JSaddle in a WKWebView
94-- | Run JSaddle in a WKWebView
20run :: JSM () -> IO ()
95run :: JSM () -> IO ()
21−run f = do
96+run = run' Nothing def
22− handler <- newStablePtr (jsaddleMain f)
97+
23− progName <- getProgName
98+-- | Run JSaddle in a WKWebView
24− withCString progName $ runInWKWebView handler
99+runWithAppConfig :: AppDelegateConfig -> JSM () -> IO ()
100+runWithAppConfig = run' Nothing
25
101
26-- | Run JSaddle in a WKWebView first loading the specified file
102-- | Run JSaddle in a WKWebView first loading the specified file
27-- from the mainBundle (relative to the resourcePath).
103-- from the mainBundle (relative to the resourcePath).
28runFile :: ByteString -- ^ The file to navigate to.
104runFile :: ByteString -- ^ The file to navigate to.
29 -> ByteString -- ^ The path to allow read access to.
105 -> ByteString -- ^ The path to allow read access to.
106+ -> AppDelegateConfig
30− -> JSM () -> IO ()
107+ -> JSM ()
108+ -> IO ()
31−runFile url allowing f = do
109+runFile url allowing = run' $ Just (url, allowing)
110+
111+run' :: Maybe (ByteString, ByteString)
112+ -> AppDelegateConfig
113+ -> JSM ()
114+ -> IO ()
115+run' mUrl cfg f = do
116+ handler <- case mUrl of
32− handler <- newStablePtr (jsaddleMainFile url allowing f)
117+ Just (url, allowing) -> newStablePtr (jsaddleMainFile url allowing f)
118+ Nothing -> newStablePtr (jsaddleMain f)
33 progName <- getProgName
119 progName <- getProgName
120+
121+ -- AppDelegate callbacks
122+ willFinishLaunchingWithOptions <- newStablePtr $ _appDelegateConfig_willFinishLaunchingWithOptions cfg
123+ didFinishLaunchingWithOptions <- newStablePtr $ _appDelegateConfig_didFinishLaunchingWithOptions cfg
124+ applicationDidBecomeActive <- newStablePtr $ _appDelegateConfig_applicationDidBecomeActive cfg
125+ applicationWillResignActive <- newStablePtr $ _appDelegateConfig_applicationWillResignActive cfg
126+ applicationDidEnterBackground <- newStablePtr $ _appDelegateConfig_applicationDidEnterBackground cfg
127+ applicationWillEnterForeground <- newStablePtr $ _appDelegateConfig_applicationWillEnterForeground cfg
128+ applicationWillTerminate <- newStablePtr $ _appDelegateConfig_applicationWillTerminate cfg
129+ applicationSignificantTimeChange <- newStablePtr $ _appDelegateConfig_applicationSignificantTimeChange cfg
130+
131+ -- AppDelegate notification configuration
132+ let ncfg = _appDelegateConfig_appDelegateNotificationConfig cfg
133+ (requestAuthorizationWithOptions, authorizationOptions) =
134+ case _appDelegateNotificationConfig_requestAuthorizationWithOptions ncfg of
135+ Nothing -> (False, Set.empty)
136+ Just opts -> (True, opts)
137+ registerForRemoteNotifications = _appDelegateNotificationConfig_registerForRemoteNotifications ncfg
138+ didRegisterForRemoteNotificationsWithDeviceToken <- newStablePtr $ _appDelegateNotificationConfig_didRegisterForRemoteNotificationsWithDeviceToken ncfg
139+ didFailToRegisterForRemoteNotificationsWithError <- newStablePtr $ _appDelegateNotificationConfig_didFailToRegisterForRemoteNotificationsWithError ncfg
34− withCString progName $ runInWKWebView handler
140+ withCString progName $ \pn -> runInWKWebView
141+ handler
142+ pn
143+ willFinishLaunchingWithOptions
144+ didFinishLaunchingWithOptions
145+ applicationDidBecomeActive
146+ applicationWillResignActive
147+ applicationDidEnterBackground
148+ applicationWillEnterForeground
149+ applicationWillTerminate
150+ applicationSignificantTimeChange
151+ (fromBool requestAuthorizationWithOptions)
152+ (fromBool $ Set.member AuthorizationOption_Badge authorizationOptions)
153+ (fromBool $ Set.member AuthorizationOption_Sound authorizationOptions)
154+ (fromBool $ Set.member AuthorizationOption_Alert authorizationOptions)
155+ (fromBool $ Set.member AuthorizationOption_CarPlay authorizationOptions)
156+ (fromBool registerForRemoteNotifications)
157+ didRegisterForRemoteNotificationsWithDeviceToken
158+ didFailToRegisterForRemoteNotificationsWithError
jsaddle-wkwebview/src/Language/Javascript/JSaddle/WKWebView/Internal.hs+16−3
@@ -30,7 +30,9 @@ newtype JSaddleHandler = JSaddleHandler (Ptr JSaddleHandler)
30foreign export ccall jsaddleStart :: StablePtr (IO ()) -> IO ()
30foreign export ccall jsaddleStart :: StablePtr (IO ()) -> IO ()
31foreign export ccall jsaddleResult :: StablePtr (Results -> IO ()) -> CString -> IO ()
31foreign export ccall jsaddleResult :: StablePtr (Results -> IO ()) -> CString -> IO ()
32foreign export ccall jsaddleSyncResult :: StablePtr (Results -> IO Batch) -> JSaddleHandler -> CString -> IO ()
32foreign export ccall jsaddleSyncResult :: StablePtr (Results -> IO Batch) -> JSaddleHandler -> CString -> IO ()
33−foreign export ccall withWebView :: WKWebView -> StablePtr (WKWebView -> IO ()) -> IO ()
33+foreign export ccall callWithWebView :: WKWebView -> StablePtr (WKWebView -> IO ()) -> IO ()
34+foreign export ccall callWithCString :: CString -> StablePtr (CString -> IO ()) -> IO ()
35+foreign export ccall callIO :: StablePtr (IO ()) -> IO ()
34foreign import ccall addJSaddleHandler :: WKWebView -> StablePtr (IO ()) -> StablePtr (Results -> IO ()) -> StablePtr (Results -> IO Batch) -> IO ()
36foreign import ccall addJSaddleHandler :: WKWebView -> StablePtr (IO ()) -> StablePtr (Results -> IO ()) -> StablePtr (Results -> IO Batch) -> IO ()
35foreign import ccall loadHTMLString :: WKWebView -> CString -> IO ()
37foreign import ccall loadHTMLString :: WKWebView -> CString -> IO ()
36foreign import ccall loadBundleFile :: WKWebView -> CString -> CString -> IO ()
38foreign import ccall loadBundleFile :: WKWebView -> CString -> CString -> IO ()
@@ -95,11 +97,21 @@ jsaddleSyncResult ptrHandler jsaddleHandler s = do
95 useAsCString (toStrict $ encode batch) $
97 useAsCString (toStrict $ encode batch) $
96 completeSync jsaddleHandler
98 completeSync jsaddleHandler
97
99
98−withWebView :: WKWebView -> StablePtr (WKWebView -> IO ()) -> IO ()
100+callWithWebView :: WKWebView -> StablePtr (WKWebView -> IO ()) -> IO ()
99−withWebView webView ptrF = do
101+callWithWebView webView ptrF = do
100 f <- deRefStablePtr ptrF
102 f <- deRefStablePtr ptrF
101 f webView
103 f webView
102
104
105+callWithCString :: CString -> StablePtr (CString -> IO ()) -> IO ()
106+callWithCString c fptr = do
107+ f <- deRefStablePtr fptr
108+ f c
109+
110+callIO :: StablePtr (IO ()) -> IO ()
111+callIO ptr = do
112+ f <- deRefStablePtr ptr
113+ f
114+
103jsaddleJs :: ByteString
115jsaddleJs :: ByteString
104jsaddleJs = ghcjsHelpers <> "\
116jsaddleJs = ghcjsHelpers <> "\
105 \runJSaddleBatch = (function() {\n\
117 \runJSaddleBatch = (function() {\n\
@@ -128,3 +140,4 @@ mainBundleResourcePath = do
128 if bs == nullPtr
140 if bs == nullPtr
129 then return Nothing
141 then return Nothing
130 else Just <$> packCString bs
142 else Just <$> packCString bs
143+