@capacitor/background-runner 1.0.4 → 1.0.5-dev-20230817T150324.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -417,4 +417,21 @@ Get access to device location information.
417
417
  | **`speed`** | <code>number \| null</code> | The speed the user is traveling (if available) | 1.0.0 |
418
418
  | **`heading`** | <code>number \| null</code> | The heading the user is facing (if available) | 1.0.0 |
419
419
 
420
+
421
+ #### CapcacitorWatch
422
+
423
+ Interact with a watch paired with this app
424
+
425
+ sendMessage, transferUserInfo and updateApplicationContext are raw routes to the WCSession delegate methods, but have no effects currently in a CapactiorWatch Watch application.
426
+ They could be used if a native watch app is developed as a companion app to a Capacitor app
427
+
428
+ | Prop | Type | Description |
429
+ | ------------------------------ | ------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
430
+ | **`sendMessage`** | <code>(options: []) =&gt; void</code> | Sends a message to the watch with the sendMessage() WCSession delegate method This has no effect on a CapacitorWatch watch app |
431
+ | **`transferUserInfo`** | <code>(options: []) =&gt; void</code> | Sends information to the watch with the transferUserInfo() WCSession delegate method This has no effect on a CapacitorWatch watch app |
432
+ | **`updateApplicationContext`** | <code>(options: []) =&gt; void</code> | Updates the application context on the watch with the updateApplicationContext() WCSession delegate method This has no effect on a CapacitorWatch watch app |
433
+ | **`isReachable`** | <code>boolean</code> | Checks to see if the compaion watch is reachable |
434
+ | **`updateWatchUI`** | <code>(options: { watchUI: string; }) =&gt; void</code> | Replaces the current UI on the watch with what is specified here. |
435
+ | **`updateWatchData`** | <code>(options: { data: { [key: string]: string; }; }) =&gt; void</code> | Updates the data the watch is using to display variables in text and button fields |
436
+
420
437
  </capacitor-api-docs>
@@ -6,6 +6,6 @@
6
6
  <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
7
7
 
8
8
  <application>
9
- <receiver android:name=".api.TimedNotificationPublisher" />
9
+ <receiver android:name="io.ionic.backgroundrunner.plugin.api.TimedNotificationPublisher" />
10
10
  </application>
11
11
  </manifest>
@@ -41,6 +41,15 @@
41
41
  "CapacitorGeolocation"
42
42
  ],
43
43
  "type": "CapacitorGeolocation"
44
+ },
45
+ {
46
+ "name": "CapacitorWatch",
47
+ "tags": [],
48
+ "docs": "",
49
+ "complexTypes": [
50
+ "CapcacitorWatch"
51
+ ],
52
+ "type": "CapcacitorWatch"
44
53
  }
45
54
  ]
46
55
  },
@@ -580,6 +589,75 @@
580
589
  "type": "number | null"
581
590
  }
582
591
  ]
592
+ },
593
+ {
594
+ "name": "CapcacitorWatch",
595
+ "slug": "capcacitorwatch",
596
+ "docs": "Interact with a watch paired with this app\n\nsendMessage, transferUserInfo and updateApplicationContext are raw routes to the WCSession delegate methods, but have no effects currently in a CapactiorWatch Watch application.\nThey could be used if a native watch app is developed as a companion app to a Capacitor app",
597
+ "tags": [],
598
+ "methods": [],
599
+ "properties": [
600
+ {
601
+ "name": "sendMessage",
602
+ "tags": [],
603
+ "docs": "Sends a message to the watch with the sendMessage() WCSession delegate method\n\nThis has no effect on a CapacitorWatch watch app",
604
+ "complexTypes": [],
605
+ "type": "(options: []) => void"
606
+ },
607
+ {
608
+ "name": "transferUserInfo",
609
+ "tags": [],
610
+ "docs": "Sends information to the watch with the transferUserInfo() WCSession delegate method\n\nThis has no effect on a CapacitorWatch watch app",
611
+ "complexTypes": [],
612
+ "type": "(options: []) => void"
613
+ },
614
+ {
615
+ "name": "updateApplicationContext",
616
+ "tags": [],
617
+ "docs": "Updates the application context on the watch with the updateApplicationContext() WCSession delegate method\n\nThis has no effect on a CapacitorWatch watch app",
618
+ "complexTypes": [],
619
+ "type": "(options: []) => void"
620
+ },
621
+ {
622
+ "name": "isReachable",
623
+ "tags": [],
624
+ "docs": "Checks to see if the compaion watch is reachable",
625
+ "complexTypes": [],
626
+ "type": "boolean"
627
+ },
628
+ {
629
+ "name": "updateWatchUI",
630
+ "tags": [
631
+ {
632
+ "text": "options the new WatchUI you want to show on the watch",
633
+ "name": "param"
634
+ },
635
+ {
636
+ "text": "void",
637
+ "name": "returns"
638
+ }
639
+ ],
640
+ "docs": "Replaces the current UI on the watch with what is specified here.",
641
+ "complexTypes": [],
642
+ "type": "(options: { watchUI: string; }) => void"
643
+ },
644
+ {
645
+ "name": "updateWatchData",
646
+ "tags": [
647
+ {
648
+ "text": "options the new data to send to the watch",
649
+ "name": "param"
650
+ },
651
+ {
652
+ "text": "void",
653
+ "name": "returns"
654
+ }
655
+ ],
656
+ "docs": "Updates the data the watch is using to display variables in text and button fields",
657
+ "complexTypes": [],
658
+ "type": "(options: { data: { [key: string]: string; }; }) => void"
659
+ }
660
+ ]
583
661
  }
