@capacitor/background-runner 1.0.6-dev-20230821T155222.0 → 1.0.6-dev-20230831T174057.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 +57 -8
- package/android/src/main/libs/android-js-engine-release.aar +0 -0
- package/dist/docs-api.json +106 -2
- package/dist/docs.json +105 -1
- package/dist/esm/apis.d.ts +3 -1
- package/dist/esm/apis.js.map +1 -1
- package/dist/esm/definitions.d.ts +95 -28
- package/dist/esm/definitions.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -98,9 +98,15 @@ Note that even if the permission is present, users can still disable exact notif
|
|
|
98
98
|
|
|
99
99
|
Read about [Setting Permissions](https://capacitorjs.com/docs/android/configuration#setting-permissions) in the [Android Guide](https://capacitorjs.com/docs/android) for more information on setting Android permissions.
|
|
100
100
|
|
|
101
|
+
## About Background Runner
|
|
102
|
+
During the corse of building complex applications, its sometimes necessary to perform work while the application is not in the foreground. The challenge with standard Capacitor applications is that the webview is not available when these background events occur, requiring you to write native code to handle these events. This is where the Background Runner plugin comes in.
|
|
103
|
+
|
|
104
|
+
Background Runner makes it easy to write JavaScript code to handle native background events. All you need to do is create your runner JavaScript file and [define your configuration](#configuring-background-runner), then the Background Runner plugin will automatically configure and schedule a native background task that will be executed according to your config and the rules of the platform. No modification to your UI code is necessary.
|
|
105
|
+
|
|
106
|
+
|
|
101
107
|
## Using Background Runner
|
|
102
108
|
|
|
103
|
-
Background Runner
|
|
109
|
+
Background Runner contains a headless JavaScript environment that calls event handlers in javascript file that you designate in your `capacitor.config.ts` file. If the runner finds a event handler corresponding to incoming event in your runner file, it will execute the event handler, then shutdown once `resolve()` or `reject()` are called (or if the OS force kills your process).
|
|
104
110
|
|
|
105
111
|
#### Example Runner JS File
|
|
106
112
|
|
|
@@ -147,23 +153,66 @@ Calling `resolve()` \ `reject()` is **required** within every event handler call
|
|
|
147
153
|
|
|
148
154
|
## Configuring Background Runner
|
|
149
155
|
|
|
150
|
-
|
|
156
|
+
<docgen-config>
|
|
157
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
158
|
+
|
|
159
|
+
On load, Background Runner will automatically register a
|
|
160
|
+
background task that will be scheduled and ran once your app is
|
|
161
|
+
backgrounded.
|
|
162
|
+
|
|
163
|
+
| Prop | Type | Description | Since |
|
|
164
|
+
| --------------- | -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
|
|
165
|
+
| **`label`** | <code>string</code> | The name of the runner, used in logs. | 1.0.0 |
|
|
166
|
+
| **`src`** | <code>string</code> | The path to the runner JavaScript file, relative to the app bundle. | 1.0.0 |
|
|
167
|
+
| **`event`** | <code>string</code> | The name of the event that will be called when the OS executes the background task. | 1.0.0 |
|
|
168
|
+
| **`repeat`** | <code>boolean</code> | If background task should repeat based on the interval set in `interval`. | 1.0.0 |
|
|
169
|
+
| **`interval`** | <code>number</code> | The number of minutes after the the app is put into the background in which the background task should begin. If `repeat` is true, this also specifies the number of minutes between each execution. | 1.0.0 |
|
|
170
|
+
| **`autoStart`** | <code>boolean</code> | Automatically register and schedule background task on app load. | 1.0.0 |
|
|
171
|
+
|
|
172
|
+
### Examples
|
|
173
|
+
|
|
174
|
+
In `capacitor.config.json`:
|
|
175
|
+
|
|
176
|
+
```json
|
|
177
|
+
{
|
|
178
|
+
"plugins": {
|
|
179
|
+
"BackgroundRunner": {
|
|
180
|
+
"label": "com.example.background.task",
|
|
181
|
+
"src": "runners/background.js",
|
|
182
|
+
"event": "myCustomEvent",
|
|
183
|
+
"repeat": true,
|
|
184
|
+
"interval": 15,
|
|
185
|
+
"autoStart": true
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
In `capacitor.config.ts`:
|
|
151
192
|
|
|
152
193
|
```ts
|
|
194
|
+
/// <reference types="@capacitor/background-runner" />
|
|
195
|
+
|
|
196
|
+
import { CapacitorConfig } from '@capacitor/cli';
|
|
197
|
+
|
|
153
198
|
const config: CapacitorConfig = {
|
|
154
199
|
plugins: {
|
|
155
200
|
BackgroundRunner: {
|
|
156
|
-
label:
|
|
157
|
-
src:
|
|
158
|
-
event:
|
|
201
|
+
label: "com.example.background.task",
|
|
202
|
+
src: "runners/background.js",
|
|
203
|
+
event: "myCustomEvent",
|
|
159
204
|
repeat: true,
|
|
160
|
-
interval:
|
|
161
|
-
autoStart:
|
|
205
|
+
interval: 15,
|
|
206
|
+
autoStart: true,
|
|
162
207
|
},
|
|
163
208
|
},
|
|
164
209
|
};
|
|
210
|
+
|
|
211
|
+
export default config;
|
|
165
212
|
```
|
|
166
213
|
|
|
214
|
+
</docgen-config>
|
|
215
|
+
|
|
167
216
|
## JavaScript API
|
|
168
217
|
|
|
169
218
|
Background Runner does not execute your Javascript code in a browser or web view, therefore the typical Web APIs you may be used to may not be available. This includes DOM APIs nor ability to interact with your application's DOM.
|
|
@@ -364,7 +413,7 @@ A simple string key / value store backed by UserDefaults on iOS and Shared Prefe
|
|
|
364
413
|
| Prop | Type | Description | Since |
|
|
365
414
|
| ------------ | ---------------------------------------------------- | -------------------------------------- | ----- |
|
|
366
415
|
| **`set`** | <code>(key: string, value: string) => void</code> | Set a string value with the given key. | 1.0.0 |
|
|
367
|
-
| **`get`** | <code>(key: string) => string</code>
|
|
416
|
+
| **`get`** | <code>(key: string) => { value: string; }</code> | Get a string value for the given key. | 1.0.0 |
|
|
368
417
|
| **`remove`** | <code>(key: string) => void</code> | Remove a value with the given key. | 1.0.0 |
|
|
369
418
|
|
|
370
419
|
|
|
Binary file
|
package/dist/docs-api.json
CHANGED
|
@@ -184,7 +184,7 @@
|
|
|
184
184
|
],
|
|
185
185
|
"docs": "Get a string value for the given key.",
|
|
186
186
|
"complexTypes": [],
|
|
187
|
-
"type": "(key: string) => string"
|
|
187
|
+
"type": "(key: string) => { value: string; }"
|
|
188
188
|
},
|
|
189
189
|
{
|
|
190
190
|
"name": "remove",
|
|
@@ -662,5 +662,109 @@
|
|
|
662
662
|
],
|
|
663
663
|
"enums": [],
|
|
664
664
|
"typeAliases": [],
|
|
665
|
-
"pluginConfigs": [
|
|
665
|
+
"pluginConfigs": [
|
|
666
|
+
{
|
|
667
|
+
"name": "BackgroundRunner",
|
|
668
|
+
"slug": "backgroundrunner",
|
|
669
|
+
"properties": [
|
|
670
|
+
{
|
|
671
|
+
"name": "label",
|
|
672
|
+
"tags": [
|
|
673
|
+
{
|
|
674
|
+
"text": "1.0.0",
|
|
675
|
+
"name": "since"
|
|
676
|
+
},
|
|
677
|
+
{
|
|
678
|
+
"text": "\"com.example.background.task\"",
|
|
679
|
+
"name": "example"
|
|
680
|
+
}
|
|
681
|
+
],
|
|
682
|
+
"docs": "The name of the runner, used in logs.",
|
|
683
|
+
"complexTypes": [],
|
|
684
|
+
"type": "string"
|
|
685
|
+
},
|
|
686
|
+
{
|
|
687
|
+
"name": "src",
|
|
688
|
+
"tags": [
|
|
689
|
+
{
|
|
690
|
+
"text": "1.0.0",
|
|
691
|
+
"name": "since"
|
|
692
|
+
},
|
|
693
|
+
{
|
|
694
|
+
"text": "\"runners/background.js\"",
|
|
695
|
+
"name": "example"
|
|
696
|
+
}
|
|
697
|
+
],
|
|
698
|
+
"docs": "The path to the runner JavaScript file, relative to the app bundle.",
|
|
699
|
+
"complexTypes": [],
|
|
700
|
+
"type": "string"
|
|
701
|
+
},
|
|
702
|
+
{
|
|
703
|
+
"name": "event",
|
|
704
|
+
"tags": [
|
|
705
|
+
{
|
|
706
|
+
"text": "1.0.0",
|
|
707
|
+
"name": "since"
|
|
708
|
+
},
|
|
709
|
+
{
|
|
710
|
+
"text": "\"myCustomEvent\"",
|
|
711
|
+
"name": "example"
|
|
712
|
+
}
|
|
713
|
+
],
|
|
714
|
+
"docs": "The name of the event that will be called when the OS executes the background task.",
|
|
715
|
+
"complexTypes": [],
|
|
716
|
+
"type": "string"
|
|
717
|
+
},
|
|
718
|
+
{
|
|
719
|
+
"name": "repeat",
|
|
720
|
+
"tags": [
|
|
721
|
+
{
|
|
722
|
+
"text": "1.0.0",
|
|
723
|
+
"name": "since"
|
|
724
|
+
},
|
|
725
|
+
{
|
|
726
|
+
"text": "true",
|
|
727
|
+
"name": "example"
|
|
728
|
+
}
|
|
729
|
+
],
|
|
730
|
+
"docs": "If background task should repeat based on the interval set in `interval`.",
|
|
731
|
+
"complexTypes": [],
|
|
732
|
+
"type": "boolean"
|
|
733
|
+
},
|
|
734
|
+
{
|
|
735
|
+
"name": "interval",
|
|
736
|
+
"tags": [
|
|
737
|
+
{
|
|
738
|
+
"text": "1.0.0",
|
|
739
|
+
"name": "since"
|
|
740
|
+
},
|
|
741
|
+
{
|
|
742
|
+
"text": "15",
|
|
743
|
+
"name": "example"
|
|
744
|
+
}
|
|
745
|
+
],
|
|
746
|
+
"docs": "The number of minutes after the the app is put into the background in which the background task should begin.\n\nIf `repeat` is true, this also specifies the number of minutes between each execution.",
|
|
747
|
+
"complexTypes": [],
|
|
748
|
+
"type": "number"
|
|
749
|
+
},
|
|
750
|
+
{
|
|
751
|
+
"name": "autoStart",
|
|
752
|
+
"tags": [
|
|
753
|
+
{
|
|
754
|
+
"text": "1.0.0",
|
|
755
|
+
"name": "since"
|
|
756
|
+
},
|
|
757
|
+
{
|
|
758
|
+
"text": "true",
|
|
759
|
+
"name": "example"
|
|
760
|
+
}
|
|
761
|
+
],
|
|
762
|
+
"docs": "Automatically register and schedule background task on app load.",
|
|
763
|
+
"complexTypes": [],
|
|
764
|
+
"type": "boolean | undefined"
|
|
765
|
+
}
|
|
766
|
+
],
|
|
767
|
+
"docs": "On load, Background Runner will automatically register a\nbackground task that will be scheduled and ran once your app is\nbackgrounded."
|
|
768
|
+
}
|
|
769
|
+
]
|
|
666
770
|
}
|
package/dist/docs.json
CHANGED
|
@@ -204,5 +204,109 @@
|
|
|
204
204
|
]
|
|
205
205
|
}
|
|
206
206
|
],
|
|
207
|
-
"pluginConfigs": [
|
|
207
|
+
"pluginConfigs": [
|
|
208
|
+
{
|
|
209
|
+
"name": "BackgroundRunner",
|
|
210
|
+
"slug": "backgroundrunner",
|
|
211
|
+
"properties": [
|
|
212
|
+
{
|
|
213
|
+
"name": "label",
|
|
214
|
+
"tags": [
|
|
215
|
+
{
|
|
216
|
+
"text": "1.0.0",
|
|
217
|
+
"name": "since"
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
"text": "\"com.example.background.task\"",
|
|
221
|
+
"name": "example"
|
|
222
|
+
}
|
|
223
|
+
],
|
|
224
|
+
"docs": "The name of the runner, used in logs.",
|
|
225
|
+
"complexTypes": [],
|
|
226
|
+
"type": "string"
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
"name": "src",
|
|
230
|
+
"tags": [
|
|
231
|
+
{
|
|
232
|
+
"text": "1.0.0",
|
|
233
|
+
"name": "since"
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
"text": "\"runners/background.js\"",
|
|
237
|
+
"name": "example"
|
|
238
|
+
}
|
|
239
|
+
],
|
|
240
|
+
"docs": "The path to the runner JavaScript file, relative to the app bundle.",
|
|
241
|
+
"complexTypes": [],
|
|
242
|
+
"type": "string"
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
"name": "event",
|
|
246
|
+
"tags": [
|
|
247
|
+
{
|
|
248
|
+
"text": "1.0.0",
|
|
249
|
+
"name": "since"
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
"text": "\"myCustomEvent\"",
|
|
253
|
+
"name": "example"
|
|
254
|
+
}
|
|
255
|
+
],
|
|
256
|
+
"docs": "The name of the event that will be called when the OS executes the background task.",
|
|
257
|
+
"complexTypes": [],
|
|
258
|
+
"type": "string"
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
"name": "repeat",
|
|
262
|
+
"tags": [
|
|
263
|
+
{
|
|
264
|
+
"text": "1.0.0",
|
|
265
|
+
"name": "since"
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
"text": "true",
|
|
269
|
+
"name": "example"
|
|
270
|
+
}
|
|
271
|
+
],
|
|
272
|
+
"docs": "If background task should repeat based on the interval set in `interval`.",
|
|
273
|
+
"complexTypes": [],
|
|
274
|
+
"type": "boolean"
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
"name": "interval",
|
|
278
|
+
"tags": [
|
|
279
|
+
{
|
|
280
|
+
"text": "1.0.0",
|
|
281
|
+
"name": "since"
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
"text": "15",
|
|
285
|
+
"name": "example"
|
|
286
|
+
}
|
|
287
|
+
],
|
|
288
|
+
"docs": "The number of minutes after the the app is put into the background in which the background task should begin.\n\nIf `repeat` is true, this also specifies the number of minutes between each execution.",
|
|
289
|
+
"complexTypes": [],
|
|
290
|
+
"type": "number"
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
"name": "autoStart",
|
|
294
|
+
"tags": [
|
|
295
|
+
{
|
|
296
|
+
"text": "1.0.0",
|
|
297
|
+
"name": "since"
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
"text": "true",
|
|
301
|
+
"name": "example"
|
|
302
|
+
}
|
|
303
|
+
],
|
|
304
|
+
"docs": "Automatically register and schedule background task on app load.",
|
|
305
|
+
"complexTypes": [],
|
|
306
|
+
"type": "boolean | undefined"
|
|
307
|
+
}
|
|
308
|
+
],
|
|
309
|
+
"docs": "On load, Background Runner will automatically register a\nbackground task that will be scheduled and ran once your app is\nbackgrounded."
|
|
310
|
+
}
|
|
311
|
+
]
|
|
208
312
|
}
|
package/dist/esm/apis.d.ts
CHANGED
package/dist/esm/apis.js.map
CHANGED
|
@@ -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\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"]}
|
|
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) => { value: 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"]}
|
|
@@ -1,4 +1,99 @@
|
|
|
1
1
|
import type { PermissionState } from '@capacitor/core';
|
|
2
|
+
export interface BackgroundRunnerConfig {
|
|
3
|
+
/**
|
|
4
|
+
* The name of the runner, used in logs.
|
|
5
|
+
*
|
|
6
|
+
* @since 1.0.0
|
|
7
|
+
*/
|
|
8
|
+
label: string;
|
|
9
|
+
/**
|
|
10
|
+
* The path to the runner JavaScript file, relative to the app bundle.
|
|
11
|
+
*
|
|
12
|
+
* @since 1.0.0
|
|
13
|
+
*/
|
|
14
|
+
src: string;
|
|
15
|
+
/**
|
|
16
|
+
* The name of the event that will be called when the OS executes the background task.
|
|
17
|
+
*
|
|
18
|
+
* @since 1.0.0
|
|
19
|
+
*/
|
|
20
|
+
event: string;
|
|
21
|
+
/**
|
|
22
|
+
* If background task should repeat based on the interval set in `interval`.
|
|
23
|
+
*
|
|
24
|
+
* @since 1.0.0
|
|
25
|
+
*/
|
|
26
|
+
repeat: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The number of minutes after the the app is put into the background in which the background task should begin.
|
|
29
|
+
*
|
|
30
|
+
* If `repeat` is true, this also specifies the number of minutes between each execution.
|
|
31
|
+
*
|
|
32
|
+
* @since 1.0.0
|
|
33
|
+
*/
|
|
34
|
+
interval: number;
|
|
35
|
+
/**
|
|
36
|
+
* Automatically register and schedule background task on app load.
|
|
37
|
+
*
|
|
38
|
+
* @since 1.0.0
|
|
39
|
+
*/
|
|
40
|
+
autoStart?: boolean;
|
|
41
|
+
}
|
|
42
|
+
declare module '@capacitor/cli' {
|
|
43
|
+
interface PluginsConfig {
|
|
44
|
+
/**
|
|
45
|
+
* On load, Background Runner will automatically register a
|
|
46
|
+
* background task that will be scheduled and ran once your app is
|
|
47
|
+
* backgrounded.
|
|
48
|
+
*/
|
|
49
|
+
BackgroundRunner?: {
|
|
50
|
+
/**
|
|
51
|
+
* The name of the runner, used in logs.
|
|
52
|
+
*
|
|
53
|
+
* @since 1.0.0
|
|
54
|
+
* @example "com.example.background.task"
|
|
55
|
+
*/
|
|
56
|
+
label: string;
|
|
57
|
+
/**
|
|
58
|
+
* The path to the runner JavaScript file, relative to the app bundle.
|
|
59
|
+
*
|
|
60
|
+
* @since 1.0.0
|
|
61
|
+
* @example "runners/background.js"
|
|
62
|
+
*/
|
|
63
|
+
src: string;
|
|
64
|
+
/**
|
|
65
|
+
* The name of the event that will be called when the OS executes the background task.
|
|
66
|
+
*
|
|
67
|
+
* @since 1.0.0
|
|
68
|
+
* @example "myCustomEvent"
|
|
69
|
+
*/
|
|
70
|
+
event: string;
|
|
71
|
+
/**
|
|
72
|
+
* If background task should repeat based on the interval set in `interval`.
|
|
73
|
+
*
|
|
74
|
+
* @since 1.0.0
|
|
75
|
+
* @example true
|
|
76
|
+
*/
|
|
77
|
+
repeat: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* The number of minutes after the the app is put into the background in which the background task should begin.
|
|
80
|
+
*
|
|
81
|
+
* If `repeat` is true, this also specifies the number of minutes between each execution.
|
|
82
|
+
*
|
|
83
|
+
* @since 1.0.0
|
|
84
|
+
* @example 15
|
|
85
|
+
*/
|
|
86
|
+
interval: number;
|
|
87
|
+
/**
|
|
88
|
+
* Automatically register and schedule background task on app load.
|
|
89
|
+
*
|
|
90
|
+
* @since 1.0.0
|
|
91
|
+
* @example true
|
|
92
|
+
*/
|
|
93
|
+
autoStart?: boolean;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
2
97
|
export type API = 'geolocation' | 'notifications';
|
|
3
98
|
export interface PermissionStatus {
|
|
4
99
|
geolocation: PermissionState;
|
|
@@ -27,34 +122,6 @@ export interface RequestPermissionOptions {
|
|
|
27
122
|
export interface RegisterBackgroundTaskOptions {
|
|
28
123
|
runner: BackgroundRunnerConfig;
|
|
29
124
|
}
|
|
30
|
-
export interface BackgroundRunnerConfig {
|
|
31
|
-
/**
|
|
32
|
-
* The name of the runner, used in logs.
|
|
33
|
-
*/
|
|
34
|
-
label: string;
|
|
35
|
-
/**
|
|
36
|
-
* The path to the runner JavaScript file, relative to the app bundle.
|
|
37
|
-
*/
|
|
38
|
-
src: string;
|
|
39
|
-
/**
|
|
40
|
-
* The custom event that will be called when the background task is run.
|
|
41
|
-
*/
|
|
42
|
-
event: string;
|
|
43
|
-
/**
|
|
44
|
-
* Repeats the execution of the background task based on the interval set in `interval`.
|
|
45
|
-
*/
|
|
46
|
-
repeat: boolean;
|
|
47
|
-
/**
|
|
48
|
-
* The number of minutes after the the app is put into the background in which the background task should begin.
|
|
49
|
-
*
|
|
50
|
-
* If `repeat` is true, this also specifies the number of minutes between each execution.
|
|
51
|
-
*/
|
|
52
|
-
interval: number;
|
|
53
|
-
/**
|
|
54
|
-
* Automatically register and schedule background task on app load.
|
|
55
|
-
*/
|
|
56
|
-
autoStart?: boolean;
|
|
57
|
-
}
|
|
58
125
|
export interface BackgroundRunnerPlugin {
|
|
59
126
|
/**
|
|
60
127
|
* Check permissions for the various Capacitor device APIs.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAAA,wCAAwC","sourcesContent":["/// <reference types=\"@capacitor/cli\" />\n\nimport type { PermissionState } from '@capacitor/core';\n\nexport
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAAA,wCAAwC","sourcesContent":["/// <reference types=\"@capacitor/cli\" />\n\nimport type { PermissionState } from '@capacitor/core';\n\nexport interface BackgroundRunnerConfig {\n /**\n * The name of the runner, used in logs.\n *\n * @since 1.0.0\n */\n label: string;\n /**\n * The path to the runner JavaScript file, relative to the app bundle.\n *\n * @since 1.0.0\n */\n src: string;\n /**\n * The name of the event that will be called when the OS executes the background task.\n *\n * @since 1.0.0\n */\n event: string;\n /**\n * If background task should repeat based on the interval set in `interval`.\n *\n * @since 1.0.0\n */\n repeat: boolean;\n /**\n * The number of minutes after the the app is put into the background in which the background task should begin.\n *\n * If `repeat` is true, this also specifies the number of minutes between each execution.\n *\n * @since 1.0.0\n */\n interval: number;\n /**\n * Automatically register and schedule background task on app load.\n *\n * @since 1.0.0\n */\n autoStart?: boolean;\n}\n\ndeclare module '@capacitor/cli' {\n export interface PluginsConfig {\n /**\n * On load, Background Runner will automatically register a\n * background task that will be scheduled and ran once your app is\n * backgrounded.\n */\n BackgroundRunner?: {\n /**\n * The name of the runner, used in logs.\n *\n * @since 1.0.0\n * @example \"com.example.background.task\"\n */\n label: string;\n /**\n * The path to the runner JavaScript file, relative to the app bundle.\n *\n * @since 1.0.0\n * @example \"runners/background.js\"\n */\n src: string;\n /**\n * The name of the event that will be called when the OS executes the background task.\n *\n * @since 1.0.0\n * @example \"myCustomEvent\"\n */\n event: string;\n /**\n * If background task should repeat based on the interval set in `interval`.\n *\n * @since 1.0.0\n * @example true\n */\n repeat: boolean;\n /**\n * The number of minutes after the the app is put into the background in which the background task should begin.\n *\n * If `repeat` is true, this also specifies the number of minutes between each execution.\n *\n * @since 1.0.0\n * @example 15\n */\n interval: number;\n /**\n * Automatically register and schedule background task on app load.\n *\n * @since 1.0.0\n * @example true\n */\n autoStart?: boolean;\n };\n }\n}\n\nexport type API = 'geolocation' | 'notifications';\n\nexport interface PermissionStatus {\n geolocation: PermissionState;\n notifications: PermissionState;\n}\n\nexport interface DispatchEventOptions {\n /**\n * The runner label to dispatch the event to\n *\n * @since 1.0.0\n */\n label: string;\n /**\n * The name of the registered event listener.\n *\n * @since 1.0.0\n */\n event: string;\n details: { [key: string]: any };\n}\n\nexport interface RequestPermissionOptions {\n apis: API[];\n}\n\nexport interface RegisterBackgroundTaskOptions {\n runner: BackgroundRunnerConfig;\n}\n\nexport interface BackgroundRunnerPlugin {\n /**\n * Check permissions for the various Capacitor device APIs.\n *\n * @since 1.0.0\n */\n checkPermissions(): Promise<PermissionStatus>;\n /**\n * Request permission to display local notifications.\n *\n * @since 1.0.0\n */\n requestPermissions(\n options: RequestPermissionOptions,\n ): Promise<PermissionStatus>;\n /**\n * Dispatches an event to the configured runner.\n * @param options\n * @since 1.0.0\n */\n dispatchEvent(options: DispatchEventOptions): Promise<void>;\n}\n\ndeclare module '@capacitor/cli' {\n export interface PluginsConfig {\n BackgroundRunner?: BackgroundRunnerConfig;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor/background-runner",
|
|
3
|
-
"version": "1.0.6-dev-
|
|
3
|
+
"version": "1.0.6-dev-20230831T174057.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": "
|
|
84
|
+
"gitHead": "1f8633987278f10280966ca7a560211973d4104d"
|
|
85
85
|
}
|