Open History to see the last commit
1import * as Dialog from "../../components/ui/Dialog";
2import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
3import Constants from "expo-constants";
4import { useCallback, useEffect, useRef, useState } from "react";
5import { Pressable, View } from "react-native";
6import { useSafeAreaInsets } from "react-native-safe-area-context";
7
8import { AppText as Text } from "../../components/ui/AppText";
9import { SymbolView } from "../../components/ui/AppSymbol";
10import {
11 type AppUpdateCheckState,
12 isAppUpdateCheckAvailable,
13 registerHiddenUpdateTap,
14 runAppUpdateCheck,
15} from "../updates/app-updates";
16import { SettingsRow } from "./components/SettingsRow";
17import { SettingsSection } from "./components/SettingsSection";
18import { SettingsScreen } from "./components/SettingsScreen";
19
20export function SettingsAboutRouteScreen() {
21 const insets = useSafeAreaInsets();
22
23 return (
24 <SettingsScreen title="About T3 Code">
25 <ScrollView
26 contentInsetAdjustmentBehavior="automatic"
27 showsVerticalScrollIndicator={false}
28 className="flex-1"
29 contentContainerClassName="gap-6 px-5 pt-4"
30 contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }}
31 >
32 <AppSettingsSection />
33 </ScrollView>
34 </SettingsScreen>
35 );
36}
37
38function AppSettingsSection() {
39 const [updateState, setUpdateState] = useState<AppUpdateCheckState>("idle");
40 const updateInFlight = useRef(false);
41 const hiddenUpdateTapCount = useRef(0);
42
43 const version = Constants.expoConfig?.version ?? "0.0.0";
44 // Fall back to "production" to match resolveAppVariant in app.config.ts, so a
45 // missing variant never mislabels a production build as development.
46 const variant = (Constants.expoConfig?.extra?.appVariant as string | undefined) ?? "production";
47 const variantLabel = variant === "production" ? "" : capitalize(variant);
48 const versionLabel = variantLabel ? `${version} · ${variantLabel}` : version;
49 const updateCheckAvailable = isAppUpdateCheckAvailable();
50 const busy =
51 updateState === "checking" || updateState === "downloading" || updateState === "restarting";
52
53 useEffect(() => {
54 if (updateState !== "current") return;
55 const timer = setTimeout(() => setUpdateState("idle"), 3000);
56 return () => clearTimeout(timer);
57 }, [updateState]);
58
59 const checkForUpdate = useCallback(async () => {
60 // `disabled={busy}` only takes effect on the next render, so two taps in the
61 // same frame would both get through. The ref closes that window.
62 if (updateInFlight.current) return;
63 updateInFlight.current = true;
64 try {
65 await runAppUpdateCheck({
66 applyMode: "immediate",
67 onFailure: (message) => Dialog.alert("Update failed", message),
68 onStateChange: setUpdateState,
69 });
70 } finally {
71 updateInFlight.current = false;
72 }
73 }, []);
74
75 const handleVersionPress = useCallback(() => {
76 if (!updateCheckAvailable || updateInFlight.current) return;
77 const tap = registerHiddenUpdateTap(hiddenUpdateTapCount.current);
78 hiddenUpdateTapCount.current = tap.nextCount;
79 if (tap.shouldCheck) {
80 void checkForUpdate();
81 }
82 }, [checkForUpdate, updateCheckAvailable]);
83
84 const statusLabel =
85 updateState === "checking"
86 ? "Checking…"
87 : updateState === "downloading"
88 ? "Downloading…"
89 : updateState === "ready"
90 ? "Update ready"
91 : updateState === "restarting"
92 ? "Restarting…"
93 : updateState === "current"
94 ? "Up to date"
95 : null;
96
97 const versionRow = (
98 <View className="flex-row items-center gap-4 p-4">
99 <SymbolView
100 name="info.circle"
101 size={22}
102 tintColorClassName="accent-icon"
103 type="monochrome"
104 weight="regular"
105 />
106 <Text className="flex-1 text-lg text-foreground">Version</Text>
107 <View className="items-end">
108 <Text className="text-lg text-foreground-muted">{versionLabel}</Text>
109 {statusLabel ? (
110 <Text className="text-xs text-foreground-muted/70">{statusLabel}</Text>
111 ) : null}
112 </View>
113 </View>
114 );
115
116 return (
117 <SettingsSection title="App">
118 <SettingsRow icon="internaldrive" label="Client Storage" target="SettingsClientStorage" />
119 <SettingsRow icon="stethoscope" label="Diagnostics" target="SettingsDiagnostics" />
120 <SettingsRow
121 icon="doc.on.doc"
122 label="Open source licenses"
123 target="SettingsOpenSourceLicenses"
124 />
125 <SettingsRow icon="doc.text" label="Legal" fullScreenTarget="SettingsLegal" />
126 {updateCheckAvailable ? (
127 <Pressable
128 accessibilityLabel={`Version ${versionLabel}`}
129 accessibilityRole="text"
130 disabled={busy}
131 onPress={handleVersionPress}
132 >
133 {versionRow}
134 </Pressable>
135 ) : (
136 versionRow
137 )}
138 </SettingsSection>
139 );
140}
141
142function capitalize(value: string): string {
143 return value.length > 0 ? value.charAt(0).toUpperCase() + value.slice(1) : value;
144}