@capacitor/background-runner 1.0.1-dev-20230731T175405.0 → 1.0.1-dev-20230809T182239.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
@@ -10,13 +10,14 @@ npx cap sync
10
10
  ```
11
11
 
12
12
  Background Runner has support for various device APIs that require permission from the user prior to use.
13
+
13
14
  ## iOS
14
15
 
15
- On iOS you must enable the Background Modes capability.
16
+ On iOS you must enable the Background Modes capability.
16
17
 
17
18
  ![Enable Background Mode Capability in Xcode](https://github.com/ionic-team/capacitor-background-runner/raw/main/docs/enable_background_mode_capability.png)
18
19
 
19
- Once added, you must enable the `Background fetch` and `Background processing` modes at a minimum to enable the ability to register and schedule your background tasks.
20
+ Once added, you must enable the `Background fetch` and `Background processing` modes at a minimum to enable the ability to register and schedule your background tasks.
20
21
 
21
22
  If you will be making use of Geolocation or Push Notifications, enable `Location updates` or `Remote notifications` respectively.
22
23
 
@@ -26,7 +27,7 @@ After enabling the Background Modes capability, add the following to your app's
26
27
 
27
28
  ```swift
28
29
  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
29
-
30
+
30
31
  // ....
31
32
  BackgroundRunnerPlugin.registerBackgroundTask()
32
33
  BackgroundRunnerPlugin.handleApplicationDidFinishLaunching(launchOptions: launchOptions)
