@vvedantb/native-ui 0.33.0 → 0.35.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 +1 -1
- package/dist/UpdateChecker.jsx +80 -61
- package/dist/entries/layout.js +1 -0
- package/dist/index.js +2 -1
- package/dist/settings/ThemeModePicker.jsx +135 -0
- package/dist/updateCheck.js +32 -0
- package/package.json +1 -1
- package/src/UpdateChecker.tsx +30 -9
- package/src/entries/layout.ts +2 -0
- package/src/index.ts +4 -2
- package/src/settings/ThemeModePicker.tsx +132 -0
- package/src/updateCheck.ts +45 -0
package/README.md
CHANGED
|
@@ -89,7 +89,7 @@ The root entry exports everything. It still imports `BottomSheetContainer` and `
|
|
|
89
89
|
| `@vvedantb/native-ui/toast` | `toast`, `Toaster`, `ToastOptions`, `ToastVariant` | none (from 0.3.12) |
|
|
90
90
|
| `@vvedantb/native-ui/theme` | `NativeUiProvider`, `useNativeUi`, `useLargerText`, `useAccentColor`, `DEFAULT_ACCENT`, `tokens`, `palette`, `withAlpha`, `configureTheme` (with the `ThemeConfig`, `ThemeColors` and `ThemePalette` types), `fontClass`, `fontFamily` (with the `ThemeFonts` type), `cn`, `Colors` and the colour constants | none |
|
|
91
91
|
| `@vvedantb/native-ui/floating` | `FloatingSurface`, `GlassSheetBackground`, `LiquidGlass`, `GlassBlurProvider`, `GlassBlurTarget`, `FloatingFAB`, `useReduceTransparency`, the floating metrics and styles | `expo-blur` (loader) |
|
|
92
|
-
| `@vvedantb/native-ui/layout` | `ScreenContainer`, `SafeAreaContainer`, `PageTitle`, `PageHeader`, `StackPageHeader` (0.5.0) and their props types, `SectionLabel` (0.5.0), `SettingsSection`, `SettingsField`, `SettingsToggleRow`, `SettingsStack`, `MoreFromProjectV` and `FromProjectV` (0.8.0), `ScreenContainerProps`, `SettingsEmptyState`, `PinnedBotTile`, `BotPinGrid`, `ArtifactList` (0.12.0). `ScreenContainer` takes `refreshing`, `onRefresh` and `refreshControl` (0.12.0). `StackPageHeader` takes `centre` (0.12.0) | `expo-blur` (loader) |
|
|
92
|
+
| `@vvedantb/native-ui/layout` | `ScreenContainer`, `SafeAreaContainer`, `PageTitle`, `PageHeader`, `StackPageHeader` (0.5.0) and their props types, `SectionLabel` (0.5.0), `SettingsSection`, `SettingsField`, `SettingsToggleRow`, `SettingsStack`, `MoreFromProjectV` and `FromProjectV` (0.8.0), `ScreenContainerProps`, `SettingsEmptyState`, `PinnedBotTile`, `BotPinGrid`, `ArtifactList` (0.12.0). Unreleased: `ThemeModePicker`, `THEME_MODES` and `ThemeMode`, the web theme tiles for an Appearance section (needs `react-native-svg`). `ScreenContainer` takes `refreshing`, `onRefresh` and `refreshControl` (0.12.0). `StackPageHeader` takes `centre` (0.12.0) | `expo-blur` (loader) |
|
|
93
93
|
| `@vvedantb/native-ui/marketing` | `UpgradeToProCard`, `PricingModal` and the pricing types | none |
|
|
94
94
|
| `@vvedantb/native-ui/ambient` | `AmbientBackground` | `expo-linear-gradient` (loader) |
|
|
95
95
|
| `@vvedantb/native-ui/blur`, `/haptics` | the loaders | `expo-blur`, `expo-haptics` (loaders) |
|
package/dist/UpdateChecker.jsx
CHANGED
|
@@ -2,7 +2,7 @@ import { c as _c } from "react/compiler-runtime";
|
|
|
2
2
|
import { useEffect, useRef, useState } from "react";
|
|
3
3
|
import { Linking } from "react-native";
|
|
4
4
|
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "./AlertDialog";
|
|
5
|
-
import { fetchGitHubUpdate } from "./updateCheck";
|
|
5
|
+
import { fetchGitHubUpdate, fetchVStoreUpdate } from "./updateCheck";
|
|
6
6
|
|
|
7
7
|
/** Opens the Updates tab of V Store, the Project V Android app store. */
|
|
8
8
|
export const V_STORE_UPDATES_URL = "vstore://updates";
|
|
@@ -221,7 +221,8 @@ async function readDismissed(storage, key) {
|
|
|
221
221
|
* Looks for a newer version once when it mounts and offers it in an
|
|
222
222
|
* `UpdatePrompt`. Mount it once, near the app root.
|
|
223
223
|
*
|
|
224
|
-
* - The check reads the GitHub releases of `source`,
|
|
224
|
+
* - The check reads the GitHub releases of `source`, asks V Store (`vStore`),
|
|
225
|
+
* or calls `check`.
|
|
225
226
|
* Offline, rate limited, a failed check or no `currentVersion`: nothing is
|
|
226
227
|
* offered, and nothing is shown.
|
|
227
228
|
* - Later (and Android back) hides that version until a newer one is out,
|
|
@@ -230,7 +231,7 @@ async function readDismissed(storage, key) {
|
|
|
230
231
|
* so it asks again at the next start if the update was not installed.
|
|
231
232
|
*/
|
|
232
233
|
export function UpdateChecker(t0) {
|
|
233
|
-
const $ = _c(
|
|
234
|
+
const $ = _c(50);
|
|
234
235
|
let check;
|
|
235
236
|
let currentVersion;
|
|
236
237
|
let onDownload;
|
|
@@ -241,10 +242,12 @@ export function UpdateChecker(t0) {
|
|
|
241
242
|
let storage;
|
|
242
243
|
let t1;
|
|
243
244
|
let t2;
|
|
245
|
+
let vStore;
|
|
244
246
|
if ($[0] !== t0) {
|
|
245
247
|
({
|
|
246
248
|
currentVersion,
|
|
247
249
|
source,
|
|
250
|
+
vStore,
|
|
248
251
|
check,
|
|
249
252
|
enabled: t1,
|
|
250
253
|
storage,
|
|
@@ -265,6 +268,7 @@ export function UpdateChecker(t0) {
|
|
|
265
268
|
$[8] = storage;
|
|
266
269
|
$[9] = t1;
|
|
267
270
|
$[10] = t2;
|
|
271
|
+
$[11] = vStore;
|
|
268
272
|
} else {
|
|
269
273
|
check = $[1];
|
|
270
274
|
currentVersion = $[2];
|
|
@@ -276,47 +280,55 @@ export function UpdateChecker(t0) {
|
|
|
276
280
|
storage = $[8];
|
|
277
281
|
t1 = $[9];
|
|
278
282
|
t2 = $[10];
|
|
283
|
+
vStore = $[11];
|
|
279
284
|
}
|
|
280
285
|
const enabled = t1 === undefined ? true : t1;
|
|
281
286
|
const storageKey = t2 === undefined ? "updateDismissed" : t2;
|
|
282
287
|
const [update, setUpdate] = useState(null);
|
|
283
288
|
let t3;
|
|
284
|
-
if ($[
|
|
289
|
+
if ($[12] !== check || $[13] !== storage || $[14] !== storageKey || $[15] !== vStore) {
|
|
285
290
|
t3 = {
|
|
286
291
|
check,
|
|
292
|
+
vStore,
|
|
287
293
|
storage,
|
|
288
294
|
storageKey
|
|
289
295
|
};
|
|
290
|
-
$[
|
|
291
|
-
$[
|
|
292
|
-
$[
|
|
293
|
-
$[
|
|
296
|
+
$[12] = check;
|
|
297
|
+
$[13] = storage;
|
|
298
|
+
$[14] = storageKey;
|
|
299
|
+
$[15] = vStore;
|
|
300
|
+
$[16] = t3;
|
|
294
301
|
} else {
|
|
295
|
-
t3 = $[
|
|
302
|
+
t3 = $[16];
|
|
296
303
|
}
|
|
297
304
|
const latest = useRef(t3);
|
|
298
305
|
let t4;
|
|
299
|
-
if ($[
|
|
306
|
+
if ($[17] !== check || $[18] !== storage || $[19] !== storageKey || $[20] !== vStore) {
|
|
300
307
|
t4 = () => {
|
|
301
308
|
latest.current = {
|
|
302
309
|
check,
|
|
310
|
+
vStore,
|
|
303
311
|
storage,
|
|
304
312
|
storageKey
|
|
305
313
|
};
|
|
306
314
|
};
|
|
307
|
-
$[
|
|
308
|
-
$[
|
|
309
|
-
$[
|
|
310
|
-
$[
|
|
315
|
+
$[17] = check;
|
|
316
|
+
$[18] = storage;
|
|
317
|
+
$[19] = storageKey;
|
|
318
|
+
$[20] = vStore;
|
|
319
|
+
$[21] = t4;
|
|
311
320
|
} else {
|
|
312
|
-
t4 = $[
|
|
321
|
+
t4 = $[21];
|
|
313
322
|
}
|
|
314
323
|
useEffect(t4);
|
|
315
324
|
const repo = source?.repo;
|
|
316
325
|
const tagPrefix = source?.tagPrefix;
|
|
317
326
|
const hasCheck = check !== undefined;
|
|
327
|
+
const vStorePackage = vStore?.packageName;
|
|
328
|
+
const vStoreSite = vStore?.siteUrl;
|
|
329
|
+
const vStoreUrl = prompt.vStoreUrl ?? V_STORE_UPDATES_URL;
|
|
318
330
|
let t5;
|
|
319
|
-
if ($[
|
|
331
|
+
if ($[22] !== currentVersion || $[23] !== enabled || $[24] !== repo || $[25] !== tagPrefix || $[26] !== vStoreUrl) {
|
|
320
332
|
t5 = () => {
|
|
321
333
|
if (!enabled || !currentVersion) {
|
|
322
334
|
return;
|
|
@@ -325,10 +337,11 @@ export function UpdateChecker(t0) {
|
|
|
325
337
|
const run = async () => {
|
|
326
338
|
const {
|
|
327
339
|
check: custom,
|
|
340
|
+
vStore: vStoreSource,
|
|
328
341
|
storage: store,
|
|
329
342
|
storageKey: key
|
|
330
343
|
} = latest.current;
|
|
331
|
-
const found = custom ? await custom(currentVersion) : repo !== undefined && tagPrefix !== undefined ? await fetchGitHubUpdate({
|
|
344
|
+
const found = custom ? await custom(currentVersion) : vStoreSource ? await fetchVStoreUpdate(vStoreSource, currentVersion, vStoreUrl) : repo !== undefined && tagPrefix !== undefined ? await fetchGitHubUpdate({
|
|
332
345
|
repo,
|
|
333
346
|
tagPrefix
|
|
334
347
|
}, currentVersion) : null;
|
|
@@ -345,30 +358,35 @@ export function UpdateChecker(t0) {
|
|
|
345
358
|
cancelled = true;
|
|
346
359
|
};
|
|
347
360
|
};
|
|
348
|
-
$[
|
|
349
|
-
$[
|
|
350
|
-
$[
|
|
351
|
-
$[
|
|
352
|
-
$[
|
|
361
|
+
$[22] = currentVersion;
|
|
362
|
+
$[23] = enabled;
|
|
363
|
+
$[24] = repo;
|
|
364
|
+
$[25] = tagPrefix;
|
|
365
|
+
$[26] = vStoreUrl;
|
|
366
|
+
$[27] = t5;
|
|
353
367
|
} else {
|
|
354
|
-
t5 = $[
|
|
368
|
+
t5 = $[27];
|
|
355
369
|
}
|
|
356
370
|
let t6;
|
|
357
|
-
if ($[
|
|
358
|
-
t6 = [enabled, currentVersion, repo, tagPrefix, hasCheck];
|
|
359
|
-
$[
|
|
360
|
-
$[
|
|
361
|
-
$[
|
|
362
|
-
$[
|
|
363
|
-
$[
|
|
364
|
-
$[
|
|
371
|
+
if ($[28] !== currentVersion || $[29] !== enabled || $[30] !== hasCheck || $[31] !== repo || $[32] !== tagPrefix || $[33] !== vStorePackage || $[34] !== vStoreSite || $[35] !== vStoreUrl) {
|
|
372
|
+
t6 = [enabled, currentVersion, repo, tagPrefix, hasCheck, vStorePackage, vStoreSite, vStoreUrl];
|
|
373
|
+
$[28] = currentVersion;
|
|
374
|
+
$[29] = enabled;
|
|
375
|
+
$[30] = hasCheck;
|
|
376
|
+
$[31] = repo;
|
|
377
|
+
$[32] = tagPrefix;
|
|
378
|
+
$[33] = vStorePackage;
|
|
379
|
+
$[34] = vStoreSite;
|
|
380
|
+
$[35] = vStoreUrl;
|
|
381
|
+
$[36] = t6;
|
|
365
382
|
} else {
|
|
366
|
-
t6 = $[
|
|
383
|
+
t6 = $[36];
|
|
367
384
|
}
|
|
368
385
|
useEffect(t5, t6);
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
386
|
+
const t7 = prompt.showDownload ?? !(vStore !== undefined && vStore.downloadUrl === undefined);
|
|
387
|
+
let t8;
|
|
388
|
+
if ($[37] !== onLater) {
|
|
389
|
+
t8 = current => {
|
|
372
390
|
setUpdate(null);
|
|
373
391
|
const {
|
|
374
392
|
storage: store_0,
|
|
@@ -379,46 +397,47 @@ export function UpdateChecker(t0) {
|
|
|
379
397
|
}
|
|
380
398
|
onLater?.(current);
|
|
381
399
|
};
|
|
382
|
-
$[
|
|
383
|
-
$[
|
|
400
|
+
$[37] = onLater;
|
|
401
|
+
$[38] = t8;
|
|
384
402
|
} else {
|
|
385
|
-
|
|
403
|
+
t8 = $[38];
|
|
386
404
|
}
|
|
387
|
-
let
|
|
388
|
-
if ($[
|
|
389
|
-
|
|
405
|
+
let t9;
|
|
406
|
+
if ($[39] !== onDownload) {
|
|
407
|
+
t9 = current_0 => {
|
|
390
408
|
setUpdate(null);
|
|
391
409
|
onDownload?.(current_0);
|
|
392
410
|
};
|
|
393
|
-
$[
|
|
394
|
-
$[
|
|
411
|
+
$[39] = onDownload;
|
|
412
|
+
$[40] = t9;
|
|
395
413
|
} else {
|
|
396
|
-
|
|
414
|
+
t9 = $[40];
|
|
397
415
|
}
|
|
398
|
-
let
|
|
399
|
-
if ($[
|
|
400
|
-
|
|
416
|
+
let t10;
|
|
417
|
+
if ($[41] !== onOpenVStore) {
|
|
418
|
+
t10 = current_1 => {
|
|
401
419
|
setUpdate(null);
|
|
402
420
|
onOpenVStore?.(current_1);
|
|
403
421
|
};
|
|
404
|
-
$[
|
|
405
|
-
$[
|
|
422
|
+
$[41] = onOpenVStore;
|
|
423
|
+
$[42] = t10;
|
|
406
424
|
} else {
|
|
407
|
-
|
|
425
|
+
t10 = $[42];
|
|
408
426
|
}
|
|
409
|
-
let
|
|
410
|
-
if ($[
|
|
411
|
-
|
|
412
|
-
$[
|
|
413
|
-
$[
|
|
414
|
-
$[
|
|
415
|
-
$[
|
|
416
|
-
$[
|
|
417
|
-
$[
|
|
427
|
+
let t11;
|
|
428
|
+
if ($[43] !== prompt || $[44] !== t10 || $[45] !== t7 || $[46] !== t8 || $[47] !== t9 || $[48] !== update) {
|
|
429
|
+
t11 = <UpdatePrompt {...prompt} showDownload={t7} update={update} onLater={t8} onDownload={t9} onOpenVStore={t10} />;
|
|
430
|
+
$[43] = prompt;
|
|
431
|
+
$[44] = t10;
|
|
432
|
+
$[45] = t7;
|
|
433
|
+
$[46] = t8;
|
|
434
|
+
$[47] = t9;
|
|
435
|
+
$[48] = update;
|
|
436
|
+
$[49] = t11;
|
|
418
437
|
} else {
|
|
419
|
-
|
|
438
|
+
t11 = $[49];
|
|
420
439
|
}
|
|
421
|
-
return
|
|
440
|
+
return t11;
|
|
422
441
|
}
|
|
423
442
|
function _temp3() {}
|
|
424
443
|
function _temp2() {}
|
package/dist/entries/layout.js
CHANGED
|
@@ -10,6 +10,7 @@ export { SettingsField } from "../settings/SettingsField";
|
|
|
10
10
|
export { SettingsToggleRow } from "../settings/SettingsToggleRow";
|
|
11
11
|
export { SettingsStack } from "../settings/SettingsStack";
|
|
12
12
|
export { SettingsEmptyState } from "../settings/SettingsEmptyState";
|
|
13
|
+
export { ThemeModePicker, THEME_MODES } from "../settings/ThemeModePicker";
|
|
13
14
|
export { PinnedBotTile, BotPinGrid } from "../PinnedBotTile";
|
|
14
15
|
export { ArtifactList } from "../ArtifactList";
|
|
15
16
|
export { MoreFromProjectV, FromProjectV } from "../settings/MoreFromProjectV";
|
package/dist/index.js
CHANGED
|
@@ -64,7 +64,7 @@ export { ConfirmDialog } from "./ConfirmDialog";
|
|
|
64
64
|
export { BulkActionBar, BULK_BAR_LABEL_MIN_WIDTH } from "./BulkActionBar";
|
|
65
65
|
export { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuLabel, DropdownMenuItem, DropdownMenuRadioItem, DropdownMenuSeparator } from "./DropdownMenu";
|
|
66
66
|
export { UpdateChecker, UpdatePrompt, V_STORE_UPDATES_URL } from "./UpdateChecker";
|
|
67
|
-
export { fetchGitHubUpdate, isNewerVersion, newerGitHubRelease } from "./updateCheck";
|
|
67
|
+
export { fetchGitHubUpdate, fetchVStoreUpdate, isNewerVersion, newerGitHubRelease, V_STORE_SITE_URL } from "./updateCheck";
|
|
68
68
|
export { Sheet, SheetTrigger, SheetClose, SheetContent, SheetHandle, SheetHeader, SheetTitle, SheetDescription, SheetBody, SheetFooter } from "./Sheet";
|
|
69
69
|
export { Toaster } from "./Toast";
|
|
70
70
|
export { toast } from "./toastStore";
|
|
@@ -79,6 +79,7 @@ export { SettingsField } from "./settings/SettingsField";
|
|
|
79
79
|
export { SettingsToggleRow } from "./settings/SettingsToggleRow";
|
|
80
80
|
export { SettingsStack } from "./settings/SettingsStack";
|
|
81
81
|
export { SettingsEmptyState } from "./settings/SettingsEmptyState";
|
|
82
|
+
export { ThemeModePicker, THEME_MODES } from "./settings/ThemeModePicker";
|
|
82
83
|
export { PinnedBotTile, BotPinGrid } from "./PinnedBotTile";
|
|
83
84
|
export { ArtifactList } from "./ArtifactList";
|
|
84
85
|
export { MoreFromProjectV, FromProjectV } from "./settings/MoreFromProjectV";
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { c as _c } from "react/compiler-runtime";
|
|
2
|
+
import { IconCheck, IconCircleHalf, IconDeviceDesktop, IconMoon, IconSun } from "@tabler/icons-react-native";
|
|
3
|
+
import { Pressable, StyleSheet, Text, View } from "react-native";
|
|
4
|
+
import Svg, { Defs, LinearGradient, Rect, Stop } from "react-native-svg";
|
|
5
|
+
import { cn } from "../cn";
|
|
6
|
+
import { sizeStyle, typeStyle } from "../controlStyles";
|
|
7
|
+
import { palette, withAlpha } from "../palette";
|
|
8
|
+
import { useLargerText } from "../theme";
|
|
9
|
+
import { tokens } from "../tokens";
|
|
10
|
+
import { useScheme } from "../useScheme";
|
|
11
|
+
|
|
12
|
+
/** A theme the picker can show, as the web `ThemeModePicker`. Neutral is the dark scheme with a grey palette. */
|
|
13
|
+
|
|
14
|
+
/** Default order: light to dark, then system. */
|
|
15
|
+
export const THEME_MODES = ["light", "neutral", "dark", "system"];
|
|
16
|
+
const LABELS = {
|
|
17
|
+
light: "Light",
|
|
18
|
+
neutral: "Neutral",
|
|
19
|
+
dark: "Dark",
|
|
20
|
+
system: "System"
|
|
21
|
+
};
|
|
22
|
+
const ICONS = {
|
|
23
|
+
light: IconSun,
|
|
24
|
+
neutral: IconCircleHalf,
|
|
25
|
+
dark: IconMoon,
|
|
26
|
+
system: IconDeviceDesktop
|
|
27
|
+
};
|
|
28
|
+
/** Web `bg-zinc-900`. */
|
|
29
|
+
const ZINC_900 = "#18181b";
|
|
30
|
+
// Swatches and icons show the theme itself, so they use the web's fixed colours, not tokens.
|
|
31
|
+
// System has no swatch colour (it is a gradient) and a muted icon.
|
|
32
|
+
const SWATCHES = {
|
|
33
|
+
light: "#ffffff",
|
|
34
|
+
neutral: "#3f3f46",
|
|
35
|
+
dark: ZINC_900,
|
|
36
|
+
system: null
|
|
37
|
+
};
|
|
38
|
+
const ICON_COLOURS = {
|
|
39
|
+
light: "#f59e0b",
|
|
40
|
+
neutral: "#d4d4d8",
|
|
41
|
+
dark: "#93c5fd",
|
|
42
|
+
system: null
|
|
43
|
+
};
|
|
44
|
+
/** The web System swatch, `bg-linear-to-br from-white to-zinc-900`. */
|
|
45
|
+
function GradientSwatch() {
|
|
46
|
+
const $ = _c(1);
|
|
47
|
+
let t0;
|
|
48
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
49
|
+
t0 = <Svg width="100%" height="100%" style={StyleSheet.absoluteFill}><Defs><LinearGradient id="theme-mode-system" x1="0" y1="0" x2="1" y2="1"><Stop offset="0" stopColor="#ffffff" /><Stop offset="1" stopColor={ZINC_900} /></LinearGradient></Defs><Rect width="100%" height="100%" fill="url(#theme-mode-system)" /></Svg>;
|
|
50
|
+
$[0] = t0;
|
|
51
|
+
} else {
|
|
52
|
+
t0 = $[0];
|
|
53
|
+
}
|
|
54
|
+
return t0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Theme tiles for an Appearance settings section, as the web
|
|
59
|
+
* `ThemeModePicker`: a swatch with the theme icon over the label, in one row
|
|
60
|
+
* that the tiles share evenly. The selected tile gets the border, a primary
|
|
61
|
+
* wash and a check badge. The app owns the stored mode and how Neutral paints.
|
|
62
|
+
*/
|
|
63
|
+
export function ThemeModePicker(t0) {
|
|
64
|
+
const $ = _c(18);
|
|
65
|
+
const {
|
|
66
|
+
value,
|
|
67
|
+
onChange,
|
|
68
|
+
modes: t1,
|
|
69
|
+
className,
|
|
70
|
+
testID
|
|
71
|
+
} = t0;
|
|
72
|
+
const modes = t1 === undefined ? THEME_MODES : t1;
|
|
73
|
+
const scheme = useScheme();
|
|
74
|
+
const largerText = useLargerText();
|
|
75
|
+
const labelSize = largerText ? "text-base" : "text-sm";
|
|
76
|
+
let t2;
|
|
77
|
+
if ($[0] !== className) {
|
|
78
|
+
t2 = cn("flex-row gap-2", className);
|
|
79
|
+
$[0] = className;
|
|
80
|
+
$[1] = t2;
|
|
81
|
+
} else {
|
|
82
|
+
t2 = $[1];
|
|
83
|
+
}
|
|
84
|
+
let t3;
|
|
85
|
+
if ($[2] !== labelSize || $[3] !== modes || $[4] !== onChange || $[5] !== scheme || $[6] !== testID || $[7] !== value) {
|
|
86
|
+
let t4;
|
|
87
|
+
if ($[9] !== labelSize || $[10] !== onChange || $[11] !== scheme || $[12] !== testID || $[13] !== value) {
|
|
88
|
+
t4 = mode => {
|
|
89
|
+
const active = value === mode;
|
|
90
|
+
const Icon = ICONS[mode];
|
|
91
|
+
const swatch = SWATCHES[mode];
|
|
92
|
+
return <Pressable key={mode} testID={testID ? `${testID}-${mode}` : undefined} accessibilityRole="radio" accessibilityLabel={LABELS[mode]} accessibilityState={{
|
|
93
|
+
checked: active
|
|
94
|
+
}} onPress={() => onChange(mode)} className="flex-1 items-center gap-2 rounded-2xl border px-1 py-3 active:opacity-80" style={{
|
|
95
|
+
borderColor: active ? tokens.color.border[scheme] : "transparent",
|
|
96
|
+
backgroundColor: active ? withAlpha(palette.primary[scheme], 0.08) : withAlpha(tokens.color.surfaceSecondary[scheme], 0.4)
|
|
97
|
+
}}><View className="mx-2 h-12 items-center justify-center self-stretch overflow-hidden rounded-2xl" style={swatch ? {
|
|
98
|
+
backgroundColor: swatch
|
|
99
|
+
} : undefined}>{swatch ? null : <GradientSwatch />}<View className="absolute inset-0 items-center justify-center"><Icon size={22} color={ICON_COLOURS[mode] ?? tokens.color.muted[scheme]} /></View></View>{active ? <View className="absolute right-2 top-2 h-4 w-4 items-center justify-center rounded-full" style={{
|
|
100
|
+
backgroundColor: palette.primary[scheme]
|
|
101
|
+
}}><IconCheck size={10} strokeWidth={3} color={palette.primaryForeground[scheme]} /></View> : null}<Text numberOfLines={1} adjustsFontSizeToFit={true} className={cn("font-instrument-sans-medium", labelSize)} style={[sizeStyle(labelSize), typeStyle("medium"), {
|
|
102
|
+
color: active ? palette.primary[scheme] : tokens.color.muted[scheme]
|
|
103
|
+
}]}>{LABELS[mode]}</Text></Pressable>;
|
|
104
|
+
};
|
|
105
|
+
$[9] = labelSize;
|
|
106
|
+
$[10] = onChange;
|
|
107
|
+
$[11] = scheme;
|
|
108
|
+
$[12] = testID;
|
|
109
|
+
$[13] = value;
|
|
110
|
+
$[14] = t4;
|
|
111
|
+
} else {
|
|
112
|
+
t4 = $[14];
|
|
113
|
+
}
|
|
114
|
+
t3 = modes.map(t4);
|
|
115
|
+
$[2] = labelSize;
|
|
116
|
+
$[3] = modes;
|
|
117
|
+
$[4] = onChange;
|
|
118
|
+
$[5] = scheme;
|
|
119
|
+
$[6] = testID;
|
|
120
|
+
$[7] = value;
|
|
121
|
+
$[8] = t3;
|
|
122
|
+
} else {
|
|
123
|
+
t3 = $[8];
|
|
124
|
+
}
|
|
125
|
+
let t4;
|
|
126
|
+
if ($[15] !== t2 || $[16] !== t3) {
|
|
127
|
+
t4 = <View accessibilityRole="radiogroup" accessibilityLabel="Theme" className={t2}>{t3}</View>;
|
|
128
|
+
$[15] = t2;
|
|
129
|
+
$[16] = t3;
|
|
130
|
+
$[17] = t4;
|
|
131
|
+
} else {
|
|
132
|
+
t4 = $[17];
|
|
133
|
+
}
|
|
134
|
+
return t4;
|
|
135
|
+
}
|
package/dist/updateCheck.js
CHANGED
|
@@ -77,3 +77,35 @@ export async function fetchGitHubUpdate(source, currentVersion) {
|
|
|
77
77
|
if (!Array.isArray(body) || !body.every(isRelease)) return null;
|
|
78
78
|
return newerGitHubRelease(body, currentVersion, source.tagPrefix);
|
|
79
79
|
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The HTTP host of V Store, the Project V Android app store. Its
|
|
83
|
+
* `GET /latest-version?package=<Android package>` answers
|
|
84
|
+
* `{ packageName, versionName }` for an app in its catalogue.
|
|
85
|
+
*/
|
|
86
|
+
export const V_STORE_SITE_URL = "https://blessed-porcupine-303.eu-west-1.convex.site";
|
|
87
|
+
/**
|
|
88
|
+
* Asks V Store for the app's newest version and returns it when it is newer
|
|
89
|
+
* than `currentVersion`, else null. V Store knows the releases of private
|
|
90
|
+
* repositories too, so this works where `fetchGitHubUpdate` cannot. Null too
|
|
91
|
+
* when the app is not in the catalogue, the request fails, or the answer has
|
|
92
|
+
* another shape. A network error rejects. Without `downloadUrl`, `url` is
|
|
93
|
+
* `fallbackUrl`.
|
|
94
|
+
*/
|
|
95
|
+
export async function fetchVStoreUpdate(source, currentVersion, fallbackUrl) {
|
|
96
|
+
const site = source.siteUrl ?? V_STORE_SITE_URL;
|
|
97
|
+
const response = await fetch(`${site}/latest-version?package=${encodeURIComponent(source.packageName)}`, {
|
|
98
|
+
headers: {
|
|
99
|
+
Accept: "application/json"
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
if (!response.ok) return null;
|
|
103
|
+
const body = await response.json();
|
|
104
|
+
if (!body || typeof body !== "object") return null;
|
|
105
|
+
const version = body.versionName;
|
|
106
|
+
if (typeof version !== "string" || !isNewerVersion(version, currentVersion)) return null;
|
|
107
|
+
return {
|
|
108
|
+
version,
|
|
109
|
+
url: source.downloadUrl?.(version) ?? fallbackUrl
|
|
110
|
+
};
|
|
111
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/native-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Shared React Native / Expo UI primitives. Floating surfaces, forms, overlays, toasts, settings chrome, tab bar, AI chat parts, the family app marks, a NativeWind preset, the Expo web root and Clerk + Convex auth screens.",
|
|
6
6
|
"type": "module",
|
package/src/UpdateChecker.tsx
CHANGED
|
@@ -10,7 +10,13 @@ import {
|
|
|
10
10
|
AlertDialogHeader,
|
|
11
11
|
AlertDialogTitle,
|
|
12
12
|
} from "./AlertDialog";
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
fetchGitHubUpdate,
|
|
15
|
+
fetchVStoreUpdate,
|
|
16
|
+
type AvailableUpdate,
|
|
17
|
+
type GitHubReleaseSource,
|
|
18
|
+
type VStoreSource,
|
|
19
|
+
} from "./updateCheck";
|
|
14
20
|
|
|
15
21
|
/** Opens the Updates tab of V Store, the Project V Android app store. */
|
|
16
22
|
export const V_STORE_UPDATES_URL = "vstore://updates";
|
|
@@ -194,9 +200,15 @@ export type UpdateCheckerProps = Omit<
|
|
|
194
200
|
* a local or preview build that has no release to compare with.
|
|
195
201
|
*/
|
|
196
202
|
currentVersion: string | null | undefined;
|
|
197
|
-
/** GitHub releases to read: the repository and the tag prefix before the version. */
|
|
203
|
+
/** GitHub releases to read: the repository and the tag prefix before the version. Public repositories only. */
|
|
198
204
|
source?: GitHubReleaseSource;
|
|
199
|
-
/**
|
|
205
|
+
/**
|
|
206
|
+
* Ask V Store for the newest version, used instead of `source`. It works
|
|
207
|
+
* for a private repository too. Without `vStore.downloadUrl`, Download is
|
|
208
|
+
* hidden unless `showDownload` says otherwise.
|
|
209
|
+
*/
|
|
210
|
+
vStore?: VStoreSource;
|
|
211
|
+
/** Your own check, used instead of `source` and `vStore`. Returns the update to offer, or null. */
|
|
200
212
|
check?: (currentVersion: string) => Promise<AvailableUpdate | null>;
|
|
201
213
|
/** `false` skips the check. Default `true`. */
|
|
202
214
|
enabled?: boolean;
|
|
@@ -216,7 +228,8 @@ export type UpdateCheckerProps = Omit<
|
|
|
216
228
|
* Looks for a newer version once when it mounts and offers it in an
|
|
217
229
|
* `UpdatePrompt`. Mount it once, near the app root.
|
|
218
230
|
*
|
|
219
|
-
* - The check reads the GitHub releases of `source`,
|
|
231
|
+
* - The check reads the GitHub releases of `source`, asks V Store (`vStore`),
|
|
232
|
+
* or calls `check`.
|
|
220
233
|
* Offline, rate limited, a failed check or no `currentVersion`: nothing is
|
|
221
234
|
* offered, and nothing is shown.
|
|
222
235
|
* - Later (and Android back) hides that version until a newer one is out,
|
|
@@ -227,6 +240,7 @@ export type UpdateCheckerProps = Omit<
|
|
|
227
240
|
export function UpdateChecker({
|
|
228
241
|
currentVersion,
|
|
229
242
|
source,
|
|
243
|
+
vStore,
|
|
230
244
|
check,
|
|
231
245
|
enabled = true,
|
|
232
246
|
storage,
|
|
@@ -238,22 +252,28 @@ export function UpdateChecker({
|
|
|
238
252
|
}: UpdateCheckerProps) {
|
|
239
253
|
const [update, setUpdate] = useState<AvailableUpdate | null>(null);
|
|
240
254
|
// The latest callbacks, so a new function each render does not check again.
|
|
241
|
-
const latest = useRef({ check, storage, storageKey });
|
|
255
|
+
const latest = useRef({ check, vStore, storage, storageKey });
|
|
242
256
|
useEffect(() => {
|
|
243
|
-
latest.current = { check, storage, storageKey };
|
|
257
|
+
latest.current = { check, vStore, storage, storageKey };
|
|
244
258
|
});
|
|
245
259
|
|
|
246
260
|
const repo = source?.repo;
|
|
247
261
|
const tagPrefix = source?.tagPrefix;
|
|
248
262
|
const hasCheck = check !== undefined;
|
|
263
|
+
const vStorePackage = vStore?.packageName;
|
|
264
|
+
const vStoreSite = vStore?.siteUrl;
|
|
265
|
+
// Without a download link, the update's link is the one that opens V Store.
|
|
266
|
+
const vStoreUrl = prompt.vStoreUrl ?? V_STORE_UPDATES_URL;
|
|
249
267
|
useEffect(() => {
|
|
250
268
|
if (!enabled || !currentVersion) return;
|
|
251
269
|
let cancelled = false;
|
|
252
270
|
const run = async () => {
|
|
253
|
-
const { check: custom, storage: store, storageKey: key } = latest.current;
|
|
271
|
+
const { check: custom, vStore: vStoreSource, storage: store, storageKey: key } = latest.current;
|
|
254
272
|
const found = custom
|
|
255
273
|
? await custom(currentVersion)
|
|
256
|
-
:
|
|
274
|
+
: vStoreSource
|
|
275
|
+
? await fetchVStoreUpdate(vStoreSource, currentVersion, vStoreUrl)
|
|
276
|
+
: repo !== undefined && tagPrefix !== undefined
|
|
257
277
|
? await fetchGitHubUpdate({ repo, tagPrefix }, currentVersion)
|
|
258
278
|
: null;
|
|
259
279
|
if (!found) return;
|
|
@@ -265,11 +285,12 @@ export function UpdateChecker({
|
|
|
265
285
|
return () => {
|
|
266
286
|
cancelled = true;
|
|
267
287
|
};
|
|
268
|
-
}, [enabled, currentVersion, repo, tagPrefix, hasCheck]);
|
|
288
|
+
}, [enabled, currentVersion, repo, tagPrefix, hasCheck, vStorePackage, vStoreSite, vStoreUrl]);
|
|
269
289
|
|
|
270
290
|
return (
|
|
271
291
|
<UpdatePrompt
|
|
272
292
|
{...prompt}
|
|
293
|
+
showDownload={prompt.showDownload ?? !(vStore !== undefined && vStore.downloadUrl === undefined)}
|
|
273
294
|
update={update}
|
|
274
295
|
onLater={(current) => {
|
|
275
296
|
setUpdate(null);
|
package/src/entries/layout.ts
CHANGED
|
@@ -15,6 +15,8 @@ export { SettingsToggleRow } from "../settings/SettingsToggleRow";
|
|
|
15
15
|
export { SettingsStack } from "../settings/SettingsStack";
|
|
16
16
|
export { SettingsEmptyState } from "../settings/SettingsEmptyState";
|
|
17
17
|
export type { SettingsEmptyStateProps } from "../settings/SettingsEmptyState";
|
|
18
|
+
export { ThemeModePicker, THEME_MODES } from "../settings/ThemeModePicker";
|
|
19
|
+
export type { ThemeMode, ThemeModePickerProps } from "../settings/ThemeModePicker";
|
|
18
20
|
export { PinnedBotTile, BotPinGrid } from "../PinnedBotTile";
|
|
19
21
|
export type { PinnedBotTileProps, BotPinGridProps } from "../PinnedBotTile";
|
|
20
22
|
export { ArtifactList } from "../ArtifactList";
|
package/src/index.ts
CHANGED
|
@@ -191,8 +191,8 @@ export type {
|
|
|
191
191
|
export type { ConfirmDialogProps } from "./ConfirmDialog";
|
|
192
192
|
export { UpdateChecker, UpdatePrompt, V_STORE_UPDATES_URL } from "./UpdateChecker";
|
|
193
193
|
export type { UpdateCheckerProps, UpdateDismissStorage, UpdatePromptProps } from "./UpdateChecker";
|
|
194
|
-
export { fetchGitHubUpdate, isNewerVersion, newerGitHubRelease } from "./updateCheck";
|
|
195
|
-
export type { AvailableUpdate, GitHubRelease, GitHubReleaseSource } from "./updateCheck";
|
|
194
|
+
export { fetchGitHubUpdate, fetchVStoreUpdate, isNewerVersion, newerGitHubRelease, V_STORE_SITE_URL } from "./updateCheck";
|
|
195
|
+
export type { AvailableUpdate, GitHubRelease, GitHubReleaseSource, VStoreSource } from "./updateCheck";
|
|
196
196
|
export {
|
|
197
197
|
Sheet,
|
|
198
198
|
SheetTrigger,
|
|
@@ -225,6 +225,8 @@ export { SettingsToggleRow } from "./settings/SettingsToggleRow";
|
|
|
225
225
|
export { SettingsStack } from "./settings/SettingsStack";
|
|
226
226
|
export { SettingsEmptyState } from "./settings/SettingsEmptyState";
|
|
227
227
|
export type { SettingsEmptyStateProps } from "./settings/SettingsEmptyState";
|
|
228
|
+
export { ThemeModePicker, THEME_MODES } from "./settings/ThemeModePicker";
|
|
229
|
+
export type { ThemeMode, ThemeModePickerProps } from "./settings/ThemeModePicker";
|
|
228
230
|
export { PinnedBotTile, BotPinGrid } from "./PinnedBotTile";
|
|
229
231
|
export type { PinnedBotTileProps, BotPinGridProps } from "./PinnedBotTile";
|
|
230
232
|
export { ArtifactList } from "./ArtifactList";
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { IconCheck, IconCircleHalf, IconDeviceDesktop, IconMoon, IconSun } from "@tabler/icons-react-native";
|
|
2
|
+
import { Pressable, StyleSheet, Text, View } from "react-native";
|
|
3
|
+
import Svg, { Defs, LinearGradient, Rect, Stop } from "react-native-svg";
|
|
4
|
+
import { cn } from "../cn";
|
|
5
|
+
import { sizeStyle, typeStyle } from "../controlStyles";
|
|
6
|
+
import { palette, withAlpha } from "../palette";
|
|
7
|
+
import { useLargerText } from "../theme";
|
|
8
|
+
import { tokens } from "../tokens";
|
|
9
|
+
import { useScheme } from "../useScheme";
|
|
10
|
+
|
|
11
|
+
/** A theme the picker can show, as the web `ThemeModePicker`. Neutral is the dark scheme with a grey palette. */
|
|
12
|
+
export type ThemeMode = "light" | "neutral" | "dark" | "system";
|
|
13
|
+
|
|
14
|
+
/** Default order: light to dark, then system. */
|
|
15
|
+
export const THEME_MODES = ["light", "neutral", "dark", "system"] as const satisfies readonly ThemeMode[];
|
|
16
|
+
|
|
17
|
+
const LABELS: Record<ThemeMode, string> = { light: "Light", neutral: "Neutral", dark: "Dark", system: "System" };
|
|
18
|
+
const ICONS = { light: IconSun, neutral: IconCircleHalf, dark: IconMoon, system: IconDeviceDesktop };
|
|
19
|
+
/** Web `bg-zinc-900`. */
|
|
20
|
+
const ZINC_900 = "#18181b";
|
|
21
|
+
// Swatches and icons show the theme itself, so they use the web's fixed colours, not tokens.
|
|
22
|
+
// System has no swatch colour (it is a gradient) and a muted icon.
|
|
23
|
+
const SWATCHES: Record<ThemeMode, string | null> = {
|
|
24
|
+
light: "#ffffff",
|
|
25
|
+
neutral: "#3f3f46",
|
|
26
|
+
dark: ZINC_900,
|
|
27
|
+
system: null,
|
|
28
|
+
};
|
|
29
|
+
const ICON_COLOURS: Record<ThemeMode, string | null> = {
|
|
30
|
+
light: "#f59e0b",
|
|
31
|
+
neutral: "#d4d4d8",
|
|
32
|
+
dark: "#93c5fd",
|
|
33
|
+
system: null,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type ThemeModePickerProps = {
|
|
37
|
+
/** The stored choice, not the resolved scheme. */
|
|
38
|
+
value: string | undefined;
|
|
39
|
+
onChange: (mode: ThemeMode) => void;
|
|
40
|
+
/** Themes to show, in order. Default `THEME_MODES`. */
|
|
41
|
+
modes?: readonly ThemeMode[];
|
|
42
|
+
className?: string;
|
|
43
|
+
/** Each tile gets `${testID}-${mode}`. */
|
|
44
|
+
testID?: string;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** The web System swatch, `bg-linear-to-br from-white to-zinc-900`. */
|
|
48
|
+
function GradientSwatch() {
|
|
49
|
+
return (
|
|
50
|
+
// Sized by props: an unsized Svg is 300 wide and widens the tile.
|
|
51
|
+
<Svg width="100%" height="100%" style={StyleSheet.absoluteFill}>
|
|
52
|
+
<Defs>
|
|
53
|
+
<LinearGradient id="theme-mode-system" x1="0" y1="0" x2="1" y2="1">
|
|
54
|
+
<Stop offset="0" stopColor="#ffffff" />
|
|
55
|
+
<Stop offset="1" stopColor={ZINC_900} />
|
|
56
|
+
</LinearGradient>
|
|
57
|
+
</Defs>
|
|
58
|
+
<Rect width="100%" height="100%" fill="url(#theme-mode-system)" />
|
|
59
|
+
</Svg>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Theme tiles for an Appearance settings section, as the web
|
|
65
|
+
* `ThemeModePicker`: a swatch with the theme icon over the label, in one row
|
|
66
|
+
* that the tiles share evenly. The selected tile gets the border, a primary
|
|
67
|
+
* wash and a check badge. The app owns the stored mode and how Neutral paints.
|
|
68
|
+
*/
|
|
69
|
+
export function ThemeModePicker({ value, onChange, modes = THEME_MODES, className, testID }: ThemeModePickerProps) {
|
|
70
|
+
const scheme = useScheme();
|
|
71
|
+
const largerText = useLargerText();
|
|
72
|
+
const labelSize = largerText ? "text-base" : "text-sm";
|
|
73
|
+
return (
|
|
74
|
+
<View accessibilityRole="radiogroup" accessibilityLabel="Theme" className={cn("flex-row gap-2", className)}>
|
|
75
|
+
{modes.map((mode) => {
|
|
76
|
+
const active = value === mode;
|
|
77
|
+
const Icon = ICONS[mode];
|
|
78
|
+
const swatch = SWATCHES[mode];
|
|
79
|
+
return (
|
|
80
|
+
<Pressable
|
|
81
|
+
key={mode}
|
|
82
|
+
testID={testID ? `${testID}-${mode}` : undefined}
|
|
83
|
+
accessibilityRole="radio"
|
|
84
|
+
accessibilityLabel={LABELS[mode]}
|
|
85
|
+
accessibilityState={{ checked: active }}
|
|
86
|
+
onPress={() => onChange(mode)}
|
|
87
|
+
className="flex-1 items-center gap-2 rounded-2xl border px-1 py-3 active:opacity-80"
|
|
88
|
+
style={{
|
|
89
|
+
borderColor: active ? tokens.color.border[scheme] : "transparent",
|
|
90
|
+
backgroundColor: active
|
|
91
|
+
? withAlpha(palette.primary[scheme], 0.08)
|
|
92
|
+
: withAlpha(tokens.color.surfaceSecondary[scheme], 0.4),
|
|
93
|
+
}}
|
|
94
|
+
>
|
|
95
|
+
<View
|
|
96
|
+
className="mx-2 h-12 items-center justify-center self-stretch overflow-hidden rounded-2xl"
|
|
97
|
+
style={swatch ? { backgroundColor: swatch } : undefined}
|
|
98
|
+
>
|
|
99
|
+
{swatch ? null : <GradientSwatch />}
|
|
100
|
+
{/* Positioned, so the web build paints it over the positioned gradient. */}
|
|
101
|
+
<View className="absolute inset-0 items-center justify-center">
|
|
102
|
+
<Icon size={22} color={ICON_COLOURS[mode] ?? tokens.color.muted[scheme]} />
|
|
103
|
+
</View>
|
|
104
|
+
</View>
|
|
105
|
+
{/* After the swatch, so it draws over the swatch corner. */}
|
|
106
|
+
{active ? (
|
|
107
|
+
<View
|
|
108
|
+
className="absolute right-2 top-2 h-4 w-4 items-center justify-center rounded-full"
|
|
109
|
+
style={{ backgroundColor: palette.primary[scheme] }}
|
|
110
|
+
>
|
|
111
|
+
<IconCheck size={10} strokeWidth={3} color={palette.primaryForeground[scheme]} />
|
|
112
|
+
</View>
|
|
113
|
+
) : null}
|
|
114
|
+
{/* On a narrow phone at a large font scale, "Neutral" shrinks to fit, not wraps. */}
|
|
115
|
+
<Text
|
|
116
|
+
numberOfLines={1}
|
|
117
|
+
adjustsFontSizeToFit
|
|
118
|
+
className={cn("font-instrument-sans-medium", labelSize)}
|
|
119
|
+
style={[
|
|
120
|
+
sizeStyle(labelSize),
|
|
121
|
+
typeStyle("medium"),
|
|
122
|
+
{ color: active ? palette.primary[scheme] : tokens.color.muted[scheme] },
|
|
123
|
+
]}
|
|
124
|
+
>
|
|
125
|
+
{LABELS[mode]}
|
|
126
|
+
</Text>
|
|
127
|
+
</Pressable>
|
|
128
|
+
);
|
|
129
|
+
})}
|
|
130
|
+
</View>
|
|
131
|
+
);
|
|
132
|
+
}
|
package/src/updateCheck.ts
CHANGED
|
@@ -101,3 +101,48 @@ export async function fetchGitHubUpdate(
|
|
|
101
101
|
if (!Array.isArray(body) || !body.every(isRelease)) return null;
|
|
102
102
|
return newerGitHubRelease(body, currentVersion, source.tagPrefix);
|
|
103
103
|
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The HTTP host of V Store, the Project V Android app store. Its
|
|
107
|
+
* `GET /latest-version?package=<Android package>` answers
|
|
108
|
+
* `{ packageName, versionName }` for an app in its catalogue.
|
|
109
|
+
*/
|
|
110
|
+
export const V_STORE_SITE_URL = "https://blessed-porcupine-303.eu-west-1.convex.site";
|
|
111
|
+
|
|
112
|
+
export type VStoreSource = {
|
|
113
|
+
/** The app's Android package, as V Store lists it. */
|
|
114
|
+
packageName: string;
|
|
115
|
+
/**
|
|
116
|
+
* What Download opens for a version: the APK, or its release page. Leave it
|
|
117
|
+
* out when the APK has no public link (a private repository). Download is
|
|
118
|
+
* then hidden, and "Install from V Store" is the one way to update.
|
|
119
|
+
*/
|
|
120
|
+
downloadUrl?: (version: string) => string;
|
|
121
|
+
/** Default `V_STORE_SITE_URL`. */
|
|
122
|
+
siteUrl?: string;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Asks V Store for the app's newest version and returns it when it is newer
|
|
127
|
+
* than `currentVersion`, else null. V Store knows the releases of private
|
|
128
|
+
* repositories too, so this works where `fetchGitHubUpdate` cannot. Null too
|
|
129
|
+
* when the app is not in the catalogue, the request fails, or the answer has
|
|
130
|
+
* another shape. A network error rejects. Without `downloadUrl`, `url` is
|
|
131
|
+
* `fallbackUrl`.
|
|
132
|
+
*/
|
|
133
|
+
export async function fetchVStoreUpdate(
|
|
134
|
+
source: VStoreSource,
|
|
135
|
+
currentVersion: string,
|
|
136
|
+
fallbackUrl: string,
|
|
137
|
+
): Promise<AvailableUpdate | null> {
|
|
138
|
+
const site = source.siteUrl ?? V_STORE_SITE_URL;
|
|
139
|
+
const response = await fetch(`${site}/latest-version?package=${encodeURIComponent(source.packageName)}`, {
|
|
140
|
+
headers: { Accept: "application/json" },
|
|
141
|
+
});
|
|
142
|
+
if (!response.ok) return null;
|
|
143
|
+
const body: unknown = await response.json();
|
|
144
|
+
if (!body || typeof body !== "object") return null;
|
|
145
|
+
const version = (body as Record<string, unknown>).versionName;
|
|
146
|
+
if (typeof version !== "string" || !isNewerVersion(version, currentVersion)) return null;
|
|
147
|
+
return { version, url: source.downloadUrl?.(version) ?? fallbackUrl };
|
|
148
|
+
}
|