@capacitor/background-runner 2.2.0 → 3.0.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.
Files changed (49) hide show
  1. package/CapacitorBackgroundRunner.podspec +2 -2
  2. package/Package.swift +45 -0
  3. package/README.md +12 -2
  4. package/android/build.gradle +12 -12
  5. package/android/src/main/java/io/ionic/backgroundrunner/plugin/BackgroundRunnerPlugin.kt +1 -1
  6. package/android/src/main/java/io/ionic/backgroundrunner/plugin/api/Device.kt +1 -1
  7. package/android/src/main/java/io/ionic/backgroundrunner/plugin/api/Notifications.kt +2 -10
  8. package/android/src/main/java/io/ionic/backgroundrunner/plugin/api/TimedNotificationPublisher.kt +1 -0
  9. package/android/src/main/libs/android-js-engine-release.aar +0 -0
  10. package/dist/esm/definitions.js.map +1 -1
  11. package/dist/esm/index.js +2 -2
  12. package/dist/esm/index.js.map +1 -1
  13. package/dist/esm/web.js.map +1 -1
  14. package/dist/plugin.cjs.js +2 -4
  15. package/dist/plugin.cjs.js.map +1 -1
  16. package/dist/plugin.js +2 -4
  17. package/dist/plugin.js.map +1 -1
  18. package/ios/{Plugin → Sources/CapacitorBackgroundRunner}/BackgroundRunner.swift +26 -11
  19. package/ios/{Plugin → Sources/CapacitorBackgroundRunner}/CapacitorAPI/Geolocation.swift +21 -9
  20. package/ios/{Plugin → Sources/CapacitorBackgroundRunner}/CapacitorAPI/Notifications.swift +2 -1
  21. package/ios/Sources/CapacitorBackgroundRunner/CapacitorBackgroundRunner.swift +308 -0
  22. package/ios/{Plugin → Sources/CapacitorBackgroundRunner}/Context+CapacitorAPI.swift +8 -2
  23. package/ios/{Plugin → Sources}/RunnerEngine/Context.swift +1 -1
  24. package/ios/{Plugin → Sources}/RunnerEngine/JSCrypto.swift +3 -3
  25. package/ios/{Plugin → Sources}/RunnerEngine/JSError.swift +1 -1
  26. package/ios/{Plugin → Sources}/RunnerEngine/Runner.swift +1 -1
  27. package/ios/Tests/CapacitorBackgroundRunnerTests/CapacitorBackgroundRunnerTests.swift +21 -0
  28. package/ios/Tests/RunnerEngineTests/ContextTests.swift +393 -0
  29. package/ios/Tests/RunnerEngineTests/RunnerTests.swift +32 -0
  30. package/package.json +24 -22
  31. package/scripts/install_libs.js +4 -12
  32. package/ios/Plugin/BackgroundRunnerPlugin.h +0 -10
  33. package/ios/Plugin/BackgroundRunnerPlugin.m +0 -12
  34. package/ios/Plugin/BackgroundRunnerPlugin.swift +0 -228
  35. package/ios/Plugin/Info.plist +0 -24
  36. /package/ios/{Plugin/BackgroundRunnerErrors.swift → Sources/CapacitorBackgroundRunner/BackgroundRunnerPluginError.swift} +0 -0
  37. /package/ios/{Plugin → Sources/CapacitorBackgroundRunner}/CapacitorAPI/App.swift +0 -0
  38. /package/ios/{Plugin → Sources/CapacitorBackgroundRunner}/CapacitorAPI/Device.swift +0 -0
  39. /package/ios/{Plugin → Sources/CapacitorBackgroundRunner}/CapacitorAPI/KV.swift +0 -0
  40. /package/ios/{Plugin → Sources/CapacitorBackgroundRunner}/CapacitorAPI/Reachability.swift +0 -0
  41. /package/ios/{Plugin → Sources/CapacitorBackgroundRunner}/CapacitorAPI/Watch.swift +0 -0
  42. /package/ios/{Plugin → Sources/CapacitorBackgroundRunner}/RunnerConfig.swift +0 -0
  43. /package/ios/{Plugin/WatchConnectivtySessionDelegate.swift → Sources/CapacitorBackgroundRunner/WatchConnectivitySessionDelegate.swift} +0 -0
  44. /package/ios/{Plugin → Sources}/RunnerEngine/Errors.swift +0 -0
  45. /package/ios/{Plugin → Sources}/RunnerEngine/JSConsole.swift +0 -0
  46. /package/ios/{Plugin → Sources}/RunnerEngine/JSFetch.swift +0 -0
  47. /package/ios/{Plugin → Sources}/RunnerEngine/JSResponse.swift +0 -0
  48. /package/ios/{Plugin → Sources}/RunnerEngine/JSTextDecoder.swift +0 -0
  49. /package/ios/{Plugin → Sources}/RunnerEngine/JSTextEncoder.swift +0 -0