584
662
  ],
585
663
  "enums": [],
@@ -309,9 +309,58 @@ export interface CapacitorNotifications {
309
309
  */
310
310
  schedule: (options: NotificationScheduleOptions[]) => void;
311
311
  }
312
+ /**
313
+ * Interact with a watch paired with this app
314
+ *
315
+ * sendMessage, transferUserInfo and updateApplicationContext are raw routes to the WCSession delegate methods, but have no effects currently in a CapactiorWatch Watch application.
316
+ * They could be used if a native watch app is developed as a companion app to a Capacitor app
317
+ */
318
+ export interface CapcacitorWatch {
319
+ /**
320
+ * Sends a message to the watch with the sendMessage() WCSession delegate method
321
+ *
322
+ * This has no effect on a CapacitorWatch watch app
323
+ */
324
+ sendMessage: (options: []) => void;
325
+ /**
326
+ * Sends information to the watch with the transferUserInfo() WCSession delegate method
327
+ *
328
+ * This has no effect on a CapacitorWatch watch app
329
+ */
330
+ transferUserInfo: (options: []) => void;
331
+ /**
332
+ * Updates the application context on the watch with the updateApplicationContext() WCSession delegate method
333
+ *
334
+ * This has no effect on a CapacitorWatch watch app
335
+ */
336
+ updateApplicationContext: (options: []) => void;
337
+ /**
338
+ * Checks to see if the compaion watch is reachable
339
+ */
340
+ isReachable: boolean;
341
+ /**
342
+ * Replaces the current UI on the watch with what is specified here.
343
+ * @param options the new WatchUI you want to show on the watch
344
+ * @returns void
345
+ */
346
+ updateWatchUI: (options: {
347
+ watchUI: string;
348
+ }) => void;
349
+ /**
350
+ * Updates the data the watch is using to display variables in text and button fields
351
+ * @param options the new data to send to the watch
352
+ * @returns void
353
+ */
354
+ updateWatchData: (options: {
355
+ data: {
356
+ [key: string]: string;
357
+ };
358
+ }) => void;
359
+ }
312
360
  export interface CapacitorAPI {
313
361
  CapacitorDevice: CapacitorDevice;
314
362
  CapacitorKV: CapacitorKV;
315
363
  CapacitorNotifications: CapacitorNotifications;
316
364
  CapacitorGeolocation: CapacitorGeolocation;
365
+ CapacitorWatch: CapcacitorWatch;
317
366
  }
