packages feed

jsaddle-wkwebview 0.9.7.0 → 0.9.7.1

raw patch · 4 files changed

+44/−4 lines, 4 filesdep ~aeson

Dependency ranges changed: aeson

Files

cbits-uikit/AppDelegate.m view
@@ -5,6 +5,7 @@  extern void callIO(HsStablePtr); extern void callWithCString(const char * _Nonnull, HsStablePtr);+extern void callWithCIntCString(int n, const char * _Nonnull, HsStablePtr);  @interface AppDelegate () @@ -20,6 +21,7 @@ HsStablePtr global_applicationWillTerminate = 0; HsStablePtr global_applicationSignificantTimeChange = 0; HsStablePtr global_applicationUniversalLink = 0;+HsStablePtr global_applicationDidReceiveRemoteNotification = 0; uint64_t global_requestAuthorizationWithOptions = 0; uint64_t global_requestAuthorizationOptionBadge = 0; uint64_t global_requestAuthorizationOptionSound = 0;@@ -115,6 +117,14 @@     if ([userInfo valueForKeyPath:@"aps.badge"] != nil) {         [UIApplication sharedApplication].applicationIconBadgeNumber=[[[userInfo objectForKey:@"aps"] objectForKey:@"badge"] intValue];     }+    NSError *error;+    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];+    if (jsonData) {+        NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];+        callWithCIntCString((int) application.applicationState, [jsonString UTF8String], global_applicationDidReceiveRemoteNotification);+    } else {+        NSLog(@"jsaddle-wkwebview didReceiveRemoteNotification handler: error while serialising push notification as JSON");+    }     completionHandler(UIBackgroundFetchResultNewData); } @@ -152,6 +162,7 @@                     HsStablePtr hs_applicationWillTerminate,                     HsStablePtr hs_applicationSignificantTimeChange,                     HsStablePtr hs_applicationUniversalLink,+                    HsStablePtr hs_applicationDidReceiveRemoteNotification,                     const uint64_t hs_requestAuthorizationWithOptions,                     const uint64_t hs_requestAuthorizationOptionBadge,                     const uint64_t hs_requestAuthorizationOptionSound,@@ -172,6 +183,7 @@         global_applicationWillTerminate = hs_applicationWillTerminate;         global_applicationSignificantTimeChange = hs_applicationSignificantTimeChange;         global_applicationUniversalLink = hs_applicationUniversalLink;+        global_applicationDidReceiveRemoteNotification = hs_applicationDidReceiveRemoteNotification;         global_requestAuthorizationWithOptions = hs_requestAuthorizationWithOptions;         global_requestAuthorizationOptionBadge = hs_requestAuthorizationOptionBadge;         global_requestAuthorizationOptionSound = hs_requestAuthorizationOptionSound;
jsaddle-wkwebview.cabal view
@@ -1,5 +1,5 @@ name: jsaddle-wkwebview-version: 0.9.7.0+version: 0.9.7.1 cabal-version: >=1.10 build-type: Simple license: MIT@@ -35,7 +35,7 @@         hs-source-dirs: src-ghcjs     else         build-depends:-            aeson >=0.8.0.2 && <1.5,+            aeson >=0.8.0.2 && <1.6,             bytestring >=0.10.6.0 && <0.11,             directory,             jsaddle >= 0.9.4.0 && <0.10,
src-ghc/Language/Javascript/JSaddle/WKWebView.hs view
@@ -9,6 +9,7 @@     , runHTMLWithBaseURL     , runFile     , mainBundleResourcePath+    , ApplicationState (..)     , AppDelegateConfig (..)     , AppDelegateNotificationConfig (..)     , AuthorizationOption (..)@@ -24,7 +25,7 @@        (jsaddleMain, jsaddleMainHTMLWithBaseURL, jsaddleMainFile, WKWebView(..), mainBundleResourcePath) import System.Environment (getProgName) import Foreign.C.String (CString, withCString)-import Foreign.C.Types (CBool)+import Foreign.C.Types (CBool, CInt) import Foreign.StablePtr (StablePtr, newStablePtr) import Language.Javascript.JSaddle (JSM) @@ -40,6 +41,7 @@     -> StablePtr (IO ()) -- applicationWillTerminate     -> StablePtr (IO ()) -- applicationSignificantTimeChange     -> StablePtr (CString -> IO ()) -- applicationUniversalLink+    -> StablePtr (CInt -> CString -> IO ()) -- applicationDidReceiveRemoteNotification     -> Word64  -- whether to run requestAuthorizationWithOptions     -> Word64 -- Ask for Badge authorization     -> Word64 -- Ask for Sound authorization@@ -66,6 +68,11 @@     --     -- The Core Foundation plist key CFBundleURLTypes controls which URL schemes     -- the app should respond to.+    , _appDelegateConfig_applicationDidReceiveRemoteNotification :: ApplicationState -> CString -> IO ()+    -- ^ Called when the application receives a remote notification.+    -- 'ApplicationState' is the current state of the app.+    -- The 'CString' JSON-encoded user info contained in the notification.+    -- For more information see https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623117-application?language=objc     , _appDelegateConfig_appDelegateNotificationConfig :: AppDelegateNotificationConfig     , _appDelegateConfig_developerExtrasEnabled :: Bool     -- ^ Allow devtools in the app. Defaults to 'True'@@ -89,6 +96,7 @@         , _appDelegateConfig_applicationWillTerminate = return ()         , _appDelegateConfig_applicationSignificantTimeChange = return ()         , _appDelegateConfig_applicationUniversalLink = \_ -> return ()+        , _appDelegateConfig_applicationDidReceiveRemoteNotification = \_ _ -> return ()         , _appDelegateConfig_appDelegateNotificationConfig = def         , _appDelegateConfig_developerExtrasEnabled = True         , _appDelegateConfig_applicationOpenFile = \_ -> return False@@ -100,6 +108,12 @@                          | AuthorizationOption_CarPlay     deriving (Show, Read, Eq, Ord) +data ApplicationState = ApplicationState_Active+                      | ApplicationState_Inactive+                      | ApplicationState_Background+                      | ApplicationState_Unknown CInt+    deriving (Show, Read, Eq, Ord)+ data AppDelegateNotificationConfig = AppDelegateNotificationConfig     { _appDelegateNotificationConfig_requestAuthorizationWithOptions :: Maybe (Set AuthorizationOption)     , _appDelegateNotificationConfig_registerForRemoteNotifications :: Bool@@ -162,6 +176,13 @@     applicationWillTerminate <- newStablePtr $ _appDelegateConfig_applicationWillTerminate cfg     applicationSignificantTimeChange <- newStablePtr $ _appDelegateConfig_applicationSignificantTimeChange cfg     applicationUniversalLink <- newStablePtr $ _appDelegateConfig_applicationUniversalLink cfg+    applicationDidReceiveRemoteNotification <- newStablePtr $ \n s -> do+      let appState = case n of+            0 -> ApplicationState_Active+            1 -> ApplicationState_Inactive+            2 -> ApplicationState_Background+            _ -> ApplicationState_Unknown n+      _appDelegateConfig_applicationDidReceiveRemoteNotification cfg appState s     applicationOpenFile <- newStablePtr $ fmap fromBool . _appDelegateConfig_applicationOpenFile cfg      -- AppDelegate notification configuration@@ -185,6 +206,7 @@       applicationWillTerminate       applicationSignificantTimeChange       applicationUniversalLink+      applicationDidReceiveRemoteNotification       (fromBool requestAuthorizationWithOptions)       (fromBool $ Set.member AuthorizationOption_Badge authorizationOptions)       (fromBool $ Set.member AuthorizationOption_Sound authorizationOptions)
src/Language/Javascript/JSaddle/WKWebView/Internal.hs view
@@ -20,7 +20,7 @@ import Data.Text.Encoding (encodeUtf8)  import Foreign.C.String (CString)-import Foreign.C.Types (CBool(..))+import Foreign.C.Types (CBool(..), CInt(..)) import Foreign.Ptr (Ptr, nullPtr) import Foreign.StablePtr (StablePtr, newStablePtr, deRefStablePtr) @@ -37,6 +37,7 @@ foreign export ccall jsaddleResult :: StablePtr (Results -> IO ()) -> CString -> IO () foreign export ccall jsaddleSyncResult :: StablePtr (Results -> IO Batch) -> JSaddleHandler -> CString -> IO () foreign export ccall callWithWebView :: WKWebView -> StablePtr (WKWebView -> IO ()) -> IO ()+foreign export ccall callWithCIntCString :: CInt -> CString -> StablePtr (CInt -> CString -> IO ()) -> IO () foreign export ccall callWithCString :: CString -> StablePtr (CString -> IO ()) -> IO () foreign export ccall callWithCStringReturningBool :: CString -> StablePtr (CString -> IO CBool) -> IO CBool foreign export ccall callIO :: StablePtr (IO ()) -> IO ()@@ -127,6 +128,11 @@ callWithCString c fptr = do     f <- deRefStablePtr fptr     f c++callWithCIntCString :: CInt -> CString -> StablePtr (CInt -> CString -> IO ()) -> IO ()+callWithCIntCString n s fptr = do+    f <- deRefStablePtr fptr+    f n s  callWithCStringReturningBool :: CString -> StablePtr (CString -> IO CBool) -> IO CBool callWithCStringReturningBool c fptr = do