@@ -37,6 +38,7 @@ func application(_ application: UIApplication, didFinishLaunchingWithOptions lau
37
38
  ```
38
39
 
39
40
  To allow the Background Runner to handle remote notifications, add the following:
41
+
40
42
  ```swift
41
43
  func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
42
44
  // ....
@@ -52,6 +54,7 @@ func application(_ application: UIApplication, didReceiveRemoteNotification user
52
54
  ```
53
55
 
54
56
  ### Geolocation
57
+
55
58
  Apple requires privacy descriptions to be specified in `Info.plist` for location information:
56
59
 
57
60
  - `NSLocationAlwaysUsageDescription` (`Privacy - Location Always Usage Description`)
@@ -62,6 +65,7 @@ Read about [Configuring `Info.plist`](https://capacitorjs.com/docs/ios/configura
62
65
  ## Android
63
66
 
64
67
  ### Geolocation
68
+
65
69
  This API requires the following permissions be added to your `AndroidManifest.xml`:
66
70
 
67
71
  ```xml
@@ -74,7 +78,8 @@ This API requires the following permissions be added to your `AndroidManifest.xm
74
78
  The first two permissions ask for location data, both fine and coarse, and the last line is optional but necessary if your app _requires_ GPS to function. You may leave it out, though keep in mind that this may mean your app is installed on devices lacking GPS hardware.
75
79
 
76
80
  ### Local Notifications
77
- Android 13 requires a permission check in order to send notifications. You are required to call `checkPermissions()` and `requestPermissions()` accordingly.
81
+
82
+ Android 13 requires a permission check in order to send notifications. You are required to call `checkPermissions()` and `requestPermissions()` accordingly.
78
83
 
79
84
  On Android 12 and older it won't show a prompt and will just return as granted.
80
85
 
@@ -89,62 +94,71 @@ Note that even if the permission is present, users can still disable exact notif
89
94
  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.
90
95
 
91
96
  ## Using Background Runner
92
- Background Runner is an event based JavaScript environment that emits events to a javascript runner 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 `details.completed()` is called (or if the OS force kills your process).
97
+
98
+ Background Runner is an event based JavaScript environment that emits events to a javascript runner 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).
93
99
 
94
100
  #### Example Runner JS File
95
101
 
96
102
  ```js
97
- addEventListener("myCustomEvent", (details) => {
98
- console.log("do something to update the system here");
99
- details.completed();
103
+ addEventListener('myCustomEvent', (resolve, reject, args) => {
104
+ console.log('do something to update the system here');
105
+ resolve();
100
106
  });
101
107
 
102
- addEventListener("myCustomEventWithReturnData", (details) => {
103
- console.log("accepted this data: " + JSON.stringify(details.user));
108
+ addEventListener('myCustomEventWithReturnData', (resolve, reject, args) => {
109
+ try {
110
+ console.log('accepted this data: ' + JSON.stringify(args.user));
104
111
 
105
- const updatedUser = details.user;
106
- updatedUser.firstName = updatedUser.firstName + " HELLO";
107
- updatedUser.lastName = updatedUser.lastName + " WORLD";
112
+ const updatedUser = args.user;
113
+ updatedUser.firstName = updatedUser.firstName + ' HELLO';
114
+ updatedUser.lastName = updatedUser.lastName + ' WORLD';
108
115
 
109
- details.completed(updatedUser);
116
+ resolve(updatedUser);
117
+ } catch (err) {
118
+ reject(err);
119
+ }
110
120
  });
111
121
 
112
- addEventListener("remoteNotification", (details) => {
113
- console.log("received silent push notification");
122
+ addEventListener('remoteNotification', (resolve, reject, args) => {
123
+ try {
124
+ console.log('received silent push notification');
114
125
 
115
- CapacitorNotifications.schedule([
116
- {
126
+ CapacitorNotifications.schedule([
127
+ {
117
128
  id: 100,
118
- title: "Enterprise Background Runner",
119
- body: "Received silent push notification",
120
- },
121
- ]);
122
-
123
- details.completed();
129
+ title: 'Enterprise Background Runner',
130
+ body: 'Received silent push notification',
131
+ },
132
+ ]);
133
+
134
+ resolve();
135
+ } catch (err) {
136
+ reject();
137
+ }
124
138
  });
125
-
126
139
  ```
127
- Calling `details.completed()` is **required** within every event handler called by the runner. Failure to do this could result in your runner being killed by the OS if your event is called while the app is in the background. If the app is in the foreground, async calls to `dispatchEvent` may not resolve.
140
+
141
+ Calling `resolve()` \ `reject()` is **required** within every event handler called by the runner. Failure to do this could result in your runner being killed by the OS if your event is called while the app is in the background. If the app is in the foreground, async calls to `dispatchEvent` may not resolve.
128
142
 
129
143
  ## Configuring Background Runner
130
- On load, Background Runner will automatically register a background task that will be scheduled and ran once your app is backgrounded. The settings for this behavior is defined in your `capacitor.config.ts` file:
144
+
145
+ On load, Background Runner will automatically register a background task that will be scheduled and ran once your app is backgrounded. The settings for this behavior is defined in your `capacitor.config.ts` file:
131
146
 
132
147
  ```ts
133
148
  const config: CapacitorConfig = {
134
- plugins: {
135
- BackgroundRunner: {
136
- label: "com.example.background.task",
137
- src: "background.js",
138
- event: "myCustomEvent",
139
- repeat: true,
140
- interval: 2,
141
- autoStart: false,
142
- },
149
+ plugins: {
150
+ BackgroundRunner: {
151
+ label: 'com.example.background.task',
152
+ src: 'background.js',
153
+ event: 'myCustomEvent',
154
+ repeat: true,
155
+ interval: 2,
156
+ autoStart: false,
143
157
  },
144
- }
158
+ },
159
+ };
145
160
  ```
146
161
 
147
-
148
162
  ## JavaScript API
149
163
 
150
164
  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.
@@ -152,58 +166,47 @@ Background Runner does not execute your Javascript code in a browser or web view
152
166
  Below is a list of the available Web APIs provided in Background Runner:
153
167
 
154
168
  - [console](https://developer.mozilla.org/en-US/docs/Web/API/console)
155
- - only `info`, `log`, `warn`, `error` , and `debug` are available
169
+ - only `info`, `log`, `warn`, `error` , and `debug` are available
156
170
  - [TextDecoder](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder)
157
- - only `decode` is available
171
+ - only `decode` is available
158
172
  - [TextEncoder](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder)
159
- - only `encode` is available
173
+ - only `encode` is available
160
174
  - [addEventListener](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener)
161
- - Event Listener options and `useCapture` not supported
175
+ - Event Listener options and `useCapture` not supported
162
176
  - [setTimeout](https://developer.mozilla.org/en-US/docs/Web/API/setTimeout)
163
177
  - [setInterval](https://developer.mozilla.org/en-US/docs/Web/API/setInterval)
164
178
  - [clearTimeout](https://developer.mozilla.org/en-US/docs/Web/API/clearTimeout)
165
179
  - [clearInterval](https://developer.mozilla.org/en-US/docs/Web/API/clearInterval)
166
180
  - [crypto](https://developer.mozilla.org/en-US/docs/Web/API/Crypto)
167
181
  - [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
168
- - Request object not yet supported
169
- - Only `method`, `headers` and `body` supported in options object
170
-
171
- In addition to the standard Web APIs, Background Runner also supports a number of custom APIs that expose relevant mobile device functionality:
172
-
173
- - CapacitorKV - a simple string key / value store backed by UserDefaults on iOS and Shared Preferences on Android.
174
- - `get(key: string): string`
175
- - `set(key: string, value: string)`
176
- - `remove(key: string)`
177
- - CapacitorNotifications - basic support for sending local notifications.
178
- - `schedule()`
179
- - CapacitorDevice - provides information on the device, such as network connectivity and battery status.
180
- - `getBatteryStatus()`
181
- - `getNetworkStatus()`
182
- - CapacitorGeolocation - provides access to the device location information
183
- - `getCurrentPosition()`
182
+ - Request object not yet supported
183
+ - Only `method`, `headers` and `body` supported in options object
184
+
185
+ In addition to the standard Web APIs, Background Runner also supports a number of [custom Capacitor APIs](#capacitor-api) custom APIs that expose relevant mobile device functionality
184
186
 
185
187
  ## Runner Lifetimes
186
188
 
187
- Currently, the runners are designed for performing periodic bursts of work while your app is in the background, or for executing asynchronous work in a separate thread from your UI while your app is in the foreground. As a result, runners are not long lived. State is not maintained between calls to events in the runner. Each call to `dispatchEvent()` creates a new context in with your runner code is loaded and executed, and once `completed()` is called, the context is destroyed.
189
+ Currently, the runners are designed for performing periodic bursts of work while your app is in the background, or for executing asynchronous work in a thread separate from your UI while your app is in the foreground. As a result, runners are not long lived. State is not maintained between calls to events in the runner. Each call to `dispatchEvent()` creates a new context in which your runner code is loaded and executed, and once `resolve()` or `reject()` is called, the context is destroyed.
188
190
 
189
191
  ## Android Battery Optimizations
190
- Some Android vendors offer built-in battery optimization settings that go beyond what stock Android provides. Some of these optimizations must be disabled by your end users in order for your background tasks to work properly.
192
+
193
+ Some Android vendors offer built-in battery optimization settings that go beyond what stock Android provides. Some of these optimizations must be disabled by your end users in order for your background tasks to work properly.
191
194
 
192
195
  Visit [Don't kill my app!](https://dontkillmyapp.com) for more information on the affected manufacturers and steps required by your users to adjust the settings.
193
196
 
194
197
  ## Limitations of Background Tasks
195
198
 
196
- It’s not possible to run persistent, always running background services on mobile operating systems. Due to the limitations imposed by iOS and Android designed to reduce battery and data consumption, background tasks are constrained with various limitations that you must keep in mind while designing and implementing your background task.
199
+ It’s not possible to run persistent, always running background services on mobile operating systems. Due to the limitations imposed by iOS and Android designed to reduce battery and data consumption, background tasks are constrained with various limitations that you must keep in mind while designing and implementing your background task.
197
200
 
198
201
  ### iOS
199
202
 
200
203
  - Each invocation of your task has approximately up to 30 seconds of runtime before you must call `completed()` or your task is killed.
201
- - While you can set an interval to define when your task runs after the app is backgrounded, or how often it should run, this is not guaranteed. iOS will determine when and how often you task will ultimately run, determined in part by how often you app is used.
204
+ - While you can set an interval to define when your task runs after the app is backgrounded, or how often it should run, this is not guaranteed. iOS will determine when and how often you task will ultimately run, determined in part by how often you app is used.
202
205
 
203
206
  ### Android
204
207
 
205
208
  - Your task has a maximum of 10 minutes to perform work, but to keep your task cross platform compatible, you should limit your work to 30 seconds at most.
206
- - Repeating background tasks have a minimal interval of at least 15 minutes. Similar to iOS, any interval you request may not be hit exactly - actual execution time is subject to OS battery optimizations and other heuristics.
209
+ - Repeating background tasks have a minimal interval of at least 15 minutes. Similar to iOS, any interval you request may not be hit exactly - actual execution time is subject to OS battery optimizations and other heuristics.
207
210
 
208
211
  ## API
209
212
 
@@ -313,3 +316,105 @@ Dispatches an event to the configured runner.
313
316
  <code>'geolocation' | 'notifications'</code>
314
317
 
315
318
  </docgen-api>
319
+
320
+ ## Capacitor API
321
+
322
+ <capacitor-api-docs>
323
+
324
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
325
+
326
+ ### Interfaces
327
+
328
+
329
+ #### CapacitorDevice
330
+
331
+ Get information on the device, such as network connectivity and battery status.
332
+
333
+ | Prop | Type | Description | Since |
334
+ | ---------------------- | ---------------------------------------------------------------- | ---------------------------------------------- | ----- |
335
+ | **`getBatteryStatus`** | <code>() =&gt; <a href="#batterystatus">BatteryStatus</a></code> | Get the current battery status for the device. | 1.0.0 |
336
+ | **`getNetworkStatus`** | <code>() =&gt; <a href="#networkstatus">NetworkStatus</a></code> | Get the current network status for the device. | 1.0.0 |
337
+
338
+
339
+ #### BatteryStatus
340
+
341
+ | Prop | Type |
342
+ | ------------------ | -------------------- |
343
+ | **`batteryLevel`** | <code>number</code> |
344
+ | **`isCharging`** | <code>boolean</code> |
345
+
346
+
347
+ #### NetworkStatus
348
+
349
+ | Prop | Type |
350
+ | -------------------- | -------------------- |
351
+ | **`connected`** | <code>boolean</code> |
352
+ | **`connectionType`** | <code>string</code> |
353
+
354
+
355
+ #### CapacitorKV
356
+
357
+ A simple string key / value store backed by UserDefaults on iOS and Shared Preferences on Android.
358
+
359
+ | Prop | Type | Description | Since |
360
+ | ------------ | ---------------------------------------------------- | -------------------------------------- | ----- |
361
+ | **`set`** | <code>(key: string, value: string) =&gt; void</code> | Set a string value with the given key. | 1.0.0 |
362
+ | **`get`** | <code>(key: string) =&gt; string</code> | Get a string value for the given key. | 1.0.0 |
363
+ | **`remove`** | <code>(key: string) =&gt; void</code> | Remove a value with the given key. | 1.0.0 |
364
+
365
+
366
+ #### CapacitorNotifications
367
+
368
+ Send basic local notifications.
369
+
370
+ | Prop | Type | Description | Since |
371
+ | -------------- | ------------------------------------- | ----------------------------- | ----- |
372
+ | **`schedule`** | <code>(options: {}) =&gt; void</code> | Schedule a local notification | 1.0.0 |
373
+
374
+
375
+ #### NotificationScheduleOptions
376
+
377
+ | Prop | Type | Description | Since |
378
+ | ---------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
379
+ | **`id`** | <code>number</code> | The notification identifier. On Android it's a 32-bit int. So the value should be between -2147483648 and 2147483647 inclusive. | 1.0.0 |
380
+ | **`title`** | <code>string</code> | The title of the notification. | 1.0.0 |
381
+ | **`body`** | <code>string</code> | The body of the notification, shown below the title. | 1.0.0 |
382
+ | **`scheduleAt`** | <code>Date</code> | Date to send this notification. | 1.0.0 |
383
+ | **`sound`** | <code>string</code> | Name of the audio file to play when this notification is displayed. Include the file extension with the filename. On iOS, the file should be in the app bundle. On Android, the file should be in res/raw folder. Recommended format is `.wav` because is supported by both iOS and Android. Only available for iOS and Android &lt; 26. For Android 26+ use channelId of a channel configured with the desired sound. If the sound file is not found, (i.e. empty string or wrong name) the default system notification sound will be used. If not provided, it will produce the default sound on Android and no sound on iOS. | 1.0.0 |
384
+ | **`actionTypeId`** | <code>string</code> | Associate an action type with this notification. | 1.0.0 |
385
+ | **`threadIdentifier`** | <code>string</code> | Used to group multiple notifications. Sets `threadIdentifier` on the [`UNMutableNotificationContent`](https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent). Only available for iOS. | 1.0.0 |
386
+ | **`summaryArgument`** | <code>string</code> | The string this notification adds to the category's summary format string. Sets `summaryArgument` on the [`UNMutableNotificationContent`](https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent). Only available for iOS. | 1.0.0 |
387
+ | **`group`** | <code>string</code> | Used to group multiple notifications. Calls `setGroup()` on [`NotificationCompat.Builder`](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder) with the provided value. Only available for Android. | 1.0.0 |
388
+ | **`groupSummary`** | <code>string</code> | If true, this notification becomes the summary for a group of notifications. Calls `setGroupSummary()` on [`NotificationCompat.Builder`](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder) with the provided value. Only available for Android when using `group`. | 1.0.0 |
389
+ | **`extra`** | <code>any</code> | Set extra data to store within this notification. | 1.0.0 |
390
+ | **`ongoing`** | <code>boolean</code> | If true, the notification can't be swiped away. Calls `setOngoing()` on [`NotificationCompat.Builder`](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder) with the provided value. Only available for Android. | 1.0.0 |
391
+ | **`autoCancel`** | <code>boolean</code> | If true, the notification is canceled when the user clicks on it. Calls `setAutoCancel()` on [`NotificationCompat.Builder`](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder) with the provided value. Only available for Android. | 1.0.0 |
392
+ | **`largeBody`** | <code>string</code> | Sets a multiline text block for display in a big text notification style. | 1.0.0 |
393
+ | **`summaryText`** | <code>string</code> | Used to set the summary text detail in inbox and big text notification styles. Only available for Android. | 1.0.0 |
394
+ | **`smallIcon`** | <code>string</code> | Set a custom status bar icon. If set, this overrides the `smallIcon` option from Capacitor configuration. Icons should be placed in your app's `res/drawable` folder. The value for this option should be the drawable resource ID, which is the filename without an extension. Only available for Android. | 1.0.0 |
395
+ | **`largeIcon`** | <code>string</code> | Set a large icon for notifications. Icons should be placed in your app's `res/drawable` folder. The value for this option should be the drawable resource ID, which is the filename without an extension. Only available for Android. | 1.0.0 |
396
+ | **`channelId`** | <code>string</code> | Specifies the channel the notification should be delivered on. If channel with the given name does not exist then the notification will not fire. If not provided, it will use the default channel. Calls `setChannelId()` on [`NotificationCompat.Builder`](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder) with the provided value. Only available for Android 26+. | 1.0.0 |
397
+
398
+
399
+ #### CapacitorGeolocation
400
+
401
+ Get access to device location information.
402
+
403
+ | Prop | Type | Description | Since |
404
+ | ------------------------ | -------------------------------------------------------------------------------------- | ------------------------------------ | ----- |
405
+ | **`getCurrentLocation`** | <code>() =&gt; <a href="#getcurrentpositionresult">GetCurrentPositionResult</a></code> | Get the device's last known location | 1.0.0 |
406
+
407
+
408
+ #### GetCurrentPositionResult
409
+
410
+ | Prop | Type | Description | Since |
411
+ | ---------------------- | --------------------------- | --------------------------------------------------------------------------------------------------------------------- | ----- |
412
+ | **`latitude`** | <code>number</code> | Latitude in decimal degrees | 1.0.0 |
413
+ | **`longitude`** | <code>number</code> | longitude in decimal degrees | 1.0.0 |
414
+ | **`accuracy`** | <code>number</code> | Accuracy level of the latitude and longitude coordinates in meters | 1.0.0 |
415
+ | **`altitude`** | <code>number \| null</code> | The altitude the user is at (if available) | 1.0.0 |
416
+ | **`altitudeAccuracy`** | <code>number \| null</code> | Accuracy level of the altitude coordinate in meters, if available. Available on all iOS versions and on Android 8.0+. | 1.0.0 |
417
+ | **`speed`** | <code>number \| null</code> | The speed the user is traveling (if available) | 1.0.0 |
418
+ | **`heading`** | <code>number \| null</code> | The heading the user is facing (if available) | 1.0.0 |
419
+
420
+ </capacitor-api-docs>
@@ -50,6 +50,7 @@ class BackgroundRunner(context: android.content.Context) {
50
50
 
51
51
  runner = Runner()
52
52
  context = initContext(config, androidContext)
53
+ context?.start()
53
54
  }
54
55
 
55
56
  fun scheduleBackgroundTask(androidContext: android.content.Context) {
@@ -84,7 +85,7 @@ class BackgroundRunner(context: android.content.Context) {
84
85
  }
85
86
  }
86
87
 
87
- suspend fun execute(androidContext: android.content.Context, config: RunnerConfig, args: JSONObject = JSONObject()): JSONObject? {
88
+ suspend fun execute(androidContext: android.content.Context, config: RunnerConfig, dataArgs: JSONObject = JSONObject()): JSONObject? {
88
89
  if (!started) {
89
90
  start(androidContext)
90
91
  }
@@ -93,17 +94,37 @@ class BackgroundRunner(context: android.content.Context) {
93
94
 
94
95
  val future = MutableStateFlow<Result<JSONObject?>?>(null)
95
96
 
96
- class CompletionCallback : JSFunction(jsName = "completed") {
97
+ class ResolveCallback : JSFunction(jsName = "resolve") {
97
98
  override fun run() {
98
99
  super.run()
99
100
  future.value = Result.success(this.args)
100
101
  }
101
102
  }
102
103
 
103
- val callback = CompletionCallback()
104
- context!!.registerFunction("_backgroundCallback", callback)
104
+ class RejectCallback : JSFunction(jsName = "reject") {
105
+ override fun run() {
106
+ super.run()
107
+ val rejectionTitle = this.args?.optString("name", "Error") ?: "Error"
108
+ val rejectionMessage = this.args?.optString("message") ?: ""
109
+ val error = Exception("$rejectionTitle: $rejectionMessage")
110
+
111
+ future.value = Result.failure(error)
112
+ }
113
+ }
105
114
 
106
- args.put("completed", "__cbr::_backgroundCallback")
115
+ val resolve = ResolveCallback()
116
+ val reject = RejectCallback()
117
+ context!!.registerFunction("_resolveCallback", resolve)
118
+ context!!.registerFunction("_rejectCallback", reject)
119
+
120
+ val args = JSONObject()
121
+
122
+ val callbacks = JSONObject();
123
+ callbacks.put("resolve", "__cbr::_resolveCallback")
124
+ callbacks.put("reject", "__cbr::_rejectCallback")
125
+
126
+ args.put("callbacks", callbacks)
127
+ args.put("dataArgs", dataArgs)
107
128
 
108
129
  context!!.dispatchEvent(config.event, args)
109
130
 
@@ -158,7 +179,6 @@ class BackgroundRunner(context: android.content.Context) {
158
179
 
159
180
  newContext.setCapacitorAPI(api)
160
181
 
161
-
162
182
  newContext.execute(srcFile, false)
163
183
 
164
184
  return newContext