@@ -1 +1 @@
1
- {"version":3,"file":"apis.js","sourceRoot":"","sources":["../../src/apis.ts"],"names":[],"mappings":"","sourcesContent":["export interface GetCurrentPositionResult {\n /**\n * Latitude in decimal degrees\n *\n * @since 1.0.0\n */\n latitude: number;\n /**\n * longitude in decimal degrees\n *\n * @since 1.0.0\n */\n longitude: number;\n /**\n * Accuracy level of the latitude and longitude coordinates in meters\n *\n * @since 1.0.0\n */\n accuracy: number;\n /**\n * The altitude the user is at (if available)\n *\n * @since 1.0.0\n */\n altitude: number | null;\n /**\n * Accuracy level of the altitude coordinate in meters, if available.\n *\n * Available on all iOS versions and on Android 8.0+.\n *\n * @since 1.0.0\n */\n altitudeAccuracy?: number | null | undefined;\n /**\n * The speed the user is traveling (if available)\n *\n * @since 1.0.0\n */\n speed: number | null;\n /**\n * The heading the user is facing (if available)\n *\n * @since 1.0.0\n */\n heading: number | null;\n}\n\nexport interface BatteryStatus {\n batteryLevel: number;\n isCharging: boolean;\n}\n\nexport interface NetworkStatus {\n connected: boolean;\n connectionType: string;\n}\n\nexport interface NotificationScheduleOptions {\n /**\n * The notification identifier.\n * On Android it's a 32-bit int.\n * So the value should be between -2147483648 and 2147483647 inclusive.\n *\n * @since 1.0.0\n */\n id: number;\n /**\n * The title of the notification.\n *\n * @since 1.0.0\n */\n title: string;\n /**\n * The body of the notification, shown below the title.\n *\n * @since 1.0.0\n */\n body: string;\n /**\n * Date to send this notification.\n *\n * @since 1.0.0\n */\n scheduleAt: Date;\n /**\n * Name of the audio file to play when this notification is displayed.\n *\n * Include the file extension with the filename.\n *\n * On iOS, the file should be in the app bundle.\n * On Android, the file should be in res/raw folder.\n *\n * Recommended format is `.wav` because is supported by both iOS and Android.\n *\n * Only available for iOS and Android < 26.\n * For Android 26+ use channelId of a channel configured with the desired sound.\n *\n * If the sound file is not found, (i.e. empty string or wrong name)\n * the default system notification sound will be used.\n * If not provided, it will produce the default sound on Android and no sound on iOS.\n *\n * @since 1.0.0\n */\n sound?: string;\n /**\n * Associate an action type with this notification.\n *\n * @since 1.0.0\n */\n actionTypeId?: string;\n /**\n * Used to group multiple notifications.\n *\n * Sets `threadIdentifier` on the\n * [`UNMutableNotificationContent`](https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent).\n *\n * Only available for iOS.\n *\n * @since 1.0.0\n */\n threadIdentifier?: string;\n /**\n * The string this notification adds to the category's summary format string.\n *\n * Sets `summaryArgument` on the\n * [`UNMutableNotificationContent`](https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent).\n *\n * Only available for iOS.\n *\n * @since 1.0.0\n */\n summaryArgument?: string;\n /**\n * Used to group multiple notifications.\n *\n * Calls `setGroup()` on\n * [`NotificationCompat.Builder`](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder)\n * with the provided value.\n *\n * Only available for Android.\n *\n * @since 1.0.0\n */\n group?: string;\n /**\n * If true, this notification becomes the summary for a group of\n * notifications.\n *\n * Calls `setGroupSummary()` on\n * [`NotificationCompat.Builder`](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder)\n * with the provided value.\n *\n * Only available for Android when using `group`.\n *\n * @since 1.0.0\n */\n groupSummary?: string;\n /**\n * Set extra data to store within this notification.\n *\n * @since 1.0.0\n */\n extra?: any;\n /**\n * If true, the notification can't be swiped away.\n *\n * Calls `setOngoing()` on\n * [`NotificationCompat.Builder`](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder)\n * with the provided value.\n *\n * Only available for Android.\n *\n * @since 1.0.0\n */\n ongoing?: boolean;\n /**\n * If true, the notification is canceled when the user clicks on it.\n *\n * Calls `setAutoCancel()` on\n * [`NotificationCompat.Builder`](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder)\n * with the provided value.\n *\n * Only available for Android.\n *\n * @since 1.0.0\n */\n autoCancel?: boolean;\n /**\n * Sets a multiline text block for display in a big text notification style.\n *\n * @since 1.0.0\n */\n largeBody?: string;\n /**\n * Used to set the summary text detail in inbox and big text notification styles.\n *\n * Only available for Android.\n *\n * @since 1.0.0\n */\n summaryText?: string;\n /**\n * Set a custom status bar icon.\n *\n * If set, this overrides the `smallIcon` option from Capacitor\n * configuration.\n *\n * Icons should be placed in your app's `res/drawable` folder. The value for\n * this option should be the drawable resource ID, which is the filename\n * without an extension.\n *\n * Only available for Android.\n *\n * @since 1.0.0\n */\n smallIcon?: string;\n /**\n * Set a large icon for notifications.\n *\n * Icons should be placed in your app's `res/drawable` folder. The value for\n * this option should be the drawable resource ID, which is the filename\n * without an extension.\n *\n * Only available for Android.\n *\n * @since 1.0.0\n */\n largeIcon?: string;\n /**\n * Specifies the channel the notification should be delivered on.\n *\n * If channel with the given name does not exist then the notification will\n * not fire. If not provided, it will use the default channel.\n *\n * Calls `setChannelId()` on\n * [`NotificationCompat.Builder`](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder)\n * with the provided value.\n *\n * Only available for Android 26+.\n *\n * @since 1.0.0\n */\n channelId?: string;\n}\n\n/**\n * Get access to device location information.\n *\n * @since 1.0.0\n */\nexport interface CapacitorGeolocation {\n /**\n * Get the device's last known location\n * @since 1.0.0\n */\n getCurrentLocation: () => GetCurrentPositionResult;\n}\n\n/**\n * A simple string key / value store backed by UserDefaults on iOS and Shared Preferences on Android.\n */\nexport interface CapacitorKV {\n /**\n * Set a string value with the given key.\n *\n * @param key\n * @param value\n * @returns\n * @since 1.0.0\n */\n set: (key: string, value: string) => void;\n /**\n * Get a string value for the given key.\n * @param key\n * @returns\n * @since 1.0.0\n */\n get: (key: string) => string;\n /**\n * Remove a value with the given key.\n * @param key\n * @returns\n * @since 1.0.0\n */\n remove: (key: string) => void;\n}\n\n/**\n * Get information on the device, such as network connectivity and battery status.\n */\nexport interface CapacitorDevice {\n /**\n * Get the current battery status for the device.\n *\n * @since 1.0.0\n */\n getBatteryStatus: () => BatteryStatus;\n /**\n * Get the current network status for the device.\n *\n * @since 1.0.0\n */\n getNetworkStatus: () => NetworkStatus;\n}\n\n/**\n * Send basic local notifications.\n */\nexport interface CapacitorNotifications {\n /**\n * Schedule a local notification\n * @example `CapacitorNotifications.schedule()`\n * @param options\n * @returns void\n * @since 1.0.0\n */\n schedule: (options: NotificationScheduleOptions[]) => void;\n}\n\nexport interface CapacitorAPI {\n CapacitorDevice: CapacitorDevice;\n CapacitorKV: CapacitorKV;\n CapacitorNotifications: CapacitorNotifications;\n CapacitorGeolocation: CapacitorGeolocation;\n}\n"]}
1
+ {"version":3,"file":"apis.js","sourceRoot":"","sources":["../../src/apis.ts"],"names":[],"mappings":"","sourcesContent":["export interface GetCurrentPositionResult {\n /**\n * Latitude in decimal degrees\n *\n * @since 1.0.0\n */\n latitude: number;\n /**\n * longitude in decimal degrees\n *\n * @since 1.0.0\n */\n longitude: number;\n /**\n * Accuracy level of the latitude and longitude coordinates in meters\n *\n * @since 1.0.0\n */\n accuracy: number;\n /**\n * The altitude the user is at (if available)\n *\n * @since 1.0.0\n */\n altitude: number | null;\n /**\n * Accuracy level of the altitude coordinate in meters, if available.\n *\n * Available on all iOS versions and on Android 8.0+.\n *\n * @since 1.0.0\n */\n altitudeAccuracy?: number | null | undefined;\n /**\n * The speed the user is traveling (if available)\n *\n * @since 1.0.0\n */\n speed: number | null;\n /**\n * The heading the user is facing (if available)\n *\n * @since 1.0.0\n */\n heading: number | null;\n}\n\nexport interface BatteryStatus {\n batteryLevel: number;\n isCharging: boolean;\n}\n\nexport interface NetworkStatus {\n connected: boolean;\n connectionType: string;\n}\n\nexport interface NotificationScheduleOptions {\n /**\n * The notification identifier.\n * On Android it's a 32-bit int.\n * So the value should be between -2147483648 and 2147483647 inclusive.\n *\n * @since 1.0.0\n */\n id: number;\n /**\n * The title of the notification.\n *\n * @since 1.0.0\n */\n title: string;\n /**\n * The body of the notification, shown below the title.\n *\n * @since 1.0.0\n */\n body: string;\n /**\n * Date to send this notification.\n *\n * @since 1.0.0\n */\n scheduleAt: Date;\n /**\n * Name of the audio file to play when this notification is displayed.\n *\n * Include the file extension with the filename.\n *\n * On iOS, the file should be in the app bundle.\n * On Android, the file should be in res/raw folder.\n *\n * Recommended format is `.wav` because is supported by both iOS and Android.\n *\n * Only available for iOS and Android < 26.\n * For Android 26+ use channelId of a channel configured with the desired sound.\n *\n * If the sound file is not found, (i.e. empty string or wrong name)\n * the default system notification sound will be used.\n * If not provided, it will produce the default sound on Android and no sound on iOS.\n *\n * @since 1.0.0\n */\n sound?: string;\n /**\n * Associate an action type with this notification.\n *\n * @since 1.0.0\n */\n actionTypeId?: string;\n /**\n * Used to group multiple notifications.\n *\n * Sets `threadIdentifier` on the\n * [`UNMutableNotificationContent`](https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent).\n *\n * Only available for iOS.\n *\n * @since 1.0.0\n */\n threadIdentifier?: string;\n /**\n * The string this notification adds to the category's summary format string.\n *\n * Sets `summaryArgument` on the\n * [`UNMutableNotificationContent`](https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent).\n *\n * Only available for iOS.\n *\n * @since 1.0.0\n */\n summaryArgument?: string;\n /**\n * Used to group multiple notifications.\n *\n * Calls `setGroup()` on\n * [`NotificationCompat.Builder`](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder)\n * with the provided value.\n *\n * Only available for Android.\n *\n * @since 1.0.0\n */\n group?: string;\n /**\n * If true, this notification becomes the summary for a group of\n * notifications.\n *\n * Calls `setGroupSummary()` on\n * [`NotificationCompat.Builder`](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder)\n * with the provided value.\n *\n * Only available for Android when using `group`.\n *\n * @since 1.0.0\n */\n groupSummary?: string;\n /**\n * Set extra data to store within this notification.\n *\n * @since 1.0.0\n */\n extra?: any;\n /**\n * If true, the notification can't be swiped away.\n *\n * Calls `setOngoing()` on\n * [`NotificationCompat.Builder`](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder)\n * with the provided value.\n *\n * Only available for Android.\n *\n * @since 1.0.0\n */\n ongoing?: boolean;\n /**\n * If true, the notification is canceled when the user clicks on it.\n *\n * Calls `setAutoCancel()` on\n * [`NotificationCompat.Builder`](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder)\n * with the provided value.\n *\n * Only available for Android.\n *\n * @since 1.0.0\n */\n autoCancel?: boolean;\n /**\n * Sets a multiline text block for display in a big text notification style.\n *\n * @since 1.0.0\n */\n largeBody?: string;\n /**\n * Used to set the summary text detail in inbox and big text notification styles.\n *\n * Only available for Android.\n *\n * @since 1.0.0\n */\n summaryText?: string;\n /**\n * Set a custom status bar icon.\n *\n * If set, this overrides the `smallIcon` option from Capacitor\n * configuration.\n *\n * Icons should be placed in your app's `res/drawable` folder. The value for\n * this option should be the drawable resource ID, which is the filename\n * without an extension.\n *\n * Only available for Android.\n *\n * @since 1.0.0\n */\n smallIcon?: string;\n /**\n * Set a large icon for notifications.\n *\n * Icons should be placed in your app's `res/drawable` folder. The value for\n * this option should be the drawable resource ID, which is the filename\n * without an extension.\n *\n * Only available for Android.\n *\n * @since 1.0.0\n */\n largeIcon?: string;\n /**\n * Specifies the channel the notification should be delivered on.\n *\n * If channel with the given name does not exist then the notification will\n * not fire. If not provided, it will use the default channel.\n *\n * Calls `setChannelId()` on\n * [`NotificationCompat.Builder`](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder)\n * with the provided value.\n *\n * Only available for Android 26+.\n *\n * @since 1.0.0\n */\n channelId?: string;\n}\n\n/**\n * Get access to device location information.\n *\n * @since 1.0.0\n */\nexport interface CapacitorGeolocation {\n /**\n * Get the device's last known location\n * @since 1.0.0\n */\n getCurrentLocation: () => GetCurrentPositionResult;\n}\n\n/**\n * A simple string key / value store backed by UserDefaults on iOS and Shared Preferences on Android.\n */\nexport interface CapacitorKV {\n /**\n * Set a string value with the given key.\n *\n * @param key\n * @param value\n * @returns\n * @since 1.0.0\n */\n set: (key: string, value: string) => void;\n /**\n * Get a string value for the given key.\n * @param key\n * @returns\n * @since 1.0.0\n */\n get: (key: string) => string;\n /**\n * Remove a value with the given key.\n * @param key\n * @returns\n * @since 1.0.0\n */\n remove: (key: string) => void;\n}\n\n/**\n * Get information on the device, such as network connectivity and battery status.\n */\nexport interface CapacitorDevice {\n /**\n * Get the current battery status for the device.\n *\n * @since 1.0.0\n */\n getBatteryStatus: () => BatteryStatus;\n /**\n * Get the current network status for the device.\n *\n * @since 1.0.0\n */\n getNetworkStatus: () => NetworkStatus;\n}\n\n/**\n * Send basic local notifications.\n */\nexport interface CapacitorNotifications {\n /**\n * Schedule a local notification\n * @example `CapacitorNotifications.schedule()`\n * @param options\n * @returns void\n * @since 1.0.0\n */\n schedule: (options: NotificationScheduleOptions[]) => void;\n}\n\n/**\n * Interact with a watch paired with this app\n *\n * sendMessage, transferUserInfo and updateApplicationContext are raw routes to the WCSession delegate methods, but have no effects currently in a CapactiorWatch Watch application.\n * They could be used if a native watch app is developed as a companion app to a Capacitor app\n */\nexport interface CapcacitorWatch {\n /**\n * Sends a message to the watch with the sendMessage() WCSession delegate method\n *\n * This has no effect on a CapacitorWatch watch app\n */\n sendMessage: (options: []) => void;\n /**\n * Sends information to the watch with the transferUserInfo() WCSession delegate method\n *\n * This has no effect on a CapacitorWatch watch app\n */\n transferUserInfo: (options: []) => void;\n /**\n * Updates the application context on the watch with the updateApplicationContext() WCSession delegate method\n *\n * This has no effect on a CapacitorWatch watch app\n */\n updateApplicationContext: (options: []) => void;\n /**\n * Checks to see if the compaion watch is reachable\n */\n isReachable: boolean;\n /**\n * Replaces the current UI on the watch with what is specified here.\n * @param options the new WatchUI you want to show on the watch\n * @returns void\n */\n updateWatchUI: (options: { watchUI: string }) => void;\n /**\n * Updates the data the watch is using to display variables in text and button fields\n * @param options the new data to send to the watch\n * @returns void\n */\n updateWatchData: (options: { data: { [key: string]: string } }) => void;\n}\n\nexport interface CapacitorAPI {\n CapacitorDevice: CapacitorDevice;\n CapacitorKV: CapacitorKV;\n CapacitorNotifications: CapacitorNotifications;\n CapacitorGeolocation: CapacitorGeolocation;\n CapacitorWatch: CapcacitorWatch;\n}\n"]}
@@ -116,6 +116,7 @@ public class BackgroundRunner {
116
116
 
117
117
  var err: Error?
118
118
 
119
+ // swiftlint:disable:next unowned_variable_capture
119
120
  DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
120
121
  do {
121
122
  _ = try self.execute(config: config, event: event, inputArgs: inputArgs)
@@ -135,6 +136,7 @@ public class BackgroundRunner {
135
136
  }
136
137
  }
137
138
 
139
+ // swiftlint:disable:next cyclomatic_complexity function_body_length
138
140
  public func execute(config: RunnerConfig, event: String, inputArgs: [String: Any]? = nil) throws -> [String: Any]? {
139
141
  do {
140
142
  if !started {
@@ -64,6 +64,7 @@ public class BackgroundRunnerPlugin: CAPPlugin {
64
64
  throw BackgroundRunnerPluginError.runnerError(reason: "no runner config loaded")
65
65
  }
66
66
 
67
+ // swiftlint:disable:next unowned_variable_capture
67
68
  DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
68
69
  do {
69
70
  let result = try self.impl.execute(
@@ -100,6 +100,7 @@ class CapacitorNotifications: NSObject, CapacitorNotificationsExports {
100
100
  }
101
101
  }
102
102
 
103
+ // swiftlint:disable:next cyclomatic_complexity
103
104
  static func schedule(_ options: JSValue) {
104
105
  do {
105
106
  if CapacitorNotifications.checkPermission() != "granted" {
@@ -150,6 +151,7 @@ class CapacitorNotifications: NSObject, CapacitorNotificationsExports {
150
151
  }
151
152
 
152
153
  let dateInfo = Calendar.current.dateComponents(in: TimeZone.current, from: notificationDate)
154
+ // swiftlint:disable:next force_unwrapping
153
155
  let dateInterval = DateInterval(start: Date(), end: dateInfo.date!)
154
156
 
155
157
  let trigger = UNTimeIntervalNotificationTrigger(timeInterval: dateInterval.duration, repeats: false)
@@ -251,6 +251,7 @@ public extension Reachability {
251
251
  fileprivate extension Reachability {
252
252
 
253
253
  func setReachabilityFlags() throws {
254
+ // swiftlint:disable:next unowned_variable_capture
254
255
  try reachabilitySerialQueue.sync { [unowned self] in
255
256
  var flags = SCNetworkReachabilityFlags()
256
257
  if !SCNetworkReachabilityGetFlags(self.reachabilityRef, &flags) {
@@ -265,6 +266,7 @@ fileprivate extension Reachability {
265
266
  func notifyReachabilityChanged() {
266
267
  let notify = { [weak self] in
267
268
  guard let self = self else { return }
269
+ // swiftlint:disable:next void_function_in_ternary
268
270
  self.connection != .unavailable ? self.whenReachable?(self) : self.whenUnreachable?(self)
269
271
  self.notificationCenter.post(name: .reachabilityChanged, object: self)
270
272
  }
@@ -0,0 +1,89 @@
1
+ import Foundation
2
+ import JavaScriptCore
3
+ import WatchConnectivity
4
+
5
+ @objc protocol CapacitorWatchExports: JSExport {
6
+ func sendMessage(_ dataDict: JSValue) -> JSValue
7
+ func transferUserInfo(_ userInfo: JSValue) -> JSValue
8
+ func updateApplicationContext(_ appContext: JSValue) -> JSValue
9
+ func isReachable() -> JSValue
10
+ func updateWatchUI(_ call: JSValue)
11
+ func updateWatchData(_ call: JSValue)
12
+ }
13
+
14
+ // swiftlint:disable:next identifier_name
15
+ public let UI_KEY = "watchUI"
16
+ // swiftlint:disable:next identifier_name
17
+ public let DATA_KEY = "viewData"
18
+
19
+ class CapacitorWatch: NSObject, CapacitorWatchExports {
20
+ func sendMessage(_ dataDict: JSValue) -> JSValue {
21
+ let dict = jsValueToDict(dataDict)
22
+
23
+ WCSession.default.sendMessage(dict, replyHandler: nil)
24
+
25
+ return JSValue(undefinedIn: JSContext.current())
26
+ }
27
+
28
+ func transferUserInfo(_ userInfo: JSValue) -> JSValue {
29
+ let dict = jsValueToDict(userInfo)
30
+
31
+ WCSession.default.transferUserInfo(dict)
32
+
33
+ return JSValue(undefinedIn: JSContext.current())
34
+ }
35
+
36
+ func updateApplicationContext(_ appContext: JSValue) -> JSValue {
37
+ let dict = jsValueToDict(appContext)
38
+
39
+ try? WCSession.default.updateApplicationContext(dict)
40
+
41
+ return JSValue(undefinedIn: JSContext.current())
42
+ }
43
+
44
+ func isReachable() -> JSValue {
45
+ if WCSession.default.isReachable {
46
+ return JSValue(bool: true, in: JSContext.current())
47
+ }
48
+
49
+ return JSValue(bool: false, in: JSContext.current())
50
+ }
51
+
52
+ func updateWatchUI(_ call: JSValue) {
53
+ let dict = jsValueToDict(call)
54
+
55
+ guard let newUI = dict["data"] as? [String: String] else {
56
+ return
57
+ }
58
+
59
+ WCSession.default.transferUserInfo([UI_KEY: newUI])
60
+ }
61
+
62
+ func updateWatchData(_ call: JSValue) {
63
+ let dict = jsValueToDict(call)
64
+
65
+ guard let newData = dict["data"] as? [String: String] else {
66
+ return
67
+ }
68
+
69
+ WCSession.default.transferUserInfo([DATA_KEY: newData])
70
+ }
71
+
72
+ fileprivate func jsValueToDict(_ jsVal: JSValue) -> [String: Any] {
73
+ var dict: [String: Any] = [:]
74
+
75
+ if jsVal.isObject {
76
+ if let convertedDict = jsVal.toDictionary() as? [String: Any] {
77
+ dict = convertedDict
78
+ }
79
+ }
80
+
81
+ return dict
82
+ }
83
+ }
84
+
85
+ enum WatchDataError: Error {
86
+ case JSValIsNotObject
87
+ // swiftlint:disable:next identifier_name
88
+ case CouldNotConvertJSVal
89
+ }
@@ -4,7 +4,7 @@ extension Context {
4
4
  public func setupCapacitorAPI() {
5
5
  ctx.setObject(CapacitorKVStore.self, forKeyedSubscript: "CapacitorKV" as NSString)
6
6
  ctx.setObject(CapacitorGeolocation(context: self), forKeyedSubscript: "CapacitorGeolocation" as NSString)
7
- ctx.setObject(CapacitorWearable(), forKeyedSubscript: "CapacitorWearable" as NSString)
7
+ ctx.setObject(CapacitorWatch(), forKeyedSubscript: "CapacitorWatch" as NSString)
8
8
  ctx.setObject(CapacitorNotifications.self, forKeyedSubscript: "CapacitorNotifications" as NSString)
9
9
  ctx.setObject(CapacitorDevice(), forKeyedSubscript: "CapacitorDevice" as NSString)
10
10
  }
@@ -18,6 +18,8 @@ extension BackgroundRunnerPlugin: WCSessionDelegate {
18
18
  try? BackgroundRunner.shared.dispatchEvent(event: "WatchConnectivity_sessionDidDeactivate", inputArgs: nil)
19
19
  }
20
20
 
21
+ // DCG Note - documentation for these events are contained within the CapacitorWatch documentation
22
+
21
23
  public func session(_ session: WCSession, didReceiveUserInfo userInfo: [String: Any] = [:]) {
22
24
  var args: [String: Any] = [:]
23
25
  args["userInfo"] = userInfo
@@ -31,4 +33,11 @@ extension BackgroundRunnerPlugin: WCSessionDelegate {
31
33
 
32
34
  try? BackgroundRunner.shared.dispatchEvent(event: "WatchConnectivity_didReceiveMessage", inputArgs: args)
33
35
  }
36
+
37
+ public func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String: Any]) {
38
+ var args: [String: Any] = [:]
39
+ args["message"] = applicationContext
40
+
41
+ try? BackgroundRunner.shared.dispatchEvent(event: "WatchConnectivity_didReceiveApplicationContext", inputArgs: args)
42
+ }
34
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/background-runner",
3
- "version": "1.0.4",
3
+ "version": "1.0.5-dev-20230817T150324.0",
4
4
  "description": "Capacitor Background Runner",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -81,5 +81,5 @@
81
81
  "src": "android"
82
82
  }
83
83
  },
84
- "gitHead": "0a4b537b808187cb2c9de0d1ac597949c8fff958"
84
+ "gitHead": "418d7338b1b483896e0b55636a364d9ff678ca41"
85
85
  }
@@ -1,48 +0,0 @@
1
- import Foundation
2
- import JavaScriptCore
3
- import WatchConnectivity
4
-
5
- @objc protocol CapacitorWearableExports: JSExport {
6
- func send(_ dataDict: JSValue) -> JSValue
7
- func transferUserInfo(_ userInfo: JSValue) -> JSValue
8
- func isReachable() -> JSValue
9
- }
10
-
11
- class CapacitorWearable: NSObject, CapacitorWearableExports {
12
- func send(_ dataDict: JSValue) -> JSValue {
13
- var dict: [String: Any] = [:]
14
-
15
- if dataDict.isObject {
16
- if let convertedDict = dataDict.toDictionary() as? [String: Any] {
17
- dict = convertedDict
18
- }
19
- }
20
-
21
- WCSession.default.sendMessage(dict, replyHandler: nil)
22
-
23
- return JSValue(undefinedIn: JSContext.current())
24
- }
25
-
26
- func transferUserInfo(_ userInfo: JSValue) -> JSValue {
27
- var dict: [String: Any] = [:]
28
-
29
- if userInfo.isObject {
30
- if let convertedDict = userInfo.toDictionary() as? [String: Any] {
31
- dict = convertedDict
32
- }
33
- }
34
-
35
- _ = WCSession.default.transferUserInfo(dict)
36
-
37
- return JSValue(undefinedIn: JSContext.current())
38
- }
39
-
40
- func isReachable() -> JSValue {
41
- if WCSession.default.isReachable {
42
- return JSValue(bool: true, in: JSContext.current())
43
- }
44
-
45
- return JSValue(bool: false, in: JSContext.current())
46
- }
47
-
48
- }