on master help sign in
Merge pull request #95 from obsidiansystems/ts-dev-extras

Allow configuration of dev extras for wkwebview

commitc1cd12609ac021f386b7654444ad1cbcecd28844 authorHamish Mackenzie <Hamish.K.Mackenzie@googlemail.com> dateWed 10 Jul 2019, 11:27 (7 years ago) parente0ebd9ec12cb3f
3 files changed+13−3
jsaddle-wkwebview/cbits-cocoa/AppDelegate.m+7−2 jsaddle-wkwebview/cbits-uikit/AppDelegate.m+2−1 jsaddle-wkwebview/src-ghc/Language/Javascript/JSaddle/WKWebView.hs+4
jsaddle-wkwebview/cbits-cocoa/AppDelegate.m+7−2
@@ -16,6 +16,7 @@ extern void callWithWebView(WKWebView *, HsStablePtr);
1616HsStablePtr global_willFinishLaunchingWithOptions = 0;
1717HsStablePtr global_didFinishLaunchingWithOptions = 0;
1818HsStablePtr global_applicationUniversalLink = 0;
19+uint64_t global_developerExtrasEnabled = 1;
1920
2021@implementation AppDelegate
2122
@@ -39,7 +40,9 @@ HsStablePtr global_applicationUniversalLink = 0;
3940
4041-(void)applicationWillFinishLaunching:(NSNotification *)notification {
4142 WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
42− [theConfiguration.preferences setValue:@YES forKey:@"developerExtrasEnabled"];
43+ if (global_developerExtrasEnabled) {
44+ [theConfiguration.preferences setValue:@YES forKey:@"developerExtrasEnabled"];
45+ }
4346 WKWebView *webView = [[WKWebView alloc] initWithFrame: [_window.contentView frame] configuration:theConfiguration];
4447 [_window setContentView:webView];
4548 callWithWebView(webView, _handler);
@@ -89,11 +92,13 @@ void runInWKWebView(HsStablePtr handler,
8992 const uint64_t hs_requestAuthorizationOptionCarPlay,
9093 const uint64_t hs_registerForRemoteNotifications,
9194 HsStablePtr hs_didRegisterForRemoteNotificationsWithDeviceToken,
92− HsStablePtr hs_didFailToRegisterForRemoteNotificationsWithError) {
95+ HsStablePtr hs_didFailToRegisterForRemoteNotificationsWithError,
96+ const uint64_t hs_developerExtrasEnabled) {
9397 @autoreleasepool {
9498 global_willFinishLaunchingWithOptions = hs_willFinishLaunchingWithOptions;
9599 global_didFinishLaunchingWithOptions = hs_didFinishLaunchingWithOptions;
96100 global_applicationUniversalLink = hs_applicationUniversalLink;
101+ global_developerExtrasEnabled = hs_developerExtrasEnabled;
97102 NSApplication *application = [NSApplication sharedApplication];
98103 AppDelegate *appDelegate = [[AppDelegate alloc] initApp:handler progName:[NSString stringWithCString:progName encoding:NSUTF8StringEncoding]];
99104 [application setDelegate:appDelegate];
jsaddle-wkwebview/cbits-uikit/AppDelegate.m+2−1
@@ -159,7 +159,8 @@ void runInWKWebView(HsStablePtr handler,
159159 const uint64_t hs_requestAuthorizationOptionCarPlay,
160160 const uint64_t hs_registerForRemoteNotifications,
161161 HsStablePtr hs_didRegisterForRemoteNotificationsWithDeviceToken,
162− HsStablePtr hs_didFailToRegisterForRemoteNotificationsWithError) {
162+ HsStablePtr hs_didFailToRegisterForRemoteNotificationsWithError,
163+ const uint64_t hs_developerExtrasEnabled) {
163164 @autoreleasepool {
164165 globalHandler = handler;
165166 global_willFinishLaunchingWithOptions = hs_willFinishLaunchingWithOptions;
jsaddle-wkwebview/src-ghc/Language/Javascript/JSaddle/WKWebView.hs+4
@@ -47,6 +47,7 @@ foreign import ccall runInWKWebView
4747 -> Word64 -- registerForRemoteNotifications
4848 -> StablePtr (CString -> IO ()) -- didRegisterForRemoteNotificationsWithDeviceToken
4949 -> StablePtr (CString -> IO ()) -- didFailToRegisterForRemoteNotificationsWithError
50+ -> Word64 -- Allow developer tools
5051 -> IO ()
5152
5253data AppDelegateConfig = AppDelegateConfig
@@ -60,6 +61,7 @@ data AppDelegateConfig = AppDelegateConfig
6061 , _appDelegateConfig_applicationSignificantTimeChange :: IO ()
6162 , _appDelegateConfig_applicationUniversalLink :: CString -> IO ()
6263 , _appDelegateConfig_appDelegateNotificationConfig :: AppDelegateNotificationConfig
64+ , _appDelegateConfig_developerExtrasEnabled :: Bool
6365 }
6466
6567instance Default AppDelegateConfig where
@@ -74,6 +76,7 @@ instance Default AppDelegateConfig where
7476 , _appDelegateConfig_applicationSignificantTimeChange = return ()
7577 , _appDelegateConfig_applicationUniversalLink = \_ -> return ()
7678 , _appDelegateConfig_appDelegateNotificationConfig = def
79+ , _appDelegateConfig_developerExtrasEnabled = True
7780 }
7881
7982data AuthorizationOption = AuthorizationOption_Badge
@@ -174,3 +177,4 @@ run' cfg main = do
174177 (fromBool registerForRemoteNotifications)
175178 didRegisterForRemoteNotificationsWithDeviceToken
176179 didFailToRegisterForRemoteNotificationsWithError
180+ (fromBool $ _appDelegateConfig_developerExtrasEnabled cfg)