create-expo-updates-server 0.3.0 → 0.6.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 (191) hide show
  1. package/README.md +4 -2
  2. package/dist/template/Dockerfile +4 -6
  3. package/dist/template/README.md +5 -10
  4. package/dist/template/app/api/admin/device-favorites/route.test.ts +125 -0
  5. package/dist/template/app/api/admin/device-favorites/route.ts +91 -0
  6. package/dist/template/app/api/admin/distribution-history/restore/route.ts +39 -0
  7. package/dist/template/app/api/admin/distribution-history/route.test.ts +55 -0
  8. package/dist/template/app/api/admin/distribution-history/route.ts +24 -0
  9. package/dist/template/app/api/admin/updates/[encodedKey]/deactivate/route.ts +2 -1
  10. package/dist/template/app/api/admin/updates/[encodedKey]/promote/route.ts +2 -1
  11. package/dist/template/app/api/admin/updates/[encodedKey]/rollback/route.ts +2 -1
  12. package/dist/template/app/api/admin/updates/[encodedKey]/route.ts +2 -1
  13. package/dist/template/app/api/admin/updates/route.test.ts +21 -0
  14. package/dist/template/app/api/admin/updates/route.ts +12 -1
  15. package/dist/template/app/globals.css +65 -68
  16. package/dist/template/app/login/page.tsx +66 -42
  17. package/dist/template/app/updates/[encodedKey]/page.tsx +382 -248
  18. package/dist/template/app/updates/devices/page.tsx +187 -145
  19. package/dist/template/app/updates/embedded/page.tsx +80 -34
  20. package/dist/template/app/updates/emergency-redirects/page.tsx +138 -71
  21. package/dist/template/app/updates/layout.tsx +2 -1
  22. package/dist/template/app/updates/page.tsx +385 -274
  23. package/dist/template/app/updates/releases.test.tsx +156 -0
  24. package/dist/template/components/admin/admin-role.ts +5 -0
  25. package/dist/template/components/admin/admin-shell.tsx +166 -95
  26. package/dist/template/components/admin/confirm-action.tsx +123 -0
  27. package/dist/template/components/admin/language-switcher.tsx +27 -16
  28. package/dist/template/components/admin/release-badges.test.tsx +50 -0
  29. package/dist/template/components/admin/release-badges.tsx +101 -0
  30. package/dist/template/components/ui/alert.tsx +10 -3
  31. package/dist/template/components/ui/avatar.tsx +108 -0
  32. package/dist/template/components/ui/badge.tsx +2 -2
  33. package/dist/template/components/ui/breadcrumb.tsx +108 -0
  34. package/dist/template/components/ui/button.tsx +5 -5
  35. package/dist/template/components/ui/card.tsx +2 -2
  36. package/dist/template/components/ui/chart.tsx +1 -1
  37. package/dist/template/components/ui/collapsible.tsx +7 -0
  38. package/dist/template/components/ui/dialog.tsx +13 -4
  39. package/dist/template/components/ui/empty.tsx +103 -0
  40. package/dist/template/components/ui/field.tsx +248 -0
  41. package/dist/template/components/ui/input-group.tsx +170 -0
  42. package/dist/template/components/ui/input.tsx +1 -1
  43. package/dist/template/components/ui/native-select.tsx +1 -1
  44. package/dist/template/components/ui/radio-group.tsx +41 -0
  45. package/dist/template/components/ui/sheet.tsx +6 -2
  46. package/dist/template/components/ui/sidebar.tsx +62 -17
  47. package/dist/template/components/ui/status-tones.ts +15 -0
  48. package/dist/template/components/ui/table.tsx +1 -1
  49. package/dist/template/components/ui/textarea.tsx +1 -1
  50. package/dist/template/docs/admin-ui.md +22 -24
  51. package/dist/template/docs/device-targeting.md +6 -12
  52. package/dist/template/docs/doctor.md +2 -2
  53. package/dist/template/docs/expo-app-setup.md +9 -27
  54. package/dist/template/docs/getting-started.md +3 -4
  55. package/dist/template/docs/getting-started.ru.md +11 -544
  56. package/dist/template/docs/index.md +1 -1
  57. package/dist/template/docs/installation-telemetry.md +6 -12
  58. package/dist/template/docs/migrations/2026-10-16-manifest-identity.sql +5 -0
  59. package/dist/template/docs/migrations/2026-11-25-device-favorites.sql +53 -0
  60. package/dist/template/docs/migrations/2026-11-25-download-on-postpone.sql +5 -0
  61. package/dist/template/docs/migrations/2026-11-25-public-distribution-history.sql +283 -0
  62. package/dist/template/docs/migrations/schema.sql +349 -0
  63. package/dist/template/docs/npm-installer.md +3 -3
  64. package/dist/template/docs/operations-guide.md +9 -7
  65. package/dist/template/docs/ota-client-lifecycle.md +30 -68
  66. package/dist/template/docs/ota-emergency-recovery.md +34 -57
  67. package/dist/template/docs/ota-update-policy.md +9 -20
  68. package/dist/template/docs/ru/admin-ui.md +33 -0
  69. package/dist/template/docs/ru/device-targeting.md +59 -0
  70. package/dist/template/docs/ru/doctor.md +98 -0
  71. package/dist/template/docs/ru/expo-app-setup.md +497 -0
  72. package/dist/template/docs/ru/getting-started.md +391 -0
  73. package/dist/template/docs/ru/index.md +50 -0
  74. package/dist/template/docs/ru/installation-telemetry.md +125 -0
  75. package/dist/template/docs/ru/npm-installer.md +71 -0
  76. package/dist/template/docs/ru/operations-guide.md +322 -0
  77. package/dist/template/docs/ru/ota-client-lifecycle.md +162 -0
  78. package/dist/template/docs/ru/ota-emergency-recovery.md +108 -0
  79. package/dist/template/docs/ru/ota-update-policy.md +69 -0
  80. package/dist/template/docs/ru/publishing-npm-installer.md +49 -0
  81. package/dist/template/docs/ru/supabase-setup.md +120 -0
  82. package/dist/template/docs/uk/admin-ui.md +33 -0
  83. package/dist/template/docs/uk/device-targeting.md +59 -0
  84. package/dist/template/docs/uk/doctor.md +98 -0
  85. package/dist/template/docs/uk/expo-app-setup.md +497 -0
  86. package/dist/template/docs/uk/getting-started.md +391 -0
  87. package/dist/template/docs/uk/index.md +50 -0
  88. package/dist/template/docs/uk/installation-telemetry.md +125 -0
  89. package/dist/template/docs/uk/npm-installer.md +71 -0
  90. package/dist/template/docs/uk/operations-guide.md +322 -0
  91. package/dist/template/docs/uk/ota-client-lifecycle.md +162 -0
  92. package/dist/template/docs/uk/ota-emergency-recovery.md +108 -0
  93. package/dist/template/docs/uk/ota-update-policy.md +69 -0
  94. package/dist/template/docs/uk/publishing-npm-installer.md +49 -0
  95. package/dist/template/docs/uk/supabase-setup.md +120 -0
  96. package/dist/template/lib/audience-ids.ts +4 -0
  97. package/dist/template/package-lock.json +46 -0
  98. package/dist/template/package.json +4 -1
  99. package/dist/template/scripts/configure-expo-app.mjs +3 -3
  100. package/dist/template/scripts/create-access-token.mjs +1 -1
  101. package/dist/template/scripts/lib/doctor.mjs +10 -7
  102. package/dist/template/scripts/lib/doctor.test.mjs +7 -5
  103. package/dist/template/scripts/lib/embedded-update-registrar.test.ts +22 -7
  104. package/dist/template/scripts/lib/expo-app-configurator.mjs +25 -22
  105. package/dist/template/scripts/lib/expo-app-configurator.test.ts +37 -2
  106. package/dist/template/scripts/lib/ota-client-configurator.mjs +152 -55
  107. package/dist/template/scripts/lib/ota-client-configurator.test.ts +60 -20
  108. package/dist/template/scripts/lib/ota-client-package.mjs +25 -0
  109. package/dist/template/scripts/lib/ota-root-hook-patcher.mjs +90 -32
  110. package/dist/template/scripts/lib/ota-root-hook-patcher.test.ts +49 -6
  111. package/dist/template/scripts/tests/device-analytics-migrations.mjs +12 -1
  112. package/dist/template/scripts/tests/device-targeting-activation.mjs +2 -3
  113. package/dist/template/scripts/tests/e2e/client-lifecycle.mjs +161 -0
  114. package/dist/template/scripts/tests/e2e/client-lifecycle.scenario.jsx +465 -0
  115. package/dist/template/scripts/tests/e2e/client-vitest.mts +18 -0
  116. package/dist/template/scripts/tests/e2e/console.mjs +86 -0
  117. package/dist/template/scripts/tests/e2e/delivery.mjs +296 -0
  118. package/dist/template/scripts/tests/e2e/device-favorites.mjs +309 -0
  119. package/dist/template/scripts/tests/e2e/installations.mjs +132 -0
  120. package/dist/template/scripts/tests/e2e/policy.mjs +253 -0
  121. package/dist/template/scripts/tests/e2e/registrar-token.mjs +59 -0
  122. package/dist/template/scripts/tests/e2e/release-matrix.mjs +307 -0
  123. package/dist/template/scripts/tests/e2e/releases.mjs +162 -0
  124. package/dist/template/scripts/tests/e2e/run.mjs +224 -0
  125. package/dist/template/scripts/tests/manifest-identity.sql +7 -5
  126. package/dist/template/scripts/tests/public-distribution-history.mjs +102 -0
  127. package/dist/template/src/client/admin-api.ts +45 -10
  128. package/dist/template/src/client/admin-types.ts +35 -1
  129. package/dist/template/src/client/devices/analytics.tsx +169 -219
  130. package/dist/template/src/client/devices/cohorts.tsx +181 -0
  131. package/dist/template/src/client/devices/device-name.tsx +37 -21
  132. package/dist/template/src/client/devices/favorite-targets.tsx +381 -0
  133. package/dist/template/src/client/devices/registry.tsx +265 -233
  134. package/dist/template/src/client/devices/use-devices-report.test.tsx +98 -0
  135. package/dist/template/src/client/devices/use-devices-report.ts +53 -82
  136. package/dist/template/src/client/devices/version-adoption-chart.tsx +48 -38
  137. package/dist/template/src/client/distribution-control.tsx +98 -53
  138. package/dist/template/src/client/distribution-history.tsx +353 -0
  139. package/dist/template/src/client/guard-action-catalog.tsx +183 -0
  140. package/dist/template/src/client/guard-action-combobox.test.ts +16 -22
  141. package/dist/template/src/client/guard-action-combobox.tsx +134 -234
  142. package/dist/template/src/client/guard-action-options.ts +4 -6
  143. package/dist/template/src/client/i18n/en.json +335 -2
  144. package/dist/template/src/client/i18n/language-switching.test.tsx +233 -0
  145. package/dist/template/src/client/i18n/messages.test.ts +102 -19
  146. package/dist/template/src/client/i18n/messages.ts +31 -16
  147. package/dist/template/src/client/i18n/provider.tsx +6 -3
  148. package/dist/template/src/client/i18n/ru.json +619 -0
  149. package/dist/template/src/client/i18n/uk.json +619 -0
  150. package/dist/template/src/client/i18n/use-formatters.ts +5 -0
  151. package/dist/template/src/client/logout-button.tsx +3 -3
  152. package/dist/template/src/client/policy-draft.ts +138 -0
  153. package/dist/template/src/client/update-audience-editor.tsx +597 -199
  154. package/dist/template/src/client/update-policy-editor.test.ts +101 -29
  155. package/dist/template/src/client/update-policy-editor.tsx +466 -307
  156. package/dist/template/src/client/use-filtered-results.ts +55 -0
  157. package/dist/template/src/server/controllers/manifest.test.ts +23 -3
  158. package/dist/template/src/server/controllers/manifest.ts +15 -1
  159. package/dist/template/src/server/devices/audience.ts +9 -5
  160. package/dist/template/src/server/lib/admin-audience-activation.test.ts +37 -90
  161. package/dist/template/src/server/lib/admin-release-history.test.ts +138 -0
  162. package/dist/template/src/server/lib/admin-updates.ts +160 -534
  163. package/dist/template/src/server/lib/distribution-history.ts +97 -0
  164. package/dist/template/src/server/lib/supabase.js +24 -0
  165. package/dist/template/src/server/lib/supabase.test.ts +38 -1
  166. package/dist/template/src/server/lib/update-policy.test.ts +20 -0
  167. package/dist/template/src/server/lib/update-policy.ts +23 -10
  168. package/dist/template/src/server/manifest/manifest-repository.ts +11 -3
  169. package/dist/template/src/server/manifest/manifest-values.test.ts +2 -0
  170. package/dist/template/src/server/manifest/manifest-values.ts +21 -13
  171. package/dist/template/templates/expo-app/scripts/ota-publish/api/database-client.mjs +7 -30
  172. package/dist/template/templates/expo-app/scripts/ota-register-embedded/index.mjs +2 -1
  173. package/dist/template/tsconfig.json +2 -2
  174. package/dist/template-manifest.json +571 -271
  175. package/package.json +1 -1
  176. package/dist/template/scripts/lib/device-identity.test.ts +0 -29
  177. package/dist/template/scripts/lib/ota-client.test.ts +0 -55
  178. package/dist/template/scripts/lib/ota-update-controller.test.ts +0 -232
  179. package/dist/template/scripts/lib/ota-updates-ui.test.tsx +0 -154
  180. package/dist/template/scripts/tests/ota-client-types.mjs +0 -69
  181. package/dist/template/templates/expo-app/ota-client/README.md +0 -73
  182. package/dist/template/templates/expo-app/ota-client/controller.ts +0 -107
  183. package/dist/template/templates/expo-app/ota-client/device-identity.ts +0 -48
  184. package/dist/template/templates/expo-app/ota-client/docs/update-lifecycle.md +0 -61
  185. package/dist/template/templates/expo-app/ota-client/index.ts +0 -16
  186. package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.ts +0 -97
  187. package/dist/template/templates/expo-app/ota-client/model/update-controller.ts +0 -293
  188. package/dist/template/templates/expo-app/ota-client/runtime.ts +0 -153
  189. package/dist/template/templates/expo-app/ota-client/types.ts +0 -85
  190. package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.tsx +0 -25
  191. package/dist/template/templates/expo-app/ota-client/ui/ota-updates.tsx +0 -196
