@symbiote-native/background-fetch 0.1.1 → 0.1.3
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 +43 -27
- package/package.json +16 -16
package/README.md
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
# @symbiote-native/background-fetch
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[
|
|
5
|
-
|
|
6
|
-
[
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
Refresh data on a rough schedule while the app is not open. One API for every
|
|
4
|
+
[SymbioteNative](../../README.md) adapter (React, Vue, Svelte, Solid and Angular).
|
|
5
|
+
|
|
6
|
+
It wraps [`expo-background-fetch`](https://github.com/expo/expo/tree/main/packages/expo-background-fetch).
|
|
7
|
+
Like [`@symbiote-native/task-manager`](../task-manager), every export is a plain async function, so
|
|
8
|
+
there is no hook, composable or service to wrap: every adapter entry point is a plain re-export of
|
|
9
|
+
the same `core`.
|
|
10
|
+
|
|
11
|
+
**Upstream deprecated this API in favor of `expo-background-task`** - Apple and Google are both
|
|
11
12
|
moving away from periodic-fetch-style scheduling toward task-scheduling APIs
|
|
12
13
|
(`BGTaskScheduler` / `WorkManager`). It is ported here anyway, alongside
|
|
13
14
|
[`@symbiote-native/background-task`](../background-task), because Expo still ships both
|
|
14
15
|
simultaneously as of sdk-57 and an app already built against the old API needs a path to run on
|
|
15
16
|
SymbioteNative too. Prefer `@symbiote-native/background-task` for new code.
|
|
16
17
|
|
|
17
|
-
This package registers a task with native so it fires **periodically in the background**
|
|
18
|
+
This package registers a task with native so it fires **periodically in the background** - it
|
|
18
19
|
does not define what the task does. Define the task first via
|
|
19
20
|
[`@symbiote-native/task-manager`](../task-manager)'s `defineTask`, then register it for periodic
|
|
20
21
|
execution via this package's `registerTaskAsync`.
|
|
@@ -34,29 +35,29 @@ npx @symbiote-native/cli add --background-fetch
|
|
|
34
35
|
```
|
|
35
36
|
|
|
36
37
|
Either way: installs `@symbiote-native/background-fetch` + `@symbiote-native/task-manager` and
|
|
37
|
-
wires the native autolinking automatically
|
|
38
|
+
wires the native autolinking automatically - see [`@symbiote-native/cli`](../cli).
|
|
38
39
|
|
|
39
40
|
<details>
|
|
40
|
-
<summary>Manual install (no CLI
|
|
41
|
+
<summary>Manual install (no CLI - installing and wiring native autolinking by hand)</summary>
|
|
41
42
|
|
|
42
43
|
```bash
|
|
43
44
|
npm install @symbiote-native/background-fetch @symbiote-native/task-manager
|
|
44
45
|
```
|
|
45
46
|
|
|
46
47
|
`expo-background-fetch` and `expo-modules-core` come along as regular dependencies, pinned to
|
|
47
|
-
exact versions
|
|
48
|
+
exact versions - never install them yourself, and never add the `expo` meta-package to your
|
|
48
49
|
project.
|
|
49
50
|
|
|
50
51
|
## Required one-time step: native autolinking wiring
|
|
51
52
|
|
|
52
|
-
Same one-time step as every other `expo-modules-core` package this project ships
|
|
53
|
+
Same one-time step as every other `expo-modules-core` package this project ships - see
|
|
53
54
|
[`@symbiote-native/local-auth`'s README](../local-auth/README.md#required-one-time-step-native-autolinking-wiring)
|
|
54
55
|
and the `symbiote-expo-native-module` project skill.
|
|
55
56
|
|
|
56
|
-
iOS also needs `UIBackgroundModes: fetch` in the app's Info.plist
|
|
57
|
+
iOS also needs `UIBackgroundModes: fetch` in the app's Info.plist -
|
|
57
58
|
`native-link.json`'s `ios.infoPlistArrayKeys` covers this ARRAY-valued case (see
|
|
58
59
|
`@symbiote-native/expo-modules-link`), so it's wired automatically by the same postinstall step,
|
|
59
|
-
no manual edit needed. Android needs no manual step
|
|
60
|
+
no manual edit needed. Android needs no manual step - `RECEIVE_BOOT_COMPLETED` and `WAKE_LOCK`
|
|
60
61
|
ship in `expo-background-fetch`'s own `AndroidManifest.xml` and merge automatically once the
|
|
61
62
|
package is installed.
|
|
62
63
|
|
|
@@ -69,7 +70,7 @@ src/core/ getStatusAsync / setMinimumIntervalAsync / registerTaskAsync / unr
|
|
|
69
70
|
plus BackgroundFetchResult / BackgroundFetchStatus / IBackgroundFetchOptions.
|
|
70
71
|
native-module.ts resolves the native module via expo-modules-core's
|
|
71
72
|
requireNativeModule.
|
|
72
|
-
src/angular/ @symbiote-native/background-fetch/angular
|
|
73
|
+
src/angular/ @symbiote-native/background-fetch/angular - export * from '../core'
|
|
73
74
|
```
|
|
74
75
|
|
|
75
76
|
`./react`, `./vue`, `./svelte`, and `./solid` are `exports`-map aliases straight onto
|
|
@@ -79,7 +80,7 @@ src/angular/ @symbiote-native/background-fetch/angular — export * from '../co
|
|
|
79
80
|
## Use it
|
|
80
81
|
|
|
81
82
|
```ts
|
|
82
|
-
// index.ts, alongside AppRegistry.registerComponent
|
|
83
|
+
// index.ts, alongside AppRegistry.registerComponent - identical on every adapter
|
|
83
84
|
import { defineTask } from '@symbiote-native/task-manager';
|
|
84
85
|
import {
|
|
85
86
|
registerTaskAsync,
|
|
@@ -104,7 +105,7 @@ await registerTaskAsync(SYNC_TASK, { minimumInterval: 900 });
|
|
|
104
105
|
```
|
|
105
106
|
|
|
106
107
|
`@symbiote-native/task-manager` is the primitive both this package and
|
|
107
|
-
[`@symbiote-native/background-task`](../background-task) build on
|
|
108
|
+
[`@symbiote-native/background-task`](../background-task) build on - `defineTask` lives there,
|
|
108
109
|
`registerTaskAsync`/`unregisterTaskAsync` live here. `defineTask` must run at the top of the JS
|
|
109
110
|
bundle, outside any component, for the same reason documented in task-manager's own README: the
|
|
110
111
|
app can be launched headlessly to run a background task, with no views mounted.
|
|
@@ -119,7 +120,7 @@ const status = await getStatusAsync();
|
|
|
119
120
|
await unregisterTaskAsync(SYNC_TASK); // stop receiving background-fetch callbacks for it
|
|
120
121
|
```
|
|
121
122
|
|
|
122
|
-
Identical import surface on every adapter
|
|
123
|
+
Identical import surface on every adapter - `@symbiote-native/background-fetch/react`,
|
|
123
124
|
`/vue`, `/svelte`, `/solid`, `/angular` all re-export the same functions.
|
|
124
125
|
|
|
125
126
|
## API
|
|
@@ -131,31 +132,46 @@ registerTaskAsync(taskName: string, options?: IBackgroundFetchOptions): Promise<
|
|
|
131
132
|
unregisterTaskAsync(taskName: string): Promise<void>
|
|
132
133
|
```
|
|
133
134
|
|
|
134
|
-
Plus `BackgroundFetchResult`, `BackgroundFetchStatus`, `IBackgroundFetchOptions`
|
|
135
|
+
Plus `BackgroundFetchResult`, `BackgroundFetchStatus`, `IBackgroundFetchOptions` - ported from
|
|
135
136
|
upstream's `BackgroundFetch.types.ts`, the options type renamed with this repo's `I`-prefix
|
|
136
137
|
convention for exported types (`ts-js-best-practices`).
|
|
137
138
|
|
|
138
139
|
## Notes
|
|
139
140
|
|
|
140
|
-
- **Every function warns once, on first call, that this API is deprecated**
|
|
141
|
+
- **Every function warns once, on first call, that this API is deprecated** - matching upstream's
|
|
141
142
|
own `showDeprecationWarning`. It still works; the warning is a nudge toward
|
|
142
143
|
`@symbiote-native/background-task`, not a functional restriction.
|
|
143
144
|
- **`registerTaskAsync` requires the task to already be defined.** It throws if
|
|
144
|
-
`@symbiote-native/task-manager`'s `isTaskDefined(taskName)` is `false`
|
|
145
|
+
`@symbiote-native/task-manager`'s `isTaskDefined(taskName)` is `false` - call `defineTask`
|
|
145
146
|
first.
|
|
146
|
-
- **`getStatusAsync` shortcuts to `Available` on Android without calling native at all**
|
|
147
|
+
- **`getStatusAsync` shortcuts to `Available` on Android without calling native at all** -
|
|
147
148
|
matches upstream, which has no Android-side status concept (the native call exists only on
|
|
148
149
|
iOS).
|
|
149
150
|
- **`setMinimumIntervalAsync` silently no-ops when native lacks the method** (Android has no
|
|
150
|
-
equivalent call) rather than throwing
|
|
151
|
+
equivalent call) rather than throwing - matches upstream.
|
|
151
152
|
- **Expo Go is out of scope.** Upstream also warns when running inside Expo Go
|
|
152
153
|
(`isRunningInExpoGo`, imported from the `expo` meta-package). This project never installs
|
|
153
|
-
`expo`
|
|
154
|
+
`expo` - every app here is a bare/dev-client build, never Expo Go - so that check has no
|
|
154
155
|
equivalent here and is intentionally not ported.
|
|
155
156
|
|
|
157
|
+
## Common questions
|
|
158
|
+
|
|
159
|
+
- **The task never fires.** `minimumInterval` is a hint: iOS decides from usage patterns. Check
|
|
160
|
+
`defineTask` runs at module scope and before `registerTaskAsync`.
|
|
161
|
+
- **Rejected on Android in release builds.** Reported upstream for release only; test a release build.
|
|
162
|
+
- **Survive a killed app.** Android: `stopOnTerminate: false` and `startOnBoot: true`. iOS stops on
|
|
163
|
+
force-quit.
|
|
164
|
+
- **Return value.** iOS: `BackgroundFetchResult.NewData` / `NoData` / `Failed`; Android ignores it.
|
|
165
|
+
- **New code?** Use `@symbiote-native/background-task`.
|
|
166
|
+
|
|
167
|
+
Sources: [Expo docs: BackgroundFetch](https://docs.expo.dev/versions/latest/sdk/background-fetch/),
|
|
168
|
+
[expo/expo#35551](https://github.com/expo/expo/issues/35551),
|
|
169
|
+
[expo/expo#33596](https://github.com/expo/expo/issues/33596),
|
|
170
|
+
[expo/expo#36492](https://github.com/expo/expo/issues/36492).
|
|
171
|
+
|
|
156
172
|
## Test it
|
|
157
173
|
|
|
158
|
-
No Fabric/Descriptor angle at all
|
|
174
|
+
No Fabric/Descriptor angle at all - every function here is a pure async-function surface, never a
|
|
159
175
|
view or per-instance state. Tests inject a fake native-module object in place of the real
|
|
160
176
|
`requireNativeModule` resolution and a fake `@symbiote-native/task-manager` module
|
|
161
|
-
(`src/core/background-fetch.test.ts`)
|
|
177
|
+
(`src/core/background-fetch.test.ts`) - no `installFabric()`, no ViewConfig.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbiote-native/background-fetch",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "expo-background-fetch wrapped for SymbioteNative — one framework-agnostic core, built once and reachable from the React, Vue, Svelte, Solid, and Angular adapters. Periodic background fetch, registered through @symbiote-native/task-manager. Deprecated upstream in favor of expo-background-task; ported for parity with what Expo still ships.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -70,8 +70,8 @@
|
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
72
|
"expo-background-fetch": "57.0.15",
|
|
73
|
-
"expo-modules-core": "57.0.
|
|
74
|
-
"@symbiote-native/task-manager": "0.1.
|
|
73
|
+
"expo-modules-core": "57.0.20",
|
|
74
|
+
"@symbiote-native/task-manager": "0.1.3"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
77
|
"@angular/core": ">=20",
|
|
@@ -81,12 +81,12 @@
|
|
|
81
81
|
"solid-js": ">=1.9.0",
|
|
82
82
|
"svelte": ">=5.56.0",
|
|
83
83
|
"vue": ">=3.5.0",
|
|
84
|
-
"@symbiote-native/angular": "^3.
|
|
85
|
-
"@symbiote-native/engine": "^1.
|
|
86
|
-
"@symbiote-native/react": "^3.0
|
|
87
|
-
"@symbiote-native/solid": "^3.0
|
|
88
|
-
"@symbiote-native/svelte": "^3.0
|
|
89
|
-
"@symbiote-native/vue": "^3.0
|
|
84
|
+
"@symbiote-native/angular": "^3.2.0",
|
|
85
|
+
"@symbiote-native/engine": "^1.5.0",
|
|
86
|
+
"@symbiote-native/react": "^3.2.0",
|
|
87
|
+
"@symbiote-native/solid": "^3.1.0",
|
|
88
|
+
"@symbiote-native/svelte": "^3.1.0",
|
|
89
|
+
"@symbiote-native/vue": "^3.2.0"
|
|
90
90
|
},
|
|
91
91
|
"peerDependenciesMeta": {
|
|
92
92
|
"@symbiote-native/angular": {
|
|
@@ -134,13 +134,13 @@
|
|
|
134
134
|
"solid-js": "^1.9.14",
|
|
135
135
|
"svelte": "^5.56.0",
|
|
136
136
|
"typescript": "~6.0.0",
|
|
137
|
-
"@symbiote-native/angular": "3.
|
|
138
|
-
"@symbiote-native/engine": "1.
|
|
139
|
-
"@symbiote-native/react": "3.0
|
|
140
|
-
"@symbiote-native/solid": "3.0
|
|
141
|
-
"@symbiote-native/svelte": "3.0
|
|
142
|
-
"@symbiote-native/test-utils": "0.4.
|
|
143
|
-
"@symbiote-native/vue": "3.0
|
|
137
|
+
"@symbiote-native/angular": "3.2.0",
|
|
138
|
+
"@symbiote-native/engine": "1.5.0",
|
|
139
|
+
"@symbiote-native/react": "3.2.0",
|
|
140
|
+
"@symbiote-native/solid": "3.1.0",
|
|
141
|
+
"@symbiote-native/svelte": "3.1.0",
|
|
142
|
+
"@symbiote-native/test-utils": "0.4.6",
|
|
143
|
+
"@symbiote-native/vue": "3.2.0"
|
|
144
144
|
},
|
|
145
145
|
"scripts": {
|
|
146
146
|
"typecheck": "tsc --build",
|