@@ -10,8 +10,8 @@ Pod::Spec.new do |s|
10
10
  s.homepage = package['repository']['url']
11
11
  s.author = package['author']
12
12
  s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
- s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}', 'packages/capacitor-plugin/ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}', 'packages/ios-engine/Sources/RunnerEngine/*.swift'
14
- s.ios.deployment_target = '14.0'
13
+ s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
14
+ s.ios.deployment_target = '15.0'
15
15
  s.dependency 'Capacitor'
16
16
  s.swift_version = '5.1'
17
17
  end
package/Package.swift ADDED
@@ -0,0 +1,45 @@
1
+ // swift-tools-version: 5.7
2
+ // The swift-tools-version declares the minimum version of Swift required to build this package.
3
+
4
+ import PackageDescription
5
+
6
+ let package = Package(
7
+ name: "CapacitorBackgroundRunner",
8
+ platforms: [.iOS(.v15), .macOS(.v13)],
9
+ products: [
10
+ // Products define the executables and libraries a package produces, making them visible to other packages.
11
+ .library(
12
+ name: "CapacitorBackgroundRunner",
13
+ targets: ["CapacitorBackgroundRunner"]
14
+ )
15
+ ],
16
+ dependencies: [
17
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
18
+ ],
19
+ targets: [
20
+ // Targets are the basic building blocks of a package, defining a module or a test suite.
21
+ // Targets can depend on other targets in this package and products from dependencies.
22
+ .target(
23
+ name: "CapacitorBackgroundRunner",
24
+ dependencies: [
25
+ .product(name: "Capacitor", package: "capacitor-swift-pm"),
26
+ .product(name: "Cordova", package: "capacitor-swift-pm"),
27
+ "RunnerEngine"
28
+ ],
29
+ path: "ios/Sources/CapacitorBackgroundRunner"
30
+ ),
31
+ .target(
32
+ name: "RunnerEngine",
33
+ dependencies: [],
34
+ path: "ios/Sources/RunnerEngine"),
35
+ .testTarget(
36
+ name: "RunnerEngineTests",
37
+ dependencies: ["RunnerEngine"],
38
+ path: "ios/Tests/RunnerEngineTests"),
39
+ .testTarget(
40
+ name: "CapacitorBackgroundRunnerTests",
41
+ dependencies: ["CapacitorBackgroundRunner"],
42
+ path: "ios/Tests/CapacitorBackgroundRunnerTests"
43
+ )
44
+ ]
45
+ )
package/README.md CHANGED
@@ -23,6 +23,18 @@ If you will be making use of Geolocation or Push Notifications, enable `Location
23
23
 
24
24
  ![Configure Background Modes in Xcode](https://github.com/ionic-team/capacitor-background-runner/raw/main/docs/configure_background_modes.png)
25
25
 
26
+ You will also need to add the following entry into your `Info.plist` file:
27
+ ```
28
+ <key>BGTaskSchedulerPermittedIdentifiers</key>
29
+ <array>
30
+ <string>com.example.background.task</string>
31
+ </array>
32
+ ```
33
+
34
+ Read about [Configuring `Info.plist`](https://capacitorjs.com/docs/ios/configuration#configuring-infoplist) in the [iOS Guide](https://capacitorjs.com/docs/ios) for more information on setting iOS permissions in Xcode.
35
+
36
+ Make sure you use the same id that you use for `BGTaskSchedulerPermittedIdentifiers` (for example "com.example.background.task") in the `label` field in the plugin configuration.
37
+
26
38
  After enabling the Background Modes capability, add the following to your app's `AppDelegate.swift`:
27
39
 
28
40
  At the top of the file, under `import Capacitor` add:
@@ -65,8 +77,6 @@ Apple requires privacy descriptions to be specified in `Info.plist` for location
65
77
  - `NSLocationAlwaysUsageDescription` (`Privacy - Location Always Usage Description`)
66
78
  - `NSLocationWhenInUseUsageDescription` (`Privacy - Location When In Use Usage Description`)
67
79
 
68
- Read about [Configuring `Info.plist`](https://capacitorjs.com/docs/ios/configuration#configuring-infoplist) in the [iOS Guide](https://capacitorjs.com/docs/ios) for more information on setting iOS permissions in Xcode
69
-
70
80
  ## Android
71
81
 
72
82
  Insert the following line to `android/app/build.gradle`:
@@ -1,21 +1,21 @@
1
1
  ext {
2
2
  junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
- androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
4
- androidxCoreKTXVersion = project.hasProperty('androidxCoreKTXVersion') ? rootProject.ext.androidxCoreKTXVersion : '1.12.0'
5
- androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
6
- androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
7
- workManagerVersion = project.hasProperty('workManagerVersion') ? rootProject.ext.workManagerVersion : '2.8.1'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
4
+ androidxCoreKTXVersion = project.hasProperty('androidxCoreKTXVersion') ? rootProject.ext.androidxCoreKTXVersion : '1.17.0'
5
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
6
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
7
+ workManagerVersion = project.hasProperty('workManagerVersion') ? rootProject.ext.workManagerVersion : '2.11.0'
8
8
 
9
9
  }
10
10
 
11
11
  buildscript {
12
- ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '1.9.25'
12
+ ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '2.2.20'
13
13
  repositories {
14
14
  google()
15
15
  mavenCentral()
16
16
  }
17
17
  dependencies {
18
- classpath 'com.android.tools.build:gradle:8.7.2'
18
+ classpath 'com.android.tools.build:gradle:8.13.0'
19
19
  classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
20
20
 
21
21
  }
@@ -25,11 +25,11 @@ apply plugin: 'com.android.library'
25
25
  apply plugin: 'org.jetbrains.kotlin.android'
26
26
 
27
27
  android {
28
- namespace "com.capacitorjs.plugins.backgroundrunner"
29
- compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
28
+ namespace = "com.capacitorjs.plugins.backgroundrunner"
29
+ compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
30
30
  defaultConfig {
31
- minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
32
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
31
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
32
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
33
33
  versionCode 1
34
34
  versionName "1.0"
35
35
  testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -41,7 +41,7 @@ android {
41
41
  }
42
42
  }
43
43
  lintOptions {
44
- abortOnError false
44
+ abortOnError = false
45
45
  }
46
46
  compileOptions {
47
47
  sourceCompatibility JavaVersion.VERSION_21
@@ -19,7 +19,7 @@ import com.getcapacitor.Bridge
19
19
 
20
20
 
21
21
  @CapacitorPlugin(
22
- name = "BackgroundRunner",
22
+ name = "CapacitorBackgroundRunner",
23
23
  permissions = [
24
24
  Permission(
25
25
  strings = [Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION],
@@ -80,7 +80,7 @@ class Device (context: android.content.Context) : DeviceAPI {
80
80
  return false
81
81
  }
82
82
 
83
- @SuppressWarnings("deprecation")
83
+ @Suppress("DEPRECATION")
84
84
  private fun getAndParseNetworkInfo(): NetworkStatus {
85
85
  val networkStatus = NetworkStatus()
86
86
  val networkInfo = connectivityManager.activeNetworkInfo
@@ -211,17 +211,9 @@ class Notifications(context: Context) : NotificationsAPI {
211
211
  PendingIntent.getBroadcast(context, request.id, intent, flags)
212
212
 
213
213
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && !alarmManager.canScheduleExactAlarms()) {
214
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
215
- alarmManager.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, request.scheduleAt.time, pendingIntent);
216
- } else {
217
- alarmManager.set(AlarmManager.RTC, request.scheduleAt.time, pendingIntent);
218
- }
214
+ alarmManager.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, request.scheduleAt.time, pendingIntent)
219
215
  } else {
220
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
221
- alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, request.scheduleAt.time, pendingIntent);
222
- } else {
223
- alarmManager.setExact(AlarmManager.RTC, request.scheduleAt.time, pendingIntent);
224
- }
216
+ alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, request.scheduleAt.time, pendingIntent)
225
217
  }
226
218
  }
227
219
  }
@@ -34,6 +34,7 @@ class TimedNotificationPublisher : BroadcastReceiver() {
34
34
  notificationManager.notify(id, notification)
35
35
  }
36
36
 
37
+ @Suppress("DEPRECATION")
37
38
  private fun getParcelableExtraLegacy(intent: Intent): android.app.Notification? {
38
39
  return intent.getParcelableExtra(NOTIFICATION_KEY)
39
40
  }
@@ -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, PluginListenerHandle } 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 run 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 NotificationActionEvent {\n actionTypeId: string;\n notificationId: number;\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<T = void>(options: DispatchEventOptions): Promise<T>;\n /**\n * Add a listener for notification actions.\n *\n * @since 2.1.1\n */\n addListener(\n eventName: 'backgroundRunnerNotificationReceived',\n listenerFunc: (event: NotificationActionEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Remove notification action listeners for this plugin.\n *\n * @since 2.1.1\n */\n removeNotificationListeners(): Promise<void>;\n}\n\ndeclare module '@capacitor/cli' {\n export interface PluginsConfig {\n BackgroundRunner?: BackgroundRunnerConfig;\n }\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAAA,wCAAwC","sourcesContent":["/// <reference types=\"@capacitor/cli\" />\n\nimport type { PermissionState, PluginListenerHandle } 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 run 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 NotificationActionEvent {\n actionTypeId: string;\n notificationId: number;\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(options: RequestPermissionOptions): Promise<PermissionStatus>;\n /**\n * Dispatches an event to the configured runner.\n * @param options\n * @since 1.0.0\n */\n dispatchEvent<T = void>(options: DispatchEventOptions): Promise<T>;\n /**\n * Add a listener for notification actions.\n *\n * @since 2.1.1\n */\n addListener(\n eventName: 'backgroundRunnerNotificationReceived',\n listenerFunc: (event: NotificationActionEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Remove notification action listeners for this plugin.\n *\n * @since 2.1.1\n */\n removeNotificationListeners(): Promise<void>;\n}\n\ndeclare module '@capacitor/cli' {\n export interface PluginsConfig {\n BackgroundRunner?: BackgroundRunnerConfig;\n }\n}\n"]}
package/dist/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { registerPlugin } from '@capacitor/core';
2
- const BackgroundRunner = registerPlugin('BackgroundRunner', {
3
- web: () => import('./web').then(m => new m.BackgroundRunnerWeb()),
2
+ const BackgroundRunner = registerPlugin('CapacitorBackgroundRunner', {
3
+ web: () => import('./web').then((m) => new m.BackgroundRunnerWeb()),
4
4
  });
5
5
  export * from './definitions';
6
6
  export * from './apis';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,gBAAgB,GAAG,cAAc,CACrC,kBAAkB,EAClB;IACE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,mBAAmB,EAAE,CAAC;CAClE,CACF,CAAC;AAEF,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AAEvB,OAAO,EAAE,gBAAgB,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { BackgroundRunnerPlugin } from './definitions';\n\nconst BackgroundRunner = registerPlugin<BackgroundRunnerPlugin>(\n 'BackgroundRunner',\n {\n web: () => import('./web').then(m => new m.BackgroundRunnerWeb()),\n },\n);\n\nexport * from './definitions';\nexport * from './apis';\n\nexport { BackgroundRunner };\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,gBAAgB,GAAG,cAAc,CAAyB,2BAA2B,EAAE;IAC3F,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,mBAAmB,EAAE,CAAC;CACpE,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AAEvB,OAAO,EAAE,gBAAgB,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { BackgroundRunnerPlugin } from './definitions';\n\nconst BackgroundRunner = registerPlugin<BackgroundRunnerPlugin>('CapacitorBackgroundRunner', {\n web: () => import('./web').then((m) => new m.BackgroundRunnerWeb()),\n});\n\nexport * from './definitions';\nexport * from './apis';\n\nexport { BackgroundRunner };\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAS5C,MAAM,OAAO,mBACX,SAAQ,SAAS;IAGjB,gBAAgB;QACd,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IAED,kBAAkB;QAChB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IAED,sBAAsB;QACpB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IAED,aAAa,CAAW,QAA8B;QACpD,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,WAAW,CACf,UAAkD,EAClD,aAAuD;QAEvD,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,2BAA2B;QAC/B,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;CACF","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\nimport { WebPlugin } from '@capacitor/core';\n\nimport type {\n BackgroundRunnerPlugin,\n DispatchEventOptions,\n PermissionStatus,\n NotificationActionEvent,\n} from './definitions';\n\nexport class BackgroundRunnerWeb\n extends WebPlugin\n implements BackgroundRunnerPlugin\n{\n checkPermissions(): Promise<PermissionStatus> {\n throw new Error('not available on web');\n }\n\n requestPermissions(): Promise<PermissionStatus> {\n throw new Error('not available on web');\n }\n\n registerBackgroundTask(): Promise<void> {\n throw new Error('not available on web');\n }\n\n dispatchEvent<T = void>(_options: DispatchEventOptions): Promise<T> {\n throw new Error('not available on web');\n }\n\n async addListener(\n _eventName: 'backgroundRunnerNotificationReceived',\n _listenerFunc: (event: NotificationActionEvent) => void,\n ): Promise<PluginListenerHandle> {\n throw new Error('not available on web');\n }\n\n async removeNotificationListeners(): Promise<void> {\n throw new Error('not available on web');\n }\n}\n"]}
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAS5C,MAAM,OAAO,mBAAoB,SAAQ,SAAS;IAChD,gBAAgB;QACd,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IAED,kBAAkB;QAChB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IAED,sBAAsB;QACpB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IAED,aAAa,CAAW,QAA8B;QACpD,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,WAAW,CACf,UAAkD,EAClD,aAAuD;QAEvD,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,2BAA2B;QAC/B,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;CACF","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\nimport { WebPlugin } from '@capacitor/core';\n\nimport type {\n BackgroundRunnerPlugin,\n DispatchEventOptions,\n PermissionStatus,\n NotificationActionEvent,\n} from './definitions';\n\nexport class BackgroundRunnerWeb extends WebPlugin implements BackgroundRunnerPlugin {\n checkPermissions(): Promise<PermissionStatus> {\n throw new Error('not available on web');\n }\n\n requestPermissions(): Promise<PermissionStatus> {\n throw new Error('not available on web');\n }\n\n registerBackgroundTask(): Promise<void> {\n throw new Error('not available on web');\n }\n\n dispatchEvent<T = void>(_options: DispatchEventOptions): Promise<T> {\n throw new Error('not available on web');\n }\n\n async addListener(\n _eventName: 'backgroundRunnerNotificationReceived',\n _listenerFunc: (event: NotificationActionEvent) => void,\n ): Promise<PluginListenerHandle> {\n throw new Error('not available on web');\n }\n\n async removeNotificationListeners(): Promise<void> {\n throw new Error('not available on web');\n }\n}\n"]}
@@ -1,11 +1,9 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var core = require('@capacitor/core');
6
4
 
7
- const BackgroundRunner = core.registerPlugin('BackgroundRunner', {
8
- web: () => Promise.resolve().then(function () { return web; }).then(m => new m.BackgroundRunnerWeb()),
5
+ const BackgroundRunner = core.registerPlugin('CapacitorBackgroundRunner', {
6
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.BackgroundRunnerWeb()),
9
7
  });
10
8
 
11
9
  class BackgroundRunnerWeb extends core.WebPlugin {
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst BackgroundRunner = registerPlugin('BackgroundRunner', {\n web: () => import('./web').then(m => new m.BackgroundRunnerWeb()),\n});\nexport * from './definitions';\nexport * from './apis';\nexport { BackgroundRunner };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class BackgroundRunnerWeb extends WebPlugin {\n checkPermissions() {\n throw new Error('not available on web');\n }\n requestPermissions() {\n throw new Error('not available on web');\n }\n registerBackgroundTask() {\n throw new Error('not available on web');\n }\n dispatchEvent(_options) {\n throw new Error('not available on web');\n }\n async addListener(_eventName, _listenerFunc) {\n throw new Error('not available on web');\n }\n async removeNotificationListeners() {\n throw new Error('not available on web');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;;;AACK,MAAC,gBAAgB,GAAGA,mBAAc,CAAC,kBAAkB,EAAE;AAC5D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,mBAAmB,EAAE,CAAC;AACrE,CAAC;;ACFM,MAAM,mBAAmB,SAASC,cAAS,CAAC;AACnD,IAAI,gBAAgB,GAAG;AACvB,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;AAChD,KAAK;AACL,IAAI,kBAAkB,GAAG;AACzB,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;AAChD,KAAK;AACL,IAAI,sBAAsB,GAAG;AAC7B,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;AAChD,KAAK;AACL,IAAI,aAAa,CAAC,QAAQ,EAAE;AAC5B,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;AAChD,KAAK;AACL,IAAI,MAAM,WAAW,CAAC,UAAU,EAAE,aAAa,EAAE;AACjD,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;AAChD,KAAK;AACL,IAAI,MAAM,2BAA2B,GAAG;AACxC,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;AAChD,KAAK;AACL;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst BackgroundRunner = registerPlugin('CapacitorBackgroundRunner', {\n web: () => import('./web').then((m) => new m.BackgroundRunnerWeb()),\n});\nexport * from './definitions';\nexport * from './apis';\nexport { BackgroundRunner };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class BackgroundRunnerWeb extends WebPlugin {\n checkPermissions() {\n throw new Error('not available on web');\n }\n requestPermissions() {\n throw new Error('not available on web');\n }\n registerBackgroundTask() {\n throw new Error('not available on web');\n }\n dispatchEvent(_options) {\n throw new Error('not available on web');\n }\n async addListener(_eventName, _listenerFunc) {\n throw new Error('not available on web');\n }\n async removeNotificationListeners() {\n throw new Error('not available on web');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,gBAAgB,GAAGA,mBAAc,CAAC,2BAA2B,EAAE;AACrE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,mBAAmB,EAAE,CAAC;AACvE,CAAC;;ACFM,MAAM,mBAAmB,SAASC,cAAS,CAAC;AACnD,IAAI,gBAAgB,GAAG;AACvB,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC;AAC/C,IAAI;AACJ,IAAI,kBAAkB,GAAG;AACzB,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC;AAC/C,IAAI;AACJ,IAAI,sBAAsB,GAAG;AAC7B,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC;AAC/C,IAAI;AACJ,IAAI,aAAa,CAAC,QAAQ,EAAE;AAC5B,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC;AAC/C,IAAI;AACJ,IAAI,MAAM,WAAW,CAAC,UAAU,EAAE,aAAa,EAAE;AACjD,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC;AAC/C,IAAI;AACJ,IAAI,MAAM,2BAA2B,GAAG;AACxC,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC;AAC/C,IAAI;AACJ;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -1,8 +1,8 @@
1
1
  var capacitorBackgroundRunner = (function (exports, core) {
2
2
  'use strict';
3
3
 
4
- const BackgroundRunner = core.registerPlugin('BackgroundRunner', {
5
- web: () => Promise.resolve().then(function () { return web; }).then(m => new m.BackgroundRunnerWeb()),
4
+ const BackgroundRunner = core.registerPlugin('CapacitorBackgroundRunner', {
5
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.BackgroundRunnerWeb()),
6
6
  });
7
7
 
8
8
  class BackgroundRunnerWeb extends core.WebPlugin {
@@ -33,8 +33,6 @@ var capacitorBackgroundRunner = (function (exports, core) {
33
33
 
34
34
  exports.BackgroundRunner = BackgroundRunner;
35
35
 
36
- Object.defineProperty(exports, '__esModule', { value: true });
37
-
38
36
  return exports;
39
37
 
40
38
  })({}, capacitorExports);
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst BackgroundRunner = registerPlugin('BackgroundRunner', {\n web: () => import('./web').then(m => new m.BackgroundRunnerWeb()),\n});\nexport * from './definitions';\nexport * from './apis';\nexport { BackgroundRunner };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class BackgroundRunnerWeb extends WebPlugin {\n checkPermissions() {\n throw new Error('not available on web');\n }\n requestPermissions() {\n throw new Error('not available on web');\n }\n registerBackgroundTask() {\n throw new Error('not available on web');\n }\n dispatchEvent(_options) {\n throw new Error('not available on web');\n }\n async addListener(_eventName, _listenerFunc) {\n throw new Error('not available on web');\n }\n async removeNotificationListeners() {\n throw new Error('not available on web');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,gBAAgB,GAAGA,mBAAc,CAAC,kBAAkB,EAAE;IAC5D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,mBAAmB,EAAE,CAAC;IACrE,CAAC;;ICFM,MAAM,mBAAmB,SAASC,cAAS,CAAC;IACnD,IAAI,gBAAgB,GAAG;IACvB,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAChD,KAAK;IACL,IAAI,kBAAkB,GAAG;IACzB,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAChD,KAAK;IACL,IAAI,sBAAsB,GAAG;IAC7B,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAChD,KAAK;IACL,IAAI,aAAa,CAAC,QAAQ,EAAE;IAC5B,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAChD,KAAK;IACL,IAAI,MAAM,WAAW,CAAC,UAAU,EAAE,aAAa,EAAE;IACjD,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAChD,KAAK;IACL,IAAI,MAAM,2BAA2B,GAAG;IACxC,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAChD,KAAK;IACL;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst BackgroundRunner = registerPlugin('CapacitorBackgroundRunner', {\n web: () => import('./web').then((m) => new m.BackgroundRunnerWeb()),\n});\nexport * from './definitions';\nexport * from './apis';\nexport { BackgroundRunner };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class BackgroundRunnerWeb extends WebPlugin {\n checkPermissions() {\n throw new Error('not available on web');\n }\n requestPermissions() {\n throw new Error('not available on web');\n }\n registerBackgroundTask() {\n throw new Error('not available on web');\n }\n dispatchEvent(_options) {\n throw new Error('not available on web');\n }\n async addListener(_eventName, _listenerFunc) {\n throw new Error('not available on web');\n }\n async removeNotificationListeners() {\n throw new Error('not available on web');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,gBAAgB,GAAGA,mBAAc,CAAC,2BAA2B,EAAE;IACrE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,mBAAmB,EAAE,CAAC;IACvE,CAAC;;ICFM,MAAM,mBAAmB,SAASC,cAAS,CAAC;IACnD,IAAI,gBAAgB,GAAG;IACvB,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC;IAC/C,IAAI;IACJ,IAAI,kBAAkB,GAAG;IACzB,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC;IAC/C,IAAI;IACJ,IAAI,sBAAsB,GAAG;IAC7B,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC;IAC/C,IAAI;IACJ,IAAI,aAAa,CAAC,QAAQ,EAAE;IAC5B,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC;IAC/C,IAAI;IACJ,IAAI,MAAM,WAAW,CAAC,UAAU,EAAE,aAAa,EAAE;IACjD,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC;IAC/C,IAAI;IACJ,IAAI,MAAM,2BAA2B,GAAG;IACxC,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC;IAC/C,IAAI;IACJ;;;;;;;;;;;;;;;"}
@@ -1,8 +1,12 @@
1
- import Foundation
2
- import Capacitor
3
1
  import BackgroundTasks
2
+ import Capacitor
3
+ import Foundation
4
4
  import JavaScriptCore
5
5
 
6
+ #if canImport(RunnerEngine)
7
+ import RunnerEngine
8
+ #endif
9
+
6
10
  public class BackgroundRunner {
7
11
  public static let shared = BackgroundRunner()
8
12
  public var config: RunnerConfig?
@@ -27,7 +31,8 @@ public class BackgroundRunner {
27
31
  }
28
32
 
29
33
  guard let interval = config.interval else {
30
- throw BackgroundRunnerPluginError.invalidRunnerConfig(reason: "cannot register background task without a configured interval")
34
+ throw BackgroundRunnerPluginError.invalidRunnerConfig(
35
+ reason: "cannot register background task without a configured interval")
31
36
  }
32
37
 
33
38
  let request = BGAppRefreshTaskRequest(identifier: config.label)
@@ -64,7 +69,9 @@ public class BackgroundRunner {
64
69
  }
65
70
 
66
71
  // swiftlint:disable:next cyclomatic_complexity function_body_length
67
- public func execute(config: RunnerConfig, inputArgs: [String: Any]? = nil, callbackId: String? = nil) throws -> [String: Any]? {
72
+ public func execute(
73
+ config: RunnerConfig, inputArgs: [String: Any]? = nil, callbackId: String? = nil
74
+ ) throws -> [String: Any]? {
68
75
  do {
69
76
  let context = try initContext(config: config, callbackId: callbackId)
70
77
 
@@ -73,7 +80,7 @@ public class BackgroundRunner {
73
80
  var result: [String: Any]?
74
81
  var rejectionErr: JSError?
75
82
 
76
- let resolveFunc: @convention(block)(JavaScriptCore.JSValue) -> Void = { returnObj in
83
+ let resolveFunc: @convention(block) (JavaScriptCore.JSValue) -> Void = { returnObj in
77
84
  if !returnObj.isUndefined && !returnObj.isNull {
78
85
  var dict: [String: Any] = [:]
79
86
 
@@ -88,7 +95,7 @@ public class BackgroundRunner {
88
95
  return
89
96
  }
90
97
 
91
- let rejectFunc: @convention(block)(JavaScriptCore.JSValue) -> Void = { rejectObj in
98
+ let rejectFunc: @convention(block) (JavaScriptCore.JSValue) -> Void = { rejectObj in
92
99
  var rejectionTitle = "Error"
93
100
  var rejectionMessage = ""
94
101
 
@@ -136,7 +143,7 @@ public class BackgroundRunner {
136
143
  waitGroup.wait()
137
144
 
138
145
  if let rejection = rejectionErr {
139
- throw EngineError.jsException(details: rejection.message)
146
+ throw EngineError.jsException(details: rejection.toString())
140
147
  }
141
148
 
142
149
  return result
@@ -146,7 +153,8 @@ public class BackgroundRunner {
146
153
  }
147
154
  }
148
155
 
149
- public func dispatchEvent(event: String, inputArgs: [String: Any]?, callbackId: String? = nil) throws {
156
+ public func dispatchEvent(event: String, inputArgs: [String: Any]?, callbackId: String? = nil)
157
+ throws {
150
158
  if let config = config {
151
159
  let waitGroup = DispatchGroup()
152
160
  waitGroup.enter()
@@ -174,13 +182,17 @@ public class BackgroundRunner {
174
182
  }
175
183
 
176
184
  private func loadRunnerConfig() throws -> RunnerConfig? {
177
- guard let capacitorConfigFileURL = Bundle.main.url(forResource: "capacitor.config.json", withExtension: nil) else {
185
+ guard
186
+ let capacitorConfigFileURL = Bundle.main.url(
187
+ forResource: "capacitor.config.json", withExtension: nil)
188
+ else {
178
189
  throw BackgroundRunnerPluginError.runnerError(reason: "capacitor.config.json file not found")
179
190
  }
180
191
 
181
192
  let capacitorConfigFileData = try Data(contentsOf: capacitorConfigFileURL)
182
193
 
183
- if let capConfig = JSTypes.coerceDictionaryToJSObject(try JSONSerialization.jsonObject(with: capacitorConfigFileData) as? [String: Any]) {
194
+ if let capConfig = JSTypes.coerceDictionaryToJSObject(
195
+ try JSONSerialization.jsonObject(with: capacitorConfigFileData) as? [String: Any]) {
184
196
  if let jsonConfig = capConfig[keyPath: "plugins.BackgroundRunner"] as? JSObject {
185
197
  return try RunnerConfig(from: jsonConfig)
186
198
  }
@@ -190,7 +202,10 @@ public class BackgroundRunner {
190
202
  }
191
203
 
192
204
  private func initContext(config: RunnerConfig, callbackId: String?) throws -> Context {
193
- guard let srcFileURL = Bundle.main.url(forResource: config.src, withExtension: nil, subdirectory: "public") else {
205
+ guard
206
+ let srcFileURL = Bundle.main.url(
207
+ forResource: config.src, withExtension: nil, subdirectory: "public")
208
+ else {
194
209
  throw BackgroundRunnerPluginError.runnerError(reason: "source file not found")
195
210
  }
196
211
 
@@ -1,6 +1,10 @@
1
+ import CoreLocation
1
2
  import Foundation
2
3
  import JavaScriptCore
3
- import CoreLocation
4
+
5
+ #if canImport(RunnerEngine)
6
+ import RunnerEngine
7
+ #endif
4
8
 
5
9
  @objc protocol CapacitorGeolocationExports: JSExport {
6
10
  var isWatchingPosition: Bool { get }
@@ -32,9 +36,12 @@ class CapacitorGeolocation: NSObject, CapacitorGeolocationExports, CLLocationMan
32
36
  self.context = context
33
37
  self.locationManager.delegate = self
34
38
 
35
- self.locationManager.allowsBackgroundLocationUpdates = true
36
- self.locationManager.desiredAccuracy = kCLLocationAccuracyKilometer
37
- self.locationManager.pausesLocationUpdatesAutomatically = false
39
+ if CLLocationManager.authorizationStatus() == .authorizedAlways {
40
+ self.locationManager.allowsBackgroundLocationUpdates = true
41
+ self.locationManager.desiredAccuracy = kCLLocationAccuracyKilometer
42
+ self.locationManager.pausesLocationUpdatesAutomatically = false
43
+ }
44
+
38
45
  }
39
46
 
40
47
  static func getCurrentKnownLocation() -> CLLocation? {
@@ -71,7 +78,8 @@ class CapacitorGeolocation: NSObject, CapacitorGeolocationExports, CLLocationMan
71
78
  return
72
79
  }
73
80
 
74
- return try await withCheckedThrowingContinuation({ (continuation: CheckedContinuation<Void, Error>) in
81
+ return try await withCheckedThrowingContinuation({
82
+ (continuation: CheckedContinuation<Void, Error>) in
75
83
  permissionContinuation = continuation
76
84
 
77
85
  DispatchQueue.main.async {
@@ -96,7 +104,8 @@ class CapacitorGeolocation: NSObject, CapacitorGeolocationExports, CLLocationMan
96
104
 
97
105
  self.isWatchingLocation = true
98
106
  } catch {
99
- JSContext.current().exception = JSValue(newErrorFromMessage: "\(error)", in: JSContext.current())
107
+ JSContext.current().exception = JSValue(
108
+ newErrorFromMessage: "\(error)", in: JSContext.current())
100
109
  }
101
110
  }
102
111
 
@@ -121,7 +130,8 @@ class CapacitorGeolocation: NSObject, CapacitorGeolocationExports, CLLocationMan
121
130
 
122
131
  return buildLocationDict(location: lastLocation)
123
132
  } catch {
124
- JSContext.current().exception = JSValue(newErrorFromMessage: "\(error)", in: JSContext.current())
133
+ JSContext.current().exception = JSValue(
134
+ newErrorFromMessage: "\(error)", in: JSContext.current())
125
135
 
126
136
  return nil
127
137
  }
@@ -139,7 +149,8 @@ class CapacitorGeolocation: NSObject, CapacitorGeolocationExports, CLLocationMan
139
149
  try? context.dispatchEvent(event: "currentLocation", details: details)
140
150
  }
141
151
 
142
- pendingCurrentLocationCalls.forEach { (callId: Int, callback: (Result<CLLocation?, Error>) -> Void) in
152
+ pendingCurrentLocationCalls.forEach {
153
+ (callId: Int, callback: (Result<CLLocation?, Error>) -> Void) in
143
154
  pendingCurrentLocationCalls.removeValue(forKey: callId)
144
155
  callback(.success(locations.last))
145
156
  }
@@ -162,7 +173,8 @@ class CapacitorGeolocation: NSObject, CapacitorGeolocationExports, CLLocationMan
162
173
  try? context.dispatchEvent(event: "currentLocation", details: details)
163
174
  }
164
175
 
165
- pendingCurrentLocationCalls.forEach { (callId: Int, callback: (Result<CLLocation?, Error>) -> Void) in
176
+ pendingCurrentLocationCalls.forEach {
177
+ (callId: Int, callback: (Result<CLLocation?, Error>) -> Void) in
166
178
  pendingCurrentLocationCalls.removeValue(forKey: callId)
167
179
  callback(.failure(error))
168
180
  }
@@ -1,4 +1,5 @@
1
1
  import Foundation
2
+ import UIKit
2
3
  import JavaScriptCore
3
4
  import UserNotifications
4
5
 
@@ -136,7 +137,7 @@ class CapacitorNotifications: NSObject, CapacitorNotificationsExports {
136
137
  let content = UNMutableNotificationContent()
137
138
  content.title = NSString.localizedUserNotificationString(forKey: notificationOption.title, arguments: nil)
138
139
  content.body = NSString.localizedUserNotificationString(forKey: notificationOption.body, arguments: nil)
139
- content.userInfo = [:]
140
+ content.userInfo = ["source": "capacitor-background-runner"]
140
141
 
141
142
  if let extra = notificationOption.extra {
142
143
  content.userInfo["cap_extra"] = extra