Extends the i18n infra from #97 (Settings screen only) to the rest of the app: session chat screen, connection add/edit/list screens, sessions list (incl. directory grouping from #96), navigation titles, notifications category metadata, error boundary, telemetry consent modal, auth gate, and every chat UI component (permission/question prompts, status indicator, model/variant pickers, directory switcher/browser, reasoning block, tool call card, session info). - 244 new keys added to en.json/zh-Hans.json with reviewed, natural Simplified Chinese (not machine-garbage), keeping key sets identical. - User content, server URLs, code snippets, log/error-detail text, and diagnostics-classify.ts (pure dependency-free module feeding Sentry/ support reports) are intentionally left untranslated per scope. - Interpolation used for counts/names (e.g. reconnect attempt, files count, connection name in delete confirmations); categoryMeta/ CONNECTION_TYPES switched to labelKey indirection since they're module-level constants evaluated before i18next is guaranteed ready. - Added src/lib/i18n/catalog-parity.test.ts (node --test) asserting en.json/zh-Hans.json expose identical key sets and no empty values, to catch future locale drift. Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
175 lines
5.9 KiB
TypeScript
175 lines
5.9 KiB
TypeScript
import { useEffect, useRef, useState } from "react"
|
|
import { Stack, router } from "expo-router"
|
|
import { StatusBar } from "expo-status-bar"
|
|
import { useColorScheme, View, ActivityIndicator } from "react-native"
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
|
|
import { GestureHandlerRootView } from "react-native-gesture-handler"
|
|
import { BottomSheetModalProvider } from "@gorhom/bottom-sheet"
|
|
import { I18nextProvider, useTranslation } from "react-i18next"
|
|
import i18n from "../src/lib/i18n/config"
|
|
import { useAuth } from "../src/stores/auth"
|
|
import { useConnections } from "../src/stores/connections"
|
|
import { useEvents } from "../src/stores/events"
|
|
import { useCatalog } from "../src/stores/catalog"
|
|
import { useSettings } from "../src/stores/settings"
|
|
import { AuthGate } from "../src/components/AuthGate"
|
|
import { ErrorBoundary } from "../src/components/ErrorBoundary"
|
|
import { TelemetryConsentModal } from "../src/components/TelemetryConsentModal"
|
|
import * as notifications from "../src/lib/notifications"
|
|
import { addBreadcrumb, wrap } from "../src/lib/sentry"
|
|
import { loadTelemetryConsent, setTelemetryConsent } from "../src/lib/telemetry"
|
|
import { initAnalytics, trackAppOpened } from "../src/lib/analytics"
|
|
|
|
const queryClient = new QueryClient()
|
|
|
|
function RootLayout() {
|
|
const colorScheme = useColorScheme()
|
|
const isDark = colorScheme === "dark"
|
|
const { t } = useTranslation()
|
|
|
|
const { initialize: initAuth, isLoading: authLoading } = useAuth()
|
|
const { loadConnections, isLoading: connectionsLoading, client } = useConnections()
|
|
const sseStarted = useRef(false)
|
|
|
|
// Telemetry consent state: null = loading, 'unknown' = show modal, else decided
|
|
const [consentState, setConsentState] = useState<"loading" | "unknown" | "decided">("loading")
|
|
|
|
useEffect(() => {
|
|
initAuth()
|
|
loadConnections()
|
|
useSettings.getState().load()
|
|
|
|
// Connect notification preferences to the notification module
|
|
notifications.configure(() => useSettings.getState().notifications)
|
|
|
|
// Navigate to session when user taps a notification
|
|
const unsubNotifications = notifications.onTap((data) => {
|
|
router.push(`/session/${data.sessionId}`)
|
|
})
|
|
|
|
// Load telemetry consent — initialise Sentry only if previously granted
|
|
loadTelemetryConsent()
|
|
.then((state) => {
|
|
if (state === "granted") {
|
|
import("../src/lib/sentry").then(({ initSentry }) => {
|
|
initSentry()
|
|
addBreadcrumb({ category: "app.lifecycle", message: "app started" })
|
|
})
|
|
initAnalytics()
|
|
trackAppOpened()
|
|
setConsentState("decided")
|
|
} else if (state === "denied") {
|
|
addBreadcrumb({ category: "app.lifecycle", message: "app started (telemetry off)" })
|
|
setConsentState("decided")
|
|
} else {
|
|
setConsentState("unknown")
|
|
}
|
|
})
|
|
.catch(() => {
|
|
// SecureStore unavailable — show modal so user can decide
|
|
setConsentState("unknown")
|
|
})
|
|
|
|
return unsubNotifications
|
|
}, [])
|
|
|
|
// Connect/disconnect SSE and load catalog when client changes
|
|
useEffect(() => {
|
|
if (client && !sseStarted.current) {
|
|
sseStarted.current = true
|
|
useEvents.getState().connect()
|
|
useCatalog.getState().load()
|
|
} else if (!client && sseStarted.current) {
|
|
sseStarted.current = false
|
|
useEvents.getState().disconnect()
|
|
}
|
|
return () => {
|
|
if (sseStarted.current) {
|
|
sseStarted.current = false
|
|
useEvents.getState().disconnect()
|
|
}
|
|
}
|
|
}, [client])
|
|
|
|
const isLoading = authLoading || connectionsLoading || consentState === "loading"
|
|
|
|
if (isLoading) {
|
|
return (
|
|
<View
|
|
style={{
|
|
flex: 1,
|
|
justifyContent: "center",
|
|
alignItems: "center",
|
|
backgroundColor: isDark ? "#0a0a0a" : "#ffffff",
|
|
}}
|
|
>
|
|
<ActivityIndicator size="large" color={isDark ? "#ffffff" : "#0a0a0a"} />
|
|
</View>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<ErrorBoundary>
|
|
<I18nextProvider i18n={i18n}>
|
|
<GestureHandlerRootView style={{ flex: 1 }}>
|
|
<BottomSheetModalProvider>
|
|
<QueryClientProvider client={queryClient}>
|
|
<AuthGate>
|
|
<Stack
|
|
screenOptions={{
|
|
headerStyle: {
|
|
backgroundColor: isDark ? "#0a0a0a" : "#ffffff",
|
|
},
|
|
headerTintColor: isDark ? "#ffffff" : "#0a0a0a",
|
|
contentStyle: {
|
|
backgroundColor: isDark ? "#0a0a0a" : "#ffffff",
|
|
},
|
|
}}
|
|
>
|
|
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
|
|
<Stack.Screen
|
|
name="session/[id]"
|
|
options={{
|
|
title: t("session.titleFallback"),
|
|
presentation: "card",
|
|
}}
|
|
/>
|
|
<Stack.Screen
|
|
name="connection/add"
|
|
options={{
|
|
title: t("nav.addConnectionTitle"),
|
|
presentation: "modal",
|
|
}}
|
|
/>
|
|
<Stack.Screen
|
|
name="connection/[id]"
|
|
options={{
|
|
title: t("nav.editConnectionTitle"),
|
|
presentation: "modal",
|
|
}}
|
|
/>
|
|
</Stack>
|
|
<StatusBar style={isDark ? "light" : "dark"} />
|
|
</AuthGate>
|
|
</QueryClientProvider>
|
|
</BottomSheetModalProvider>
|
|
</GestureHandlerRootView>
|
|
{/* Telemetry consent modal — shown once on first launch */}
|
|
<TelemetryConsentModal
|
|
visible={consentState === "unknown"}
|
|
onAllow={async () => {
|
|
await setTelemetryConsent(true)
|
|
setConsentState("decided")
|
|
}}
|
|
onDecline={async () => {
|
|
await setTelemetryConsent(false)
|
|
setConsentState("decided")
|
|
}}
|
|
/>
|
|
</I18nextProvider>
|
|
</ErrorBoundary>
|
|
)
|
|
}
|
|
|
|
export default wrap(RootLayout)
|