create-expo-updates-server 0.2.1 → 0.3.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/dist/template/docs/expo-app-setup.md +8 -12
- package/dist/template/docs/getting-started.md +5 -5
- package/dist/template/docs/getting-started.ru.md +5 -5
- package/dist/template/docs/ota-client-lifecycle.md +46 -42
- package/dist/template/package-lock.json +589 -0
- package/dist/template/package.json +1 -0
- package/dist/template/scripts/lib/device-identity.test.ts +2 -2
- package/dist/template/scripts/lib/doctor.mjs +3 -3
- package/dist/template/scripts/lib/doctor.test.mjs +1 -1
- package/dist/template/scripts/lib/ota-client-configurator.mjs +116 -34
- package/dist/template/scripts/lib/ota-client-configurator.test.ts +210 -61
- package/dist/template/scripts/lib/ota-client.test.ts +1 -1
- package/dist/template/scripts/lib/ota-root-hook-patcher.mjs +435 -118
- package/dist/template/scripts/lib/ota-root-hook-patcher.test.ts +243 -86
- package/dist/template/scripts/lib/ota-update-controller.test.ts +10 -9
- package/dist/template/scripts/lib/ota-updates-ui.test.tsx +154 -0
- package/dist/template/scripts/tests/fixtures/react-native-ui.tsx +34 -0
- package/dist/template/scripts/tests/ota-client-types.mjs +69 -0
- package/dist/template/templates/expo-app/ota-client/README.md +16 -2
- package/dist/template/templates/expo-app/ota-client/controller.ts +107 -0
- package/dist/template/templates/expo-app/ota-client/device-identity.ts +48 -0
- package/dist/template/templates/expo-app/ota-client/docs/update-lifecycle.md +18 -9
- package/dist/template/templates/expo-app/ota-client/index.ts +16 -0
- package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.ts +97 -0
- package/dist/template/templates/expo-app/ota-client/model/update-controller.ts +293 -0
- package/dist/template/templates/expo-app/ota-client/runtime.ts +153 -0
- package/dist/template/templates/expo-app/ota-client/types.ts +85 -0
- package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.tsx +25 -0
- package/dist/template/templates/expo-app/ota-client/ui/ota-updates.tsx +196 -0
- package/dist/template/tsconfig.json +3 -1
- package/dist/template/vitest.config.mts +3 -0
- package/dist/template-manifest.json +85 -65
- package/package.json +1 -1
- package/dist/template/templates/expo-app/ota-client/controller.js +0 -60
- package/dist/template/templates/expo-app/ota-client/device-identity.js +0 -26
- package/dist/template/templates/expo-app/ota-client/index.d.ts +0 -47
- package/dist/template/templates/expo-app/ota-client/index.js +0 -3
- package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.js +0 -48
- package/dist/template/templates/expo-app/ota-client/model/update-controller.js +0 -182
- package/dist/template/templates/expo-app/ota-client/runtime.js +0 -112
- package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.js +0 -56
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { cp, mkdtemp, writeFile, symlink, rm } from "node:fs/promises";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
|
|
8
|
+
// Check the generated source against the target application's actual Expo/RN types.
|
|
9
|
+
const app = process.argv[2];
|
|
10
|
+
if (!app)
|
|
11
|
+
throw new Error(
|
|
12
|
+
"Usage: node scripts/tests/ota-client-types.mjs /path/to/expo-app",
|
|
13
|
+
);
|
|
14
|
+
const require = createRequire(path.resolve(app, "package.json"));
|
|
15
|
+
const temp = await mkdtemp(path.join(os.tmpdir(), "ota-client-types-"));
|
|
16
|
+
try {
|
|
17
|
+
const template = fileURLToPath(
|
|
18
|
+
new URL("../../templates/expo-app/ota-client", import.meta.url),
|
|
19
|
+
);
|
|
20
|
+
await cp(template, path.join(temp, "ota-client"), { recursive: true });
|
|
21
|
+
await symlink(
|
|
22
|
+
path.resolve(app, "node_modules"),
|
|
23
|
+
path.join(temp, "node_modules"),
|
|
24
|
+
"dir",
|
|
25
|
+
);
|
|
26
|
+
await writeFile(
|
|
27
|
+
path.join(temp, "ota-client/config.json"),
|
|
28
|
+
JSON.stringify({
|
|
29
|
+
channel: "test",
|
|
30
|
+
identityNamespace: "test",
|
|
31
|
+
heartbeatUrl: "https://example.org/api/device-heartbeat",
|
|
32
|
+
}),
|
|
33
|
+
);
|
|
34
|
+
await writeFile(
|
|
35
|
+
path.join(temp, "tsconfig.json"),
|
|
36
|
+
JSON.stringify({
|
|
37
|
+
compilerOptions: {
|
|
38
|
+
strict: true,
|
|
39
|
+
noEmit: true,
|
|
40
|
+
target: "ES2022",
|
|
41
|
+
module: "ESNext",
|
|
42
|
+
moduleResolution: "bundler",
|
|
43
|
+
jsx: "react-jsx",
|
|
44
|
+
esModuleInterop: true,
|
|
45
|
+
skipLibCheck: true,
|
|
46
|
+
resolveJsonModule: true,
|
|
47
|
+
types: ["react", "react-native"],
|
|
48
|
+
},
|
|
49
|
+
include: ["ota-client/**/*"],
|
|
50
|
+
}),
|
|
51
|
+
);
|
|
52
|
+
const result = spawnSync(
|
|
53
|
+
process.execPath,
|
|
54
|
+
[
|
|
55
|
+
require.resolve("typescript/bin/tsc"),
|
|
56
|
+
"--project",
|
|
57
|
+
path.join(temp, "tsconfig.json"),
|
|
58
|
+
],
|
|
59
|
+
{ stdio: "inherit" },
|
|
60
|
+
);
|
|
61
|
+
if (result.error) throw result.error;
|
|
62
|
+
if (result.status !== 0)
|
|
63
|
+
throw new Error("Generated OTA client typecheck failed.");
|
|
64
|
+
console.log(
|
|
65
|
+
"Generated OTA client passed strict TypeScript with the application dependencies.",
|
|
66
|
+
);
|
|
67
|
+
} finally {
|
|
68
|
+
await rm(temp, { recursive: true, force: true });
|
|
69
|
+
}
|
|
@@ -7,7 +7,7 @@ required native modules to an older binary via OTA. Keep these native dependenci
|
|
|
7
7
|
in the same runtime compatibility boundary as the rest of your application.
|
|
8
8
|
|
|
9
9
|
`ota-entry.js` starts telemetry without waiting, then synchronously loads the original
|
|
10
|
-
entry saved in `ota-client-entry.json`. The configurator also patches the root layout with the
|
|
10
|
+
entry saved in `ota-client-entry.json`. The configurator also patches the root layout with the standalone OtaUpdates component. Development,
|
|
11
11
|
Expo Go, web and disabled-updates builds do not report. Original OTA check policy
|
|
12
12
|
remains under the application/configurator's control.
|
|
13
13
|
|
|
@@ -49,7 +49,9 @@ SecureStore; do not deliver this client to older binaries lacking the native dep
|
|
|
49
49
|
## Update hook
|
|
50
50
|
|
|
51
51
|
`useOtaUpdates` shares identity, state and lifecycle actions across the application.
|
|
52
|
-
The configurator
|
|
52
|
+
The configurator renders `<OtaUpdates />` beside navigation. It calls the hook
|
|
53
|
+
internally, shows optional download/restart prompts, and blocks required updates.
|
|
54
|
+
The generated implementation uses TypeScript and JSX, with no context wrapper.
|
|
53
55
|
See [Update lifecycle](./docs/update-lifecycle.md) for manual/automatic/background
|
|
54
56
|
updates, force OTA versus store upgrades, custom guards and option defaults.
|
|
55
57
|
|
|
@@ -57,3 +59,15 @@ For a custom root that could not be patched, see the complete
|
|
|
57
59
|
[manual integration guide](https://tonichiga.github.io/expo-updates-server/ota-client-lifecycle#manual-integration)
|
|
58
60
|
(or `docs/ota-client-lifecycle.md` in the server repository). It covers both an
|
|
59
61
|
already generated client and copying/configuring the client without the generator.
|
|
62
|
+
|
|
63
|
+
## Type checking
|
|
64
|
+
|
|
65
|
+
Run `npx tsc --noEmit` in the Expo application. The server itself does not depend
|
|
66
|
+
on React Native. Maintainers can check the template against an application's
|
|
67
|
+
installed Expo dependencies without changing that application:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
node scripts/tests/ota-client-types.mjs /path/to/expo-app
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Run that command from the server repository.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
interface Heartbeat {
|
|
2
|
+
installationId: string;
|
|
3
|
+
eventId: string;
|
|
4
|
+
sequence: number;
|
|
5
|
+
observedAt: string;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
interface InstallationState {
|
|
9
|
+
installationId: string;
|
|
10
|
+
sequence: number;
|
|
11
|
+
pending: Heartbeat | null;
|
|
12
|
+
}
|
|
13
|
+
interface InstallationDependencies {
|
|
14
|
+
read(): Promise<string | null>;
|
|
15
|
+
write(value: string): Promise<void>;
|
|
16
|
+
uuid(): string;
|
|
17
|
+
snapshot(): Record<string, unknown>;
|
|
18
|
+
send(event: Heartbeat): Promise<void>;
|
|
19
|
+
setIdentity(id: string): Promise<void>;
|
|
20
|
+
now?(): string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Pure controller: storage and network are injected so ordering is testable.
|
|
24
|
+
// One persisted envelope owns identity, sequence and the bounded outbox.
|
|
25
|
+
export function createInstallationClient({
|
|
26
|
+
read,
|
|
27
|
+
write,
|
|
28
|
+
uuid,
|
|
29
|
+
snapshot,
|
|
30
|
+
send,
|
|
31
|
+
setIdentity,
|
|
32
|
+
now = () => new Date().toISOString(),
|
|
33
|
+
}: InstallationDependencies) {
|
|
34
|
+
let state: InstallationState | undefined;
|
|
35
|
+
let queue: Promise<unknown> = Promise.resolve();
|
|
36
|
+
let flight: Promise<void> | undefined;
|
|
37
|
+
const serial = <T>(work: () => Promise<T>): Promise<T> => {
|
|
38
|
+
const result = queue.then(work);
|
|
39
|
+
queue = result.catch(() => undefined);
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
async function initialize() {
|
|
43
|
+
if (state) return state;
|
|
44
|
+
const stored = await read();
|
|
45
|
+
if (stored) {
|
|
46
|
+
const parsed = JSON.parse(stored);
|
|
47
|
+
if (
|
|
48
|
+
!parsed.installationId ||
|
|
49
|
+
!Number.isSafeInteger(parsed.sequence) ||
|
|
50
|
+
parsed.sequence < 0
|
|
51
|
+
)
|
|
52
|
+
throw new Error("Invalid OTA client state");
|
|
53
|
+
state = parsed;
|
|
54
|
+
} else {
|
|
55
|
+
const next = { installationId: uuid(), sequence: 0, pending: null };
|
|
56
|
+
await write(JSON.stringify(next));
|
|
57
|
+
state = next;
|
|
58
|
+
}
|
|
59
|
+
return state!;
|
|
60
|
+
}
|
|
61
|
+
const ready = () =>
|
|
62
|
+
serial(async () => {
|
|
63
|
+
const current = await initialize();
|
|
64
|
+
await setIdentity(current.installationId);
|
|
65
|
+
return current.installationId;
|
|
66
|
+
});
|
|
67
|
+
async function flush() {
|
|
68
|
+
if (flight) return flight;
|
|
69
|
+
flight = (async () => {
|
|
70
|
+
const pending = await serial(async () => (await initialize()).pending);
|
|
71
|
+
if (!pending) return;
|
|
72
|
+
await send(pending);
|
|
73
|
+
await serial(async () => {
|
|
74
|
+
if (state?.pending?.eventId !== pending.eventId) return;
|
|
75
|
+
const next = { ...state, pending: null };
|
|
76
|
+
await write(JSON.stringify(next));
|
|
77
|
+
state = next;
|
|
78
|
+
});
|
|
79
|
+
})();
|
|
80
|
+
try {
|
|
81
|
+
await flight;
|
|
82
|
+
} finally {
|
|
83
|
+
flight = undefined;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function observe() {
|
|
87
|
+
await serial(async () => {
|
|
88
|
+
const current = await initialize();
|
|
89
|
+
await setIdentity(current.installationId);
|
|
90
|
+
if (current.sequence >= Number.MAX_SAFE_INTEGER)
|
|
91
|
+
throw new Error("OTA sequence exhausted");
|
|
92
|
+
const sequence = current.sequence + 1;
|
|
93
|
+
const pending = {
|
|
94
|
+
...snapshot(),
|
|
95
|
+
installationId: current.installationId,
|
|
96
|
+
eventId: uuid(),
|
|
97
|
+
sequence,
|
|
98
|
+
observedAt: now(),
|
|
99
|
+
};
|
|
100
|
+
const next = { ...current, sequence, pending };
|
|
101
|
+
await write(JSON.stringify(next));
|
|
102
|
+
state = next;
|
|
103
|
+
});
|
|
104
|
+
await flush();
|
|
105
|
+
}
|
|
106
|
+
return { ready, observe, flush };
|
|
107
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
interface DeviceIdentityDependencies {
|
|
2
|
+
platform: string;
|
|
3
|
+
scope: string;
|
|
4
|
+
androidId(): string | null;
|
|
5
|
+
readSecure(key: string): Promise<string | null>;
|
|
6
|
+
writeSecure(key: string, value: string): Promise<void>;
|
|
7
|
+
uuid(): string;
|
|
8
|
+
digest(value: string): Promise<string>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Dependencies are injected so reinstall behaviour can be tested without native modules.
|
|
12
|
+
export function createDeviceIdentity({
|
|
13
|
+
platform,
|
|
14
|
+
scope,
|
|
15
|
+
androidId,
|
|
16
|
+
readSecure,
|
|
17
|
+
writeSecure,
|
|
18
|
+
uuid,
|
|
19
|
+
digest,
|
|
20
|
+
}: DeviceIdentityDependencies) {
|
|
21
|
+
let flight: Promise<string | null> | undefined;
|
|
22
|
+
async function resolve() {
|
|
23
|
+
const namespace = await digest(`ota-device-v1:${scope}`);
|
|
24
|
+
let seed;
|
|
25
|
+
if (platform === "android") {
|
|
26
|
+
seed = androidId();
|
|
27
|
+
if (!seed) throw new Error("Android ID unavailable");
|
|
28
|
+
} else if (platform === "ios") {
|
|
29
|
+
const key = `ota-device-v1.${namespace}`;
|
|
30
|
+
seed = await readSecure(key);
|
|
31
|
+
if (!seed) {
|
|
32
|
+
seed = uuid();
|
|
33
|
+
await writeSecure(key, seed);
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return digest(`${namespace}:${platform}:${seed}`);
|
|
39
|
+
}
|
|
40
|
+
return () => {
|
|
41
|
+
if (!flight)
|
|
42
|
+
flight = resolve().catch((error) => {
|
|
43
|
+
flight = undefined;
|
|
44
|
+
throw error;
|
|
45
|
+
});
|
|
46
|
+
return flight;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
# Update lifecycle
|
|
2
2
|
|
|
3
|
-
`configure-app`
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
`configure-app` generates a formatted TypeScript client and renders `<OtaUpdates />`
|
|
4
|
+
beside navigation in the root layout/App. The component calls `useOtaUpdates`
|
|
5
|
+
internally; it does not wrap the app or provide React context. Mount it once in a
|
|
6
|
+
persistent root, including loading/early-return paths.
|
|
7
|
+
|
|
8
|
+
By default it checks automatically and shows **Download / Later** for an ordinary
|
|
9
|
+
update, then **Restart / Later** when downloaded. `autoUpdate={false}` disables
|
|
10
|
+
automatic downloading, not the prompt. A dismissed candidate stays hidden until the
|
|
11
|
+
component remounts, a different candidate arrives, or its download state changes.
|
|
12
|
+
Background updates remain silent; required updates cannot be dismissed.
|
|
13
|
+
|
|
14
|
+
The lower-level `useOtaUpdates()` is still available for optional custom screens.
|
|
15
|
+
It shares state/actions but defaults to no automation and renders no UI. Configure
|
|
16
|
+
automation in one root; multiple configured consumers combine booleans with OR.
|
|
17
|
+
Keep custom guard handlers stable.
|
|
9
18
|
|
|
10
19
|
Identity is persisted and installed in Expo request parameters before any check/download.
|
|
11
20
|
Launch/foreground heartbeats report only the **running** bundle, never a downloaded
|
|
@@ -14,7 +23,7 @@ Expo Go, web and disabled-updates builds leave automation off.
|
|
|
14
23
|
|
|
15
24
|
| Policy/options | Behavior |
|
|
16
25
|
| --- | --- |
|
|
17
|
-
| manual, default options |
|
|
26
|
+
| manual, default options | OtaUpdates offers download/restart; the hook alone exposes state |
|
|
18
27
|
| autoCheck | Check on mount and foreground, minimum interval 60 seconds |
|
|
19
28
|
| autoUpdate | Also download eligible manual candidates |
|
|
20
29
|
| autoReload | Reload a pending non-background bundle while app is active |
|
|
@@ -29,8 +38,8 @@ https, market and itms-apps URLs are accepted. Native upgrades still require a s
|
|
|
29
38
|
release; OTA cannot add native modules or change the installed runtime.
|
|
30
39
|
|
|
31
40
|
The built-in gate is a non-dismissable modal that preserves mounted navigation and providers.
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
Customize required UI with `renderBlocked`, and optional UI with `renderAvailable`.
|
|
42
|
+
Keep `OtaUpdates` mounted beside navigation; a hook alone exposes `blocked` but cannot prevent interaction with
|
|
34
43
|
your own screens. Unknown guards fail closed. Required checks are online policy,
|
|
35
44
|
not authentication or a tamper-proof access restriction. Offline check failure keeps
|
|
36
45
|
the running app usable unless a required candidate was already discovered or the running bundle requires a store/custom guard.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export {
|
|
2
|
+
start,
|
|
3
|
+
getInstallationId,
|
|
4
|
+
getDeviceId,
|
|
5
|
+
checkForUpdateAsync,
|
|
6
|
+
fetchUpdateAsync,
|
|
7
|
+
} from "./runtime";
|
|
8
|
+
export { useOtaUpdates } from "./model/hooks/useOtaUpdates";
|
|
9
|
+
export { OtaUpdateGate } from "./ui/ota-update-gate";
|
|
10
|
+
export { OtaUpdates } from "./ui/ota-updates";
|
|
11
|
+
export type {
|
|
12
|
+
OtaOptions,
|
|
13
|
+
OtaController,
|
|
14
|
+
OtaUpdatesProps,
|
|
15
|
+
OtaPolicy,
|
|
16
|
+
} from "./types";
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { OtaOptions, OtaController } from "../../types";
|
|
2
|
+
import { useEffect, useRef, useSyncExternalStore } from "react";
|
|
3
|
+
import * as Updates from "expo-updates";
|
|
4
|
+
import { AppState, Linking, Platform } from "react-native";
|
|
5
|
+
import {
|
|
6
|
+
enabled,
|
|
7
|
+
start,
|
|
8
|
+
getInstallationId,
|
|
9
|
+
getDeviceId,
|
|
10
|
+
checkForUpdateAsync,
|
|
11
|
+
fetchUpdateAsync,
|
|
12
|
+
} from "../../runtime";
|
|
13
|
+
import { createUpdateController } from "../update-controller";
|
|
14
|
+
|
|
15
|
+
const controller = createUpdateController({
|
|
16
|
+
enabled,
|
|
17
|
+
start,
|
|
18
|
+
identity: async () => ({
|
|
19
|
+
installationId: await getInstallationId(),
|
|
20
|
+
deviceId: await getDeviceId(),
|
|
21
|
+
}),
|
|
22
|
+
check: checkForUpdateAsync,
|
|
23
|
+
fetch: fetchUpdateAsync,
|
|
24
|
+
runningCandidate: () => ({ type: "new", manifest: Updates.manifest }),
|
|
25
|
+
reload: () => Updates.reloadAsync(),
|
|
26
|
+
isActive: () => AppState.currentState === "active",
|
|
27
|
+
openStore: async (payload) => {
|
|
28
|
+
const links =
|
|
29
|
+
payload && typeof payload === "object"
|
|
30
|
+
? (payload as Record<string, unknown>)
|
|
31
|
+
: {};
|
|
32
|
+
const url = links[`${Platform.OS}Url`] || links.url;
|
|
33
|
+
if (
|
|
34
|
+
typeof url !== "string" ||
|
|
35
|
+
!/^(https:\/\/|market:\/\/|itms-apps:\/\/)/i.test(url)
|
|
36
|
+
) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
"The store update policy must provide a valid https/store URL",
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
await Linking.openURL(url);
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
const emptyOptions = Object.freeze({});
|
|
45
|
+
|
|
46
|
+
/** Configure once in the root; additional consumers share identity, state and actions. */
|
|
47
|
+
export function useOtaUpdates(
|
|
48
|
+
options: OtaOptions = emptyOptions,
|
|
49
|
+
): OtaController {
|
|
50
|
+
const owner = useRef(Symbol("ota-updates"));
|
|
51
|
+
const state = useSyncExternalStore(
|
|
52
|
+
controller.subscribe,
|
|
53
|
+
controller.getSnapshot,
|
|
54
|
+
controller.getSnapshot,
|
|
55
|
+
);
|
|
56
|
+
const native = Updates.useUpdates();
|
|
57
|
+
const {
|
|
58
|
+
autoCheck = false,
|
|
59
|
+
autoUpdate = false,
|
|
60
|
+
autoReload = false,
|
|
61
|
+
guardHandlers,
|
|
62
|
+
} = options;
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
const token = owner.current;
|
|
65
|
+
controller.configure(token, {
|
|
66
|
+
autoCheck,
|
|
67
|
+
autoUpdate,
|
|
68
|
+
autoReload,
|
|
69
|
+
guardHandlers,
|
|
70
|
+
});
|
|
71
|
+
void controller.initialize().catch(() => undefined);
|
|
72
|
+
controller.automaticCheck();
|
|
73
|
+
const subscription = AppState.addEventListener("change", (next) => {
|
|
74
|
+
if (next === "active") controller.automaticCheck();
|
|
75
|
+
});
|
|
76
|
+
return () => {
|
|
77
|
+
subscription.remove();
|
|
78
|
+
controller.removeOwner(token);
|
|
79
|
+
};
|
|
80
|
+
}, [autoCheck, autoUpdate, autoReload, guardHandlers]);
|
|
81
|
+
const downloaded = native.downloadedUpdate;
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (!enabled || !downloaded || !native.isUpdatePending) return;
|
|
84
|
+
void controller
|
|
85
|
+
.syncPending({ type: downloaded.type, manifest: downloaded.manifest })
|
|
86
|
+
.catch(() => undefined);
|
|
87
|
+
}, [downloaded, native.isUpdatePending]);
|
|
88
|
+
return {
|
|
89
|
+
...state,
|
|
90
|
+
isBusy: state.status !== "idle",
|
|
91
|
+
check: controller.check,
|
|
92
|
+
download: controller.download,
|
|
93
|
+
reload: controller.reload,
|
|
94
|
+
retry: controller.retry,
|
|
95
|
+
openStore: controller.openStore,
|
|
96
|
+
};
|
|
97
|
+
}
|