@octane-xplat/background-tasks 0.18.0 → 0.19.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 +41 -15
- package/package.json +87 -94
- package/src/background-tasks.linux.ts +3 -1
- package/src/background-tasks.macos.ts +78 -10
- package/src/background-tasks.ts +14 -3
- package/src/background-tasks.web.ts +1 -0
- package/src/background-tasks.windows.ts +3 -1
- package/src/types.ts +19 -0
- package/types/generated/background-tasks.d.ts +1 -0
- package/types/generated/background-tasks.linux.d.ts +1 -0
- package/types/generated/background-tasks.macos.d.ts +1 -0
- package/types/generated/background-tasks.web.d.ts +1 -0
- package/types/generated/background-tasks.windows.d.ts +1 -0
- package/types/generated/types.d.ts +19 -0
- package/LICENSE +0 -21
package/README.md
CHANGED
|
@@ -1,26 +1,52 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @octane-xplat/background-tasks
|
|
2
|
+
|
|
3
|
+
Define deferrable work for iOS/Android scheduler experiments. The OS chooses
|
|
4
|
+
when work runs; this is not an exact timer. The current Android cold-start/
|
|
5
|
+
completion bridge and iOS outcome/expiration/recurrence lifecycle have open
|
|
6
|
+
gaps ([#71](https://github.com/octane-xplat/octane-xplat/issues/71),
|
|
7
|
+
[#72](https://github.com/octane-xplat/octane-xplat/issues/72)). Do not treat
|
|
8
|
+
registration as a production delivery guarantee. Web/desktop are unsupported.
|
|
9
|
+
|
|
10
|
+
Follow [Run a background refresh](https://octane-xplat.goddardai.org/background-work)
|
|
11
|
+
for a maintained timestamp job, foreground recovery screen, native configuration,
|
|
12
|
+
launch-time registration, disable and execution checks.
|
|
13
|
+
|
|
14
|
+
## Define a small task
|
|
15
|
+
|
|
16
|
+
Install in an existing Xplat app:
|
|
2
17
|
|
|
3
18
|
```sh
|
|
4
|
-
|
|
19
|
+
bun add @octane-xplat/background-tasks @octane-xplat/platform
|
|
5
20
|
```
|
|
6
21
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
bodies must be declared at module scope because the OS can invoke a task on
|
|
11
|
-
a cold start before app code runs again.
|
|
22
|
+
Define tasks at module scope in a module imported at native startup. Keep their
|
|
23
|
+
results outside mounted screens, and confirm durable writes. This definition
|
|
24
|
+
records an execution attempt; it does not itself schedule or prove OS delivery:
|
|
12
25
|
|
|
13
26
|
```ts
|
|
14
27
|
import { backgroundTasks } from '@octane-xplat/background-tasks'
|
|
28
|
+
import { storage } from '@octane-xplat/platform'
|
|
15
29
|
|
|
16
|
-
backgroundTasks.defineTask('
|
|
17
|
-
|
|
18
|
-
|
|
30
|
+
backgroundTasks.defineTask('record-refresh', async () => {
|
|
31
|
+
try {
|
|
32
|
+
storage.setString('refresh.background-at', new Date().toISOString())
|
|
33
|
+
return storage.flush() ? 'success' : 'failed'
|
|
34
|
+
} catch {
|
|
35
|
+
return 'failed'
|
|
36
|
+
}
|
|
19
37
|
})
|
|
20
|
-
|
|
21
|
-
await backgroundTasks.register('sync-cache', { minimumInterval: 3600 })
|
|
22
38
|
```
|
|
23
39
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
40
|
+
Use the guide's [native configuration](https://octane-xplat.goddardai.org/background-work#configure-the-native-experiment)
|
|
41
|
+
and [startup request](https://octane-xplat.goddardai.org/background-work#request-once-at-startup)
|
|
42
|
+
before scheduling. On iOS, the task requires a permitted full identifier and a
|
|
43
|
+
handler registered once before app launch finishes. Repeated registration can
|
|
44
|
+
terminate the app; do not register from a button or hot-reloaded component.
|
|
45
|
+
Android carries a WorkManager bridge with a 15-minute interval floor, but its
|
|
46
|
+
current worker does not bootstrap a dead JS runtime.
|
|
47
|
+
|
|
48
|
+
Keep the [foreground fallback](https://octane-xplat.goddardai.org/background-work#disable-retry-and-fall-back).
|
|
49
|
+
The interval is in seconds and is a scheduling hint. `isRegistered` only checks
|
|
50
|
+
the current JS map, not the OS queue. Qualify a persisted execution timestamp,
|
|
51
|
+
actual task outcome and subsequent delivery using the guide's
|
|
52
|
+
[device procedure](https://octane-xplat.goddardai.org/background-work#prove-execution-separately).
|
package/package.json
CHANGED
|
@@ -1,95 +1,88 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
},
|
|
90
|
-
"scripts": {
|
|
91
|
-
"typegen": "tsrx-typegen --target octane",
|
|
92
|
-
"pack:check": "tsrx-typegen --pack-check",
|
|
93
|
-
"typecheck": "node ../../scripts/typecheck.ts"
|
|
94
|
-
}
|
|
95
|
-
}
|
|
2
|
+
"name": "@octane-xplat/background-tasks",
|
|
3
|
+
"version": "0.19.0",
|
|
4
|
+
"description": "OS-scheduled periodic background work for Octane xplat — BGTaskScheduler and WorkManager",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"android",
|
|
7
|
+
"cross-platform",
|
|
8
|
+
"nativescript",
|
|
9
|
+
"octane",
|
|
10
|
+
"xplat",
|
|
11
|
+
"background-tasks",
|
|
12
|
+
"background-fetch",
|
|
13
|
+
"workmanager"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://github.com/octane-xplat/octane-xplat/tree/main/packages/background-tasks",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/octane-xplat/octane-xplat",
|
|
20
|
+
"directory": "packages/background-tasks"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"src",
|
|
24
|
+
"platforms",
|
|
25
|
+
"types",
|
|
26
|
+
"!src/**/*.test.*",
|
|
27
|
+
"!src/**/*.spec.*"
|
|
28
|
+
],
|
|
29
|
+
"type": "module",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./types/generated/index.d.ts",
|
|
33
|
+
"macos": "./src/index.macos.ts",
|
|
34
|
+
"web": "./src/index.web.ts",
|
|
35
|
+
"native": "./src/index.ts",
|
|
36
|
+
"default": "./src/index.ts"
|
|
37
|
+
},
|
|
38
|
+
"./*": {
|
|
39
|
+
"types": "./types/generated/*.d.ts",
|
|
40
|
+
"default": "./src/*"
|
|
41
|
+
},
|
|
42
|
+
"./*.ts": {
|
|
43
|
+
"types": "./types/generated/*.d.ts",
|
|
44
|
+
"default": "./src/*.ts"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"test": "node --test tests/*.test.ts",
|
|
52
|
+
"typegen": "tsrx-typegen --target octane",
|
|
53
|
+
"prepack": "bun run typegen && tsrx-typegen --pack-check",
|
|
54
|
+
"pack:check": "tsrx-typegen --pack-check",
|
|
55
|
+
"typecheck": "node ../../scripts/typecheck.ts"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@nativescript-community/octane": "0.2.5",
|
|
59
|
+
"@nativescript/core": "9.1.3",
|
|
60
|
+
"@nativescript/types": "9.1.4",
|
|
61
|
+
"@tsrx/typescript-plugin": "0.4.11",
|
|
62
|
+
"octane": "0.16.3",
|
|
63
|
+
"tsrx-typegen": "0.5.0",
|
|
64
|
+
"typescript": "5.9.3"
|
|
65
|
+
},
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"@nativescript-community/octane": ">=0.2.1 <1",
|
|
68
|
+
"@nativescript/core": ">=9.1.0 <10",
|
|
69
|
+
"octane": ">=0.6.3 <1"
|
|
70
|
+
},
|
|
71
|
+
"peerDependenciesMeta": {
|
|
72
|
+
"@nativescript-community/octane": {
|
|
73
|
+
"optional": true
|
|
74
|
+
},
|
|
75
|
+
"@nativescript/core": {
|
|
76
|
+
"optional": true
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"nativescript": {
|
|
80
|
+
"platforms": {
|
|
81
|
+
"android": "9.1.0",
|
|
82
|
+
"ios": "9.1.0"
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
"dependencies": {
|
|
86
|
+
"@octane-xplat/platform": "0.19.0"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
// on macOS) are follow-ups; the API surface stands.
|
|
3
3
|
import type { BackgroundTasks, TaskStatus } from './types'
|
|
4
4
|
|
|
5
|
-
const unsupported = () =>
|
|
5
|
+
const unsupported = () =>
|
|
6
|
+
Promise.reject(new Error('unsupported: background tasks are not wired on this platform'))
|
|
6
7
|
|
|
8
|
+
/** Background-task scheduler service — see BackgroundTasks for the contract. */
|
|
7
9
|
export const backgroundTasks: BackgroundTasks = {
|
|
8
10
|
supported: false,
|
|
9
11
|
defineTask: () => {},
|
|
@@ -1,14 +1,82 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
|
|
1
|
+
// Background tasks — AppKit leaf over NSBackgroundActivityScheduler. The
|
|
2
|
+
// scheduler is deferrable maintenance work: `interval` is a request the OS
|
|
3
|
+
// may stretch, the app must be running (no launch-on-event), and a deferred
|
|
4
|
+
// fire surfaces TaskResult through the executor's completion.
|
|
5
|
+
import { NSBackgroundActivityScheduler } from '@octane-xplat/platform/macos'
|
|
6
|
+
import type { BackgroundTasks, TaskExecutor, TaskResult, TaskStatus } from './types'
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
// NSBackgroundActivityResult: 1 deferred, 2 finished.
|
|
9
|
+
const RESULT_FINISHED = 2
|
|
10
|
+
const RESULT_DEFERRED = 1
|
|
6
11
|
|
|
12
|
+
const executors = new Map<string, TaskExecutor>()
|
|
13
|
+
const schedulers = new Map<string, any>()
|
|
14
|
+
|
|
15
|
+
const schedulerClass = (): any => {
|
|
16
|
+
try {
|
|
17
|
+
return typeof NSBackgroundActivityScheduler?.alloc === 'function'
|
|
18
|
+
? NSBackgroundActivityScheduler
|
|
19
|
+
: null
|
|
20
|
+
} catch {
|
|
21
|
+
return null
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Background-task scheduler service — see BackgroundTasks for the contract. */
|
|
7
26
|
export const backgroundTasks: BackgroundTasks = {
|
|
8
|
-
supported
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
27
|
+
get supported() {
|
|
28
|
+
return schedulerClass() !== null
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
defineTask(name: string, executor: TaskExecutor): void {
|
|
32
|
+
executors.set(name, executor)
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
register: async (name: string, options?: { minimumInterval?: number }): Promise<void> => {
|
|
36
|
+
if (!executors.has(name)) {
|
|
37
|
+
throw new Error(`backgroundTasks.register: no task defined as '${name}'`)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const klass = schedulerClass()
|
|
41
|
+
if (!klass) {
|
|
42
|
+
throw new Error('backgroundTasks.register: NSBackgroundActivityScheduler is unavailable')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
backgroundTasks.unregister(name).catch(() => {})
|
|
46
|
+
const scheduler = klass.alloc().initWithIdentifier(`xplat.background.${name}`)
|
|
47
|
+
scheduler.repeats = true
|
|
48
|
+
scheduler.interval = Math.max(options?.minimumInterval ?? 3600, 60)
|
|
49
|
+
scheduler.tolerance = scheduler.interval / 2
|
|
50
|
+
scheduler.qualityOfService = 0x09 // NSQualityOfServiceBackground
|
|
51
|
+
scheduler.scheduleWithBlock((completion: (result: number) => void) => {
|
|
52
|
+
const executor = executors.get(name)
|
|
53
|
+
if (scheduler.shouldDefer || !executor) {
|
|
54
|
+
completion(RESULT_DEFERRED)
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
Promise.resolve()
|
|
59
|
+
.then(() => executor({ name }))
|
|
60
|
+
.then((result: TaskResult) => completion(result === 'success' ? RESULT_FINISHED : RESULT_DEFERRED))
|
|
61
|
+
.catch(() => completion(RESULT_DEFERRED))
|
|
62
|
+
})
|
|
63
|
+
schedulers.set(name, scheduler)
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
unregister: async (name: string): Promise<void> => {
|
|
67
|
+
const scheduler = schedulers.get(name)
|
|
68
|
+
if (scheduler) {
|
|
69
|
+
schedulers.delete(name)
|
|
70
|
+
try {
|
|
71
|
+
scheduler.invalidate()
|
|
72
|
+
} catch {
|
|
73
|
+
// Invalidating a released scheduler must not poison unregister.
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
getStatus: async (): Promise<TaskStatus> =>
|
|
79
|
+
schedulerClass() ? 'available' : 'unavailable',
|
|
80
|
+
|
|
81
|
+
isRegistered: async (name: string): Promise<boolean> => schedulers.has(name),
|
|
14
82
|
}
|
package/src/background-tasks.ts
CHANGED
|
@@ -34,7 +34,9 @@ async function runTask(name: string): Promise<TaskResult> {
|
|
|
34
34
|
// a background thread; we resolve via the JS executor then mark completion.
|
|
35
35
|
function iosHandle(task: any): void {
|
|
36
36
|
const identifier: string = task?.identifier ?? ''
|
|
37
|
-
const name = identifier.startsWith(TASK_PREFIX)
|
|
37
|
+
const name = identifier.startsWith(TASK_PREFIX)
|
|
38
|
+
? identifier.slice(TASK_PREFIX.length)
|
|
39
|
+
: identifier
|
|
38
40
|
task.expirationHandler = () => {}
|
|
39
41
|
runTask(name).finally(() => {
|
|
40
42
|
try {
|
|
@@ -43,6 +45,7 @@ function iosHandle(task: any): void {
|
|
|
43
45
|
})
|
|
44
46
|
}
|
|
45
47
|
|
|
48
|
+
/** Background-task scheduler service — see BackgroundTasks for the contract. */
|
|
46
49
|
export const backgroundTasks: BackgroundTasks = {
|
|
47
50
|
supported: isIOS ? typeof BGTaskScheduler !== 'undefined' : true,
|
|
48
51
|
|
|
@@ -52,24 +55,31 @@ export const backgroundTasks: BackgroundTasks = {
|
|
|
52
55
|
|
|
53
56
|
async register(name: string, options?: { minimumInterval?: number }): Promise<void> {
|
|
54
57
|
if (!executors.has(name)) {
|
|
55
|
-
throw new Error(
|
|
58
|
+
throw new Error(
|
|
59
|
+
`backgroundTasks.register: '${name}' has no defineTask — declare it at module scope`,
|
|
60
|
+
)
|
|
56
61
|
}
|
|
57
62
|
registered.set(name, options?.minimumInterval ?? 0)
|
|
58
63
|
if (isIOS) {
|
|
59
64
|
if (typeof BGTaskScheduler === 'undefined') {
|
|
60
65
|
throw new Error('unsupported: BGTaskScheduler is not available')
|
|
61
66
|
}
|
|
67
|
+
|
|
62
68
|
const identifier = TASK_PREFIX + name
|
|
63
69
|
BGTaskScheduler.sharedScheduler.registerForTaskWithIdentifierLaunchHandler(
|
|
64
70
|
identifier,
|
|
65
71
|
null,
|
|
66
72
|
iosHandle,
|
|
67
73
|
)
|
|
74
|
+
|
|
68
75
|
const request = BGAppRefreshTaskRequest.alloc().initWithIdentifier(identifier)
|
|
69
76
|
const interval = options?.minimumInterval
|
|
70
77
|
if (interval) {
|
|
71
|
-
request.earliestBeginDate = (globalThis as any).NSDate.dateWithTimeIntervalSinceNow(
|
|
78
|
+
request.earliestBeginDate = (globalThis as any).NSDate.dateWithTimeIntervalSinceNow(
|
|
79
|
+
interval,
|
|
80
|
+
)
|
|
72
81
|
}
|
|
82
|
+
|
|
73
83
|
BGTaskScheduler.sharedScheduler.submitTaskRequestError(request, null)
|
|
74
84
|
return
|
|
75
85
|
}
|
|
@@ -96,6 +106,7 @@ export const backgroundTasks: BackgroundTasks = {
|
|
|
96
106
|
if (typeof BGTaskScheduler === 'undefined') {
|
|
97
107
|
return 'unavailable'
|
|
98
108
|
}
|
|
109
|
+
|
|
99
110
|
const status = (globalThis as any).UIApplication?.sharedApplication?.backgroundRefreshStatus
|
|
100
111
|
// UIBackgroundRefreshStatus: 0 restricted, 1 denied, 2 available
|
|
101
112
|
return status === 0 || status === 1 ? 'restricted' : 'available'
|
|
@@ -4,6 +4,7 @@ import type { BackgroundTasks, TaskStatus } from './types'
|
|
|
4
4
|
|
|
5
5
|
const unsupported = () => Promise.reject(new Error('unsupported: no background task API on web'))
|
|
6
6
|
|
|
7
|
+
/** Background-task scheduler service — see BackgroundTasks for the contract. */
|
|
7
8
|
export const backgroundTasks: BackgroundTasks = {
|
|
8
9
|
supported: false,
|
|
9
10
|
defineTask: () => {},
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
// on macOS) are follow-ups; the API surface stands.
|
|
3
3
|
import type { BackgroundTasks, TaskStatus } from './types'
|
|
4
4
|
|
|
5
|
-
const unsupported = () =>
|
|
5
|
+
const unsupported = () =>
|
|
6
|
+
Promise.reject(new Error('unsupported: background tasks are not wired on this platform'))
|
|
6
7
|
|
|
8
|
+
/** Background-task scheduler service — see BackgroundTasks for the contract. */
|
|
7
9
|
export const backgroundTasks: BackgroundTasks = {
|
|
8
10
|
supported: false,
|
|
9
11
|
defineTask: () => {},
|
package/src/types.ts
CHANGED
|
@@ -1,22 +1,41 @@
|
|
|
1
|
+
/** Reported outcome of a task run — the OS uses it for scheduling heuristics
|
|
2
|
+
* (repeated 'failed' runs get deferred on both stores). */
|
|
1
3
|
export type TaskResult = 'success' | 'failed'
|
|
2
4
|
|
|
5
|
+
/** Invocation payload handed to a TaskExecutor. */
|
|
3
6
|
export interface TaskContext {
|
|
7
|
+
/** The registered task name — one executor may serve several names. */
|
|
4
8
|
name: string
|
|
5
9
|
}
|
|
6
10
|
|
|
11
|
+
/** The task body; resolves 'success' | 'failed' for OS scheduling feedback. */
|
|
7
12
|
export type TaskExecutor = (context: TaskContext) => Promise<TaskResult>
|
|
8
13
|
|
|
14
|
+
/** OS willingness to run background tasks — 'restricted' means the user or
|
|
15
|
+
* a battery/data saver mode has throttled them; 'unavailable' means the
|
|
16
|
+
* platform has no background-task path at all. */
|
|
9
17
|
export type TaskStatus = 'available' | 'restricted' | 'unavailable'
|
|
10
18
|
|
|
19
|
+
/** Background-task façade. Tasks are defined at module scope, then
|
|
20
|
+
* registered/unregistered against the OS scheduler (iOS BGTaskScheduler /
|
|
21
|
+
* Android WorkManager-style periodic work). Intervals are minimums — the OS
|
|
22
|
+
* decides actual timing. */
|
|
11
23
|
export interface BackgroundTasks {
|
|
24
|
+
/** Synchronous fast check — a background-task scheduler exists. */
|
|
12
25
|
readonly supported: boolean
|
|
13
26
|
/** Define a task at module scope — the OS may invoke the name before any
|
|
14
27
|
* other call, so registration must be load-time (expo-task-manager's
|
|
15
28
|
* structural constraint, mirrored deliberately). */
|
|
16
29
|
defineTask(name: string, executor: TaskExecutor): void
|
|
30
|
+
/** Schedule a defined task. `minimumInterval` is a hint in scheduler units
|
|
31
|
+
* (seconds on iOS via earliestBeginDate) — the OS decides actual timing
|
|
32
|
+
* and may defer well past it. */
|
|
17
33
|
register(name: string, options?: { minimumInterval?: number }): Promise<void>
|
|
34
|
+
/** Cancel a previously registered task; no-op when not registered. */
|
|
18
35
|
unregister(name: string): Promise<void>
|
|
36
|
+
/** Current OS scheduling posture for this app. */
|
|
19
37
|
getStatus(): Promise<TaskStatus>
|
|
38
|
+
/** Whether `name` is currently scheduled with the OS. */
|
|
20
39
|
isRegistered(name: string): Promise<boolean>
|
|
21
40
|
}
|
|
22
41
|
|
|
@@ -1,20 +1,39 @@
|
|
|
1
|
+
/** Reported outcome of a task run — the OS uses it for scheduling heuristics
|
|
2
|
+
* (repeated 'failed' runs get deferred on both stores). */
|
|
1
3
|
export type TaskResult = 'success' | 'failed';
|
|
4
|
+
/** Invocation payload handed to a TaskExecutor. */
|
|
2
5
|
export interface TaskContext {
|
|
6
|
+
/** The registered task name — one executor may serve several names. */
|
|
3
7
|
name: string;
|
|
4
8
|
}
|
|
9
|
+
/** The task body; resolves 'success' | 'failed' for OS scheduling feedback. */
|
|
5
10
|
export type TaskExecutor = (context: TaskContext) => Promise<TaskResult>;
|
|
11
|
+
/** OS willingness to run background tasks — 'restricted' means the user or
|
|
12
|
+
* a battery/data saver mode has throttled them; 'unavailable' means the
|
|
13
|
+
* platform has no background-task path at all. */
|
|
6
14
|
export type TaskStatus = 'available' | 'restricted' | 'unavailable';
|
|
15
|
+
/** Background-task façade. Tasks are defined at module scope, then
|
|
16
|
+
* registered/unregistered against the OS scheduler (iOS BGTaskScheduler /
|
|
17
|
+
* Android WorkManager-style periodic work). Intervals are minimums — the OS
|
|
18
|
+
* decides actual timing. */
|
|
7
19
|
export interface BackgroundTasks {
|
|
20
|
+
/** Synchronous fast check — a background-task scheduler exists. */
|
|
8
21
|
readonly supported: boolean;
|
|
9
22
|
/** Define a task at module scope — the OS may invoke the name before any
|
|
10
23
|
* other call, so registration must be load-time (expo-task-manager's
|
|
11
24
|
* structural constraint, mirrored deliberately). */
|
|
12
25
|
defineTask(name: string, executor: TaskExecutor): void;
|
|
26
|
+
/** Schedule a defined task. `minimumInterval` is a hint in scheduler units
|
|
27
|
+
* (seconds on iOS via earliestBeginDate) — the OS decides actual timing
|
|
28
|
+
* and may defer well past it. */
|
|
13
29
|
register(name: string, options?: {
|
|
14
30
|
minimumInterval?: number;
|
|
15
31
|
}): Promise<void>;
|
|
32
|
+
/** Cancel a previously registered task; no-op when not registered. */
|
|
16
33
|
unregister(name: string): Promise<void>;
|
|
34
|
+
/** Current OS scheduling posture for this app. */
|
|
17
35
|
getStatus(): Promise<TaskStatus>;
|
|
36
|
+
/** Whether `name` is currently scheduled with the OS. */
|
|
18
37
|
isRegistered(name: string): Promise<boolean>;
|
|
19
38
|
}
|
|
20
39
|
export declare const backgroundTasks: BackgroundTasks;
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Alec Larson
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
THE SOFTWARE.
|