@zykeco/expo-background-task 1.0.0 → 1.0.2

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
@@ -1,6 +1,8 @@
1
1
  # expo-background-task
2
2
 
3
- Expo Android and iOS module for Background Task APIs
3
+ Expo Android and iOS module for Background Task APIs.
4
+
5
+ > This is a non-fork fork of [`expo-background-task`](https://github.com/expo/expo/tree/main/packages/expo-background-task) from the [`expo/expo`](https://github.com/expo/expo) repository, published as `@zykeco/expo-background-task`. It includes bug fixes and the `iosTaskType` option that are not yet available upstream.
4
6
 
5
7
  # API documentation
6
8
 
@@ -103,7 +105,7 @@ await BackgroundTask.registerTaskAsync('heavyTask', {
103
105
 
104
106
  | Option | Platforms | Default | Description |
105
107
  |---|---|---|---|
106
- | `minimumInterval` | iOS, Android | 720 (12h) | Minimum interval in minutes between task executions |
108
+ | `minimumInterval` | iOS, Android | iOS: 720 (12h), Android: 1440 (24h) | Minimum interval in minutes between task executions |
107
109
  | `iosTaskType` | iOS only | `'refresh'` | Which BGTask type to use |
108
110
  | `requiresNetworkConnectivity` | iOS, Android | `true` | Whether the task needs network access |
109
111
  | `requiresExternalPower` | iOS only | `false` | Whether the task needs external power (only for `'processing'`) |
@@ -17,11 +17,11 @@ import com.google.common.util.concurrent.ListenableFuture
17
17
  import expo.modules.interfaces.taskManager.TaskServiceProviderHelper
18
18
  import kotlinx.coroutines.CancellationException
19
19
  import kotlinx.coroutines.CompletableDeferred
20
+ import kotlinx.coroutines.CoroutineScope
20
21
  import kotlinx.coroutines.Dispatchers
22
+ import kotlinx.coroutines.SupervisorJob
21
23
  import kotlinx.coroutines.awaitAll
22
- import kotlinx.coroutines.CoroutineScope
23
24
  import kotlinx.coroutines.launch
24
-
25
25
  import kotlinx.coroutines.withContext
26
26
  import java.time.Duration
27
27
  import java.util.concurrent.TimeUnit
@@ -36,6 +36,10 @@ object BackgroundTaskScheduler {
36
36
  // Log tag
37
37
  private val TAG = BackgroundTaskScheduler::class.java.simpleName
38
38
 
39
+ // Structured coroutine scope for async scheduling operations.
40
+ // SupervisorJob prevents one failure from cancelling sibling coroutines.
41
+ private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
42
+
39
43
  // Number of active task consumers
40
44
  private var numberOfRegisteredTasksOfThisType = 0
41
45
 
@@ -45,7 +49,9 @@ object BackgroundTaskScheduler {
45
49
  // Whether network connectivity is required
46
50
  private var requiresNetwork: Boolean = true
47
51
 
48
- // Tracks whether in foreground
52
+ // Tracks whether in foreground — @Volatile for cross-thread visibility
53
+ // (written from main thread via lifecycle callbacks, read from WorkManager background thread)
54
+ @Volatile
49
55
  var inForeground: Boolean = false
50
56
 
51
57
  /**
@@ -59,7 +65,7 @@ object BackgroundTaskScheduler {
59
65
  }
60
66
 
61
67
  if (numberOfRegisteredTasksOfThisType == 1) {
62
- CoroutineScope(Dispatchers.IO).launch {
68
+ scope.launch {
63
69
  // Only schedule if no worker is already running/enqueued
64
70
  if (!isWorkerRunning(context)) {
65
71
  scheduleWorker(context, context.packageName)
@@ -75,7 +81,7 @@ object BackgroundTaskScheduler {
75
81
  numberOfRegisteredTasksOfThisType -= 1
76
82
 
77
83
  if (numberOfRegisteredTasksOfThisType == 0) {
78
- CoroutineScope(Dispatchers.IO).launch {
84
+ scope.launch {
79
85
  stopWorker(context)
80
86
  }
81
87
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zykeco/expo-background-task",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Expo Android and iOS module for Background Task APIs",
5
5
  "main": "build/BackgroundTask.js",
6
6
  "types": "build/BackgroundTask.d.ts",
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const config_plugins_1 = require("expo/config-plugins");
4
- const pkg = require('expo-background-task/package.json');
4
+ const pkg = require('@zykeco/expo-background-task/package.json');
5
5
  const withBackgroundTask = (config) => {
6
6
  return (0, config_plugins_1.withInfoPlist)(config, (config) => {
7
7
  // Enable background mode processing
@@ -1,6 +1,6 @@
1
1
  import { ConfigPlugin, createRunOncePlugin, withInfoPlist } from 'expo/config-plugins';
2
2
 
3
- const pkg = require('expo-background-task/package.json');
3
+ const pkg = require('@zykeco/expo-background-task/package.json');
4
4
 
5
5
  const withBackgroundTask: ConfigPlugin = (config) => {
6
6
  return withInfoPlist(config, (config) => {