@@ -1,153 +0,0 @@
1
- import AsyncStorage from "@react-native-async-storage/async-storage";
2
- import * as Application from "expo-application";
3
- import * as Crypto from "expo-crypto";
4
- import * as SecureStore from "expo-secure-store";
5
- import { createDeviceIdentity } from "./device-identity";
6
- import * as Updates from "expo-updates";
7
- import { AppState, Platform } from "react-native";
8
- import { createInstallationClient } from "./controller";
9
- import config from "./config.json";
10
- import { manifestDetails } from "./types";
11
-
12
- class HeartbeatError extends Error {
13
- constructor(
14
- message: string,
15
- readonly permanent: boolean,
16
- ) {
17
- super(message);
18
- }
19
- }
20
-
21
- const STORAGE_KEY = "@ota-client/installation-v1";
22
- export const enabled = Platform.OS !== "web" && !__DEV__ && Updates.isEnabled;
23
- const resolveDeviceId = createDeviceIdentity({
24
- platform: Platform.OS,
25
- scope: `${Application.applicationId}:${config.identityNamespace}`,
26
- androidId: () => Application.getAndroidId(),
27
- readSecure: (key) => SecureStore.getItemAsync(key),
28
- writeSecure: (key, value) =>
29
- SecureStore.setItemAsync(key, value, {
30
- keychainAccessible: SecureStore.WHEN_UNLOCKED_THIS_DEVICE_ONLY,
31
- }),
32
- uuid: () => Crypto.randomUUID(),
33
- digest: (value) =>
34
- Crypto.digestStringAsync(Crypto.CryptoDigestAlgorithm.SHA256, value),
35
- });
36
- let deviceId: string | null = null;
37
- const client = createInstallationClient({
38
- read: () => AsyncStorage.getItem(STORAGE_KEY),
39
- write: (value) => AsyncStorage.setItem(STORAGE_KEY, value),
40
- uuid: () => Crypto.randomUUID(),
41
- setIdentity: async (id) => {
42
- await Updates.setExtraParamAsync("installation_id", id);
43
- // Temporary Keychain failure must not stop installation telemetry or keep a stale identity.
44
- deviceId = await resolveDeviceId().catch(() => null);
45
- await Updates.setExtraParamAsync("device_id", deviceId);
46
- },
47
- snapshot: () => ({
48
- ...(deviceId ? { deviceId } : {}),
49
- platform: Platform.OS,
50
- channel:
51
- manifestDetails(Updates.manifest)?.metadata?.channel || config.channel,
52
- runtimeVersion: Updates.runtimeVersion,
53
- updateId: Updates.updateId,
54
- nativeVersion: Application.nativeApplicationVersion,
55
- nativeBuild: Application.nativeBuildVersion,
56
- isEmbeddedLaunch: Updates.isEmbeddedLaunch,
57
- isEmergencyLaunch: Updates.isEmergencyLaunch,
58
- }),
59
- send: async (event) => {
60
- const abort = new AbortController();
61
- const timeout = setTimeout(() => abort.abort(), 8000);
62
- try {
63
- const response = await fetch(config.heartbeatUrl, {
64
- method: "POST",
65
- headers: { "Content-Type": "application/json" },
66
- body: JSON.stringify(event),
67
- signal: abort.signal,
68
- });
69
- if (!response.ok) {
70
- const error = new HeartbeatError(
71
- `Heartbeat HTTP ${response.status}`,
72
- response.status === 400 || response.status === 409,
73
- );
74
- throw error;
75
- }
76
- const result = await response.json();
77
- if (!["accepted", "duplicate", "stale"].includes(result.status))
78
- throw new Error("Invalid heartbeat response");
79
- } finally {
80
- clearTimeout(timeout);
81
- }
82
- },
83
- });
84
-
85
- let started = false;
86
- let timer: ReturnType<typeof setTimeout> | undefined;
87
- let lastObservation = 0;
88
- let failures = 0;
89
- let ticking: Promise<void> | undefined;
90
- function schedule() {
91
- clearTimeout(timer);
92
- if (AppState.currentState !== "active") return;
93
- timer = setTimeout(tick, Math.min(60000 * 2 ** failures, 300000));
94
- }
95
- async function performTick() {
96
- clearTimeout(timer);
97
- try {
98
- // Retry the exact durable event before replacing it with a fresh observation.
99
- try {
100
- await client.flush();
101
- } catch (error) {
102
- if (!(error instanceof HeartbeatError) || !error.permanent) throw error;
103
- }
104
- if (Date.now() - lastObservation >= 60000) {
105
- await client.observe();
106
- lastObservation = Date.now();
107
- }
108
- failures = 0;
109
- } catch {
110
- failures = Math.min(failures + 1, 3);
111
- } finally {
112
- schedule();
113
- }
114
- }
115
- function tick() {
116
- if (ticking) return ticking;
117
- ticking = performTick().finally(() => {
118
- ticking = undefined;
119
- });
120
- return ticking;
121
- }
122
- export function start() {
123
- if (started || !enabled) return;
124
- started = true;
125
- // Registration of the original application entry never waits for telemetry.
126
- void client
127
- .observe()
128
- .then(() => {
129
- lastObservation = Date.now();
130
- })
131
- .catch(() => undefined)
132
- .finally(schedule);
133
- AppState.addEventListener("change", (state) => {
134
- if (state === "active") void tick();
135
- else clearTimeout(timer);
136
- });
137
- }
138
- export async function getInstallationId() {
139
- if (!enabled) return null;
140
- return client.ready();
141
- }
142
- export async function getDeviceId() {
143
- await getInstallationId();
144
- return deviceId;
145
- }
146
- export async function checkForUpdateAsync() {
147
- await getInstallationId();
148
- return Updates.checkForUpdateAsync();
149
- }
150
- export async function fetchUpdateAsync() {
151
- await getInstallationId();
152
- return Updates.fetchUpdateAsync();
153
- }
@@ -1,85 +0,0 @@
1
- import type { ReactNode } from "react";
2
-
3
- export interface OtaPolicy {
4
- schemaVersion: number;
5
- delivery: "manual" | "background";
6
- guard?: { action: string; payload?: unknown };
7
- }
8
-
9
- export interface OtaManifest {
10
- id?: string;
11
- extra?: { updatePolicy?: OtaPolicy };
12
- metadata?: { channel?: string };
13
- }
14
-
15
- export interface OtaCandidate {
16
- type: "new" | "rollback";
17
- manifest: unknown;
18
- }
19
-
20
- export interface OtaCheckResult {
21
- isAvailable: boolean;
22
- isRollBackToEmbedded?: boolean;
23
- manifest?: unknown;
24
- }
25
-
26
- export interface OtaFetchResult {
27
- isNew: boolean;
28
- isRollBackToEmbedded?: boolean;
29
- manifest?: unknown;
30
- }
31
-
32
- export interface OtaOptions {
33
- /** Check on mount/foreground, at most once per minute. Default false in the hook. */
34
- autoCheck?: boolean;
35
- /** Download ordinary releases automatically; does not control their visibility. */
36
- autoUpdate?: boolean;
37
- /** Reload non-background updates while the application is active. */
38
- autoReload?: boolean;
39
- guardHandlers?: Record<
40
- string,
41
- (context: {
42
- action: string;
43
- payload: unknown;
44
- manifest: unknown;
45
- }) => "allow" | "block" | Promise<"allow" | "block">
46
- >;
47
- }
48
-
49
- export interface OtaState {
50
- enabled: boolean;
51
- status: "idle" | "checking" | "downloading" | "reloading" | "opening-store";
52
- installationId: string | null;
53
- deviceId: string | null;
54
- available: boolean;
55
- pending: boolean;
56
- candidate: OtaCandidate | null;
57
- policy: OtaPolicy | null;
58
- blocked: boolean;
59
- blockReason: string | null;
60
- error: Error | null;
61
- }
62
-
63
- export interface OtaController extends OtaState {
64
- isBusy: boolean;
65
- check(): Promise<OtaCheckResult>;
66
- download(): Promise<OtaFetchResult>;
67
- reload(): Promise<void>;
68
- retry(): Promise<OtaCheckResult>;
69
- openStore(): Promise<void>;
70
- }
71
-
72
- export interface OtaUpdatesProps extends OtaOptions {
73
- renderBlocked?: (controller: OtaController) => ReactNode;
74
- renderAvailable?: (
75
- controller: OtaController,
76
- dismiss: () => void,
77
- ) => ReactNode;
78
- }
79
-
80
- /** Native manifests are data, not necessarily the full Expo manifest schema. */
81
- export function manifestDetails(manifest: unknown): OtaManifest | null {
82
- return manifest && typeof manifest === "object"
83
- ? (manifest as OtaManifest)
84
- : null;
85
- }
@@ -1,25 +0,0 @@
1
- import type { ReactNode } from "react";
2
- import type { OtaController, OtaUpdatesProps } from "../types";
3
- import { OtaUpdateOverlay } from "./ota-updates";
4
-
5
- /** Compatibility for existing layouts; new integrations render OtaUpdates beside navigation. */
6
- export function OtaUpdateGate({
7
- controller,
8
- children,
9
- renderBlocked,
10
- }: {
11
- controller: OtaController;
12
- children?: ReactNode;
13
- renderBlocked?: OtaUpdatesProps["renderBlocked"];
14
- }) {
15
- return (
16
- <>
17
- {children}
18
- <OtaUpdateOverlay
19
- controller={controller}
20
- renderBlocked={renderBlocked}
21
- showAvailable={false}
22
- />
23
- </>
24
- );
25
- }
@@ -1,196 +0,0 @@
1
- import { useState } from "react";
2
- import {
3
- ActivityIndicator,
4
- Modal,
5
- Pressable,
6
- StyleSheet,
7
- Text,
8
- View,
9
- } from "react-native";
10
- import type { OtaController, OtaUpdatesProps } from "../types";
11
- import { manifestDetails } from "../types";
12
- import { useOtaUpdates } from "../model/hooks/useOtaUpdates";
13
-
14
- /** Mount once beside navigation. No context or application wrapper is required. */
15
- export function OtaUpdates({
16
- autoCheck = true,
17
- autoUpdate = false,
18
- autoReload = false,
19
- guardHandlers,
20
- renderBlocked,
21
- renderAvailable,
22
- }: OtaUpdatesProps) {
23
- const controller = useOtaUpdates({
24
- autoCheck,
25
- autoUpdate,
26
- autoReload,
27
- guardHandlers,
28
- });
29
- return (
30
- <OtaUpdateOverlay
31
- controller={controller}
32
- renderBlocked={renderBlocked}
33
- renderAvailable={renderAvailable}
34
- />
35
- );
36
- }
37
-
38
- interface OverlayProps
39
- extends Pick<OtaUpdatesProps, "renderBlocked" | "renderAvailable"> {
40
- controller: OtaController;
41
- showAvailable?: boolean;
42
- }
43
-
44
- export function OtaUpdateOverlay({
45
- controller,
46
- renderBlocked,
47
- renderAvailable,
48
- showAvailable = true,
49
- }: OverlayProps) {
50
- const [dismissed, setDismissed] = useState<string | null>(null);
51
- const candidateId =
52
- manifestDetails(controller.candidate?.manifest)?.id ??
53
- controller.candidate?.type ??
54
- "update";
55
- const noticeId = `${candidateId}:${controller.pending}`;
56
- const dismiss = () => {
57
- if (!controller.blocked) setDismissed(noticeId);
58
- };
59
- const optional =
60
- showAvailable &&
61
- controller.available &&
62
- controller.policy?.delivery !== "background" &&
63
- dismissed !== noticeId;
64
- if (!controller.blocked && !optional) return null;
65
-
66
- let content = <UpdateNotice controller={controller} dismiss={dismiss} />;
67
- if (controller.blocked && renderBlocked)
68
- content = <>{renderBlocked(controller)}</>;
69
- if (!controller.blocked && renderAvailable)
70
- content = <>{renderAvailable(controller, dismiss)}</>;
71
-
72
- return (
73
- <Modal
74
- visible
75
- animationType="none"
76
- presentationStyle="fullScreen"
77
- onRequestClose={dismiss}
78
- >
79
- {content}
80
- </Modal>
81
- );
82
- }
83
-
84
- function UpdateNotice({
85
- controller,
86
- dismiss,
87
- }: {
88
- controller: OtaController;
89
- dismiss: () => void;
90
- }) {
91
- let title = "Update available";
92
- let description =
93
- "A new version is available. Download it now or continue using the application.";
94
- let label = "Download";
95
- let action: () => Promise<unknown> = controller.download;
96
- if (controller.pending) {
97
- description = "The update is ready. Restart the application to apply it.";
98
- label = "Restart";
99
- action = controller.reload;
100
- }
101
- if (controller.blocked) {
102
- title = "Update required";
103
- description = "An application update is required to continue.";
104
- label = "Retry";
105
- action = controller.retry;
106
- if (controller.blockReason === "ota-force-store-update") {
107
- description = "Install the latest version from the store to continue.";
108
- label = "Open store";
109
- action = controller.openStore;
110
- } else if (controller.blockReason === "ota-force-update") {
111
- if (controller.pending) {
112
- description =
113
- "The update is ready. Restart the application to continue.";
114
- label = "Restart";
115
- action = controller.reload;
116
- }
117
- } else {
118
- title = "Update needs attention";
119
- description = "This update requires an action before you can continue.";
120
- }
121
- }
122
-
123
- return (
124
- <View style={styles.root}>
125
- <Text style={styles.title} accessibilityRole="header">
126
- {title}
127
- </Text>
128
- <Text style={styles.text}>{description}</Text>
129
- {controller.error && (
130
- <Text style={styles.error} accessibilityRole="alert">
131
- {controller.error.message}
132
- </Text>
133
- )}
134
- {controller.isBusy && (
135
- <ActivityIndicator
136
- color="#93c5fd"
137
- accessibilityLabel="Updating application"
138
- />
139
- )}
140
- <Pressable
141
- style={styles.button}
142
- accessibilityRole="button"
143
- accessibilityState={{ disabled: controller.isBusy }}
144
- disabled={controller.isBusy}
145
- onPress={() => {
146
- void action().catch(() => undefined);
147
- }}
148
- >
149
- <Text style={styles.buttonText}>{label}</Text>
150
- </Pressable>
151
- {controller.blockReason === "ota-force-store-update" && (
152
- <Pressable
153
- style={styles.button}
154
- accessibilityRole="button"
155
- disabled={controller.isBusy}
156
- onPress={() => {
157
- void controller.retry().catch(() => undefined);
158
- }}
159
- >
160
- <Text style={styles.buttonText}>Check again</Text>
161
- </Pressable>
162
- )}
163
- {!controller.blocked && (
164
- <Pressable
165
- style={styles.button}
166
- accessibilityRole="button"
167
- onPress={dismiss}
168
- >
169
- <Text style={styles.buttonText}>Later</Text>
170
- </Pressable>
171
- )}
172
- </View>
173
- );
174
- }
175
-
176
- const styles = StyleSheet.create({
177
- root: {
178
- flex: 1,
179
- justifyContent: "center",
180
- padding: 28,
181
- gap: 20,
182
- backgroundColor: "#0f172a",
183
- },
184
- title: { color: "#f8fafc", fontSize: 26, fontWeight: "700" },
185
- text: { color: "#cbd5e1", fontSize: 16, lineHeight: 24 },
186
- error: { color: "#fca5a5", fontSize: 14 },
187
- button: {
188
- minHeight: 48,
189
- justifyContent: "center",
190
- alignItems: "center",
191
- backgroundColor: "#2563eb",
192
- borderRadius: 12,
193
- padding: 12,
194
- },
195
- buttonText: { color: "#fff", fontSize: 16, fontWeight: "600" },
196
- });