@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
tsx 162 lines 5.75 KB
Raw
1 import { T, useGT } from "gt-react-native";
2 import * as Dialog from "../../components/ui/Dialog";
3 import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
4 import * as Application from "expo-application";
5 import Constants from "expo-constants";
6 import { settlePromise } from "@t3tools/client-runtime/state/runtime";
7 import { useRef, useState } from "react";
8 import { Pressable, View } from "react-native";
9 import { useSafeAreaInsets } from "react-native-safe-area-context";
10
11 import { AppText as Text } from "../../components/ui/AppText";
12 import { SymbolView } from "../../components/ui/AppSymbol";
13 import { useDeadlinePassed } from "../../lib/clock";
14 import {
15 type AppUpdateCheckState,
16 isAppUpdateCheckAvailable,
17 registerHiddenUpdateTap,
18 runAppUpdateCheck,
19 } from "../updates/app-updates";
20 import { SettingsRow } from "./components/SettingsRow";
21 import { SettingsSection } from "./components/SettingsSection";
22 import { SettingsScreen } from "./components/SettingsScreen";
23
24 export function SettingsAboutRouteScreen() {
25 const gt = useGT();
26 const insets = useSafeAreaInsets();
27
28 return (
29 <SettingsScreen title={gt("About")}>
30 <ScrollView
31 contentInsetAdjustmentBehavior="automatic"
32 showsVerticalScrollIndicator={false}
33 className="flex-1"
34 contentContainerClassName="gap-6 px-5 pt-4"
35 contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }}
36 >
37 <AppSettingsSection />
38 </ScrollView>
39 </SettingsScreen>
40 );
41 }
42
43 function AppSettingsSection() {
44 const gt = useGT();
45 const [checkState, setCheckState] = useState<{
46 readonly state: AppUpdateCheckState;
47 // "Up to date" is a confirmation that fades back to idle.
48 readonly settledUntil: number | null;
49 }>({ state: "idle", settledUntil: null });
50 const confirmationExpired = useDeadlinePassed(checkState.settledUntil);
51 const updateState =
52 checkState.state === "current" && confirmationExpired ? "idle" : checkState.state;
53 const updateInFlight = useRef(false);
54 const hiddenUpdateTapCount = useRef(0);
55
56 const version = Constants.expoConfig?.version ?? "0.0.0";
57 // Match app.config.ts's production fallback to avoid mislabeling builds as development.
58 const variant = (Constants.expoConfig?.extra?.appVariant as string | undefined) ?? "production";
59 const variantLabel = variant === "production" ? "" : capitalize(variant);
60 // EAS assigns build numbers remotely; only the installed binary knows its own.
61 const build = Application.nativeBuildVersion;
62 const versionWithBuild = build ? `${version} (${build})` : version;
63 const versionLabel = variantLabel ? `${versionWithBuild} · ${variantLabel}` : versionWithBuild;
64 const updateCheckAvailable = isAppUpdateCheckAvailable();
65 const busy =
66 updateState === "checking" || updateState === "downloading" || updateState === "restarting";
67
68 async function checkForUpdate() {
69 // disabled updates next render; the ref blocks same-frame double taps.
70 if (updateInFlight.current) return;
71 updateInFlight.current = true;
72 // Failures arrive through onFailure; the settled result only matters for unlocking.
73 await settlePromise(() =>
74 runAppUpdateCheck({
75 applyMode: "immediate",
76 onFailure: (message) => Dialog.alert(gt("Update failed"), message),
77 onStateChange: (state) =>
78 setCheckState({
79 state,
80 settledUntil: state === "current" ? Date.now() + 3000 : null,
81 }),
82 }),
83 );
84 updateInFlight.current = false;
85 }
86
87 function handleVersionPress() {
88 if (!updateCheckAvailable || updateInFlight.current) return;
89 const tap = registerHiddenUpdateTap(hiddenUpdateTapCount.current);
90 hiddenUpdateTapCount.current = tap.nextCount;
91 if (tap.shouldCheck) {
92 void checkForUpdate();
93 }
94 }
95
96 const statusLabel =
97 updateState === "checking"
98 ? gt("Checking…")
99 : updateState === "downloading"
100 ? gt("Downloading…")
101 : updateState === "ready"
102 ? gt("Update ready")
103 : updateState === "restarting"
104 ? gt("Restarting…")
105 : updateState === "current"
106 ? gt("Up to date")
107 : null;
108
109 const versionRow = (
110 <View className="flex-row items-center gap-4 p-4">
111 <SymbolView
112 name="info.circle"
113 size={22}
114 tintColorClassName="accent-icon"
115 type="monochrome"
116 weight="regular"
117 />
118 <Text className="flex-1 text-lg text-foreground">
119 <T>Version</T>
120 </Text>
121 <View className="items-end">
122 <Text className="text-lg text-foreground-muted">{versionLabel}</Text>
123 {statusLabel ? (
124 <Text className="text-xs text-foreground-muted/70">{statusLabel}</Text>
125 ) : null}
126 </View>
127 </View>
128 );
129
130 return (
131 <SettingsSection title={gt("App", { $context: "settings section about this mobile app" })}>
132 <SettingsRow
133 icon="internaldrive"
134 label={gt("Client Storage")}
135 target="SettingsClientStorage"
136 />
137 <SettingsRow icon="stethoscope" label={gt("Diagnostics")} target="SettingsDiagnostics" />
138 <SettingsRow
139 icon="doc.on.doc"
140 label={gt("Open source licenses")}
141 target="SettingsOpenSourceLicenses"
142 />
143 <SettingsRow icon="doc.text" label={gt("Legal")} fullScreenTarget="SettingsLegal" />
144 {updateCheckAvailable ? (
145 <Pressable
146 accessibilityLabel={gt("Version {version}", { version: versionLabel })}
147 accessibilityRole="text"
148 disabled={busy}
149 onPress={handleVersionPress}
150 >
151 {versionRow}
152 </Pressable>
153 ) : (
154 versionRow
155 )}
156 </SettingsSection>
157 );
158 }
159
160 function capitalize(value: string): string {
161 return value.length > 0 ? value.charAt(0).toUpperCase() + value.slice(1) : value;
162 }