diff --git a/apps/android/src/screens/setup-screens.tsx b/apps/android/src/screens/setup-screens.tsx index 9b51cac..e28de2f 100644 --- a/apps/android/src/screens/setup-screens.tsx +++ b/apps/android/src/screens/setup-screens.tsx @@ -7,9 +7,11 @@ import * as Clipboard from 'expo-clipboard' import { File, Paths } from 'expo-file-system' import { getContentUriAsync } from 'expo-file-system/legacy' import * as IntentLauncher from 'expo-intent-launcher' -import { ActivityIndicator, Alert, Animated, Easing, Image, KeyboardAvoidingView, Linking, Modal, PixelRatio, Platform, Pressable, ScrollView, StyleSheet, Text, TextInput, View } from 'react-native' +import { ActivityIndicator, Animated, Easing, Image, KeyboardAvoidingView, Linking, Modal, PixelRatio, Platform, Pressable, ScrollView, StyleSheet, Text, TextInput, View } from 'react-native' +import { Alert } from '../ui/alert' import { Toggle } from '../ui/toggle' -import { AlertTriangle, BatteryCharging, Bell, BellRing, Bot, Cable, Check, ChevronRight, Copy, Download, ExternalLink, Fingerprint, FolderPen, Globe, Hash, History, Info, KeyRound, Languages, Laptop, Layers, ListCollapse, LockKeyhole, LogOut, Mail, MoreVertical, Network, PanelTop, QrCode as QrCodeIcon, RotateCcw, Route, Server, Settings, ShieldAlert, ShieldCheck, SlidersHorizontal, Smartphone, Terminal, Type, UserRound, X, type LucideIcon } from 'lucide-react-native' +import { AlertTriangle, BatteryCharging, Bell, BellRing, Bot, Cable, Check, ChevronRight, Clock, Copy, Download, ExternalLink, Fingerprint, FolderPen, Globe, Hash, History, Info, KeyRound, Languages, Laptop, Layers, ListCollapse, LockKeyhole, LogOut, Mail, MoreVertical, Network, Palette, PanelLeft, PanelTop, Puzzle, QrCode as QrCodeIcon, RotateCcw, Route, Server, Settings, ShieldAlert, ShieldCheck, SlidersHorizontal, Smartphone, Terminal, Type, UserRound, X, Zap, type LucideIcon } from 'lucide-react-native' +import { ChatAppearanceScreen } from './chat-appearance-screen' import { useAppStore } from '../state/store' import { useBotTeamStore } from '../state/bot-store' import { DsBotSettingsModal } from './bot/ds-bot-settings-screen' @@ -33,7 +35,8 @@ import { easingCurve, resolveMotion } from '../ui/motion' import { useReduceMotion } from '../ui/use-reduce-motion' import { SheetModal } from '../ui/sheet' import { strings as zhCN, type LanguagePreference } from '../locales/i18n' -import type { ActivityDockMode, ThemePreference, TypographyDensity } from '../ui/theme' +import type { ActivityDockMode, DrawerLayoutMode, ThemePreference, TypographyDensity } from '../ui/theme' +import type { QuickPromptActionMode } from '../services/storage' /** Default DSH Remote Server; a build can override it via EXPO_PUBLIC_DSH_REMOTE_SERVER. */ const defaultServerUrl = 'https://dsh.r2049.cn' @@ -606,7 +609,21 @@ export function ServerSetupScreen({ onComplete, onBack, onMore, serverExpanded, ) } -export function SettingsScreen({ onBack, onReset, onOpenDiagnostics, onOpenAbout }: { onBack: () => void; onReset: () => void; onOpenDiagnostics?: () => void; onOpenAbout?: () => void }) { +export function SettingsScreen({ + active = true, + onBack, + onReset, + onSigningOutChange, + onOpenDiagnostics, + onOpenAbout, +}: { + active?: boolean + onBack: () => void + onReset: () => void + onSigningOutChange?: (busy: boolean) => void + onOpenDiagnostics?: () => void + onOpenAbout?: () => void +}) { const config = useAppStore(state => state.config) const identity = useAppStore(state => state.identity) const account = useAppStore(state => state.account) @@ -639,6 +656,9 @@ export function SettingsScreen({ onBack, onReset, onOpenDiagnostics, onOpenAbout } const [diagnosticsOpen, setDiagnosticsOpen] = useState(false) const [aboutOpen, setAboutOpen] = useState(false) + const [appearanceOpen, setAppearanceOpen] = useState(false) + const [signingOut, setSigningOut] = useState(false) + const chatAppearance = useAppStore(state => state.chatAppearance) const [logCount, setLogCount] = useState(() => connectionLogEntries().length) useEffect(() => { setLogCount(connectionLogEntries().length) @@ -656,6 +676,20 @@ export function SettingsScreen({ onBack, onReset, onOpenDiagnostics, onOpenAbout : activityDockMode === 'hidden' ? zhCN.settings.activityDockHidden : zhCN.settings.activityDockCompact + const drawerLayoutMode = useAppStore(state => state.drawerLayoutMode) + const setDrawerLayoutMode = useAppStore(state => state.setDrawerLayoutMode) + const [drawerLayoutSaving, setDrawerLayoutSaving] = useState(false) + const [drawerLayoutPickerOpen, setDrawerLayoutPickerOpen] = useState(false) + const currentDrawerLayoutLabel = drawerLayoutMode === 'classic' + ? zhCN.settings.drawerLayoutClassic + : zhCN.settings.drawerLayoutCompact + const quickPromptActionMode = useAppStore(state => state.quickPromptActionMode) + const setQuickPromptActionMode = useAppStore(state => state.setQuickPromptActionMode) + const [quickPromptActionSaving, setQuickPromptActionSaving] = useState(false) + const [quickPromptActionPickerOpen, setQuickPromptActionPickerOpen] = useState(false) + const currentQuickPromptActionLabel = quickPromptActionMode === 'send' + ? zhCN.settings.quickPromptActionSend + : zhCN.settings.quickPromptActionFill const compactHistory = useAppStore(state => state.compactHistory) const setCompactHistory = useAppStore(state => state.setCompactHistory) const [compactSaving, setCompactSaving] = useState(false) @@ -712,6 +746,22 @@ export function SettingsScreen({ onBack, onReset, onOpenDiagnostics, onOpenAbout finally { setActivityDockSaving(false) } } + const toggleDrawerLayoutMode = async (value: DrawerLayoutMode) => { + if (drawerLayoutSaving || value === drawerLayoutMode) return + setDrawerLayoutSaving(true) + try { await setDrawerLayoutMode(value) } + catch { Alert.alert(zhCN.settings.drawerLayoutModeSaveFailed, zhCN.settings.statusBarSaveFailedBody) } + finally { setDrawerLayoutSaving(false) } + } + + const toggleQuickPromptActionMode = async (value: QuickPromptActionMode) => { + if (quickPromptActionSaving || value === quickPromptActionMode) return + setQuickPromptActionSaving(true) + try { await setQuickPromptActionMode(value) } + catch { Alert.alert(zhCN.settings.quickPromptActionSaveFailed, zhCN.settings.statusBarSaveFailedBody) } + finally { setQuickPromptActionSaving(false) } + } + const toggleStatusBar = async (visible: boolean) => { if (statusBarSaving) return setStatusBarSaving(true) @@ -744,12 +794,25 @@ export function SettingsScreen({ onBack, onReset, onOpenDiagnostics, onOpenAbout } else void save() } + const runSignOutOrReset = async (action: () => Promise) => { + if (signingOut) return + setSigningOut(true) + onSigningOutChange?.(true) + try { + await action() + onReset() + } finally { + setSigningOut(false) + onSigningOutChange?.(false) + } + } + const confirmReset = () => Alert.alert( zhCN.settings.resetTitle, zhCN.settings.resetBody, [ { text: zhCN.common.cancel, style: 'cancel' }, - { text: zhCN.settings.reset, style: 'destructive', onPress: () => void reset().then(onReset) }, + { text: zhCN.settings.reset, style: 'destructive', onPress: () => void runSignOutOrReset(reset) }, ], ) @@ -758,22 +821,32 @@ export function SettingsScreen({ onBack, onReset, onOpenDiagnostics, onOpenAbout zhCN.settings.signOutBody, [ { text: zhCN.common.cancel, style: 'cancel' }, - { text: zhCN.settings.signOut, style: 'destructive', onPress: () => void signOut().then(onReset) }, + { text: zhCN.settings.signOut, style: 'destructive', onPress: () => void runSignOutOrReset(signOut) }, ], ) const switchColors = { trackColor: { false: colors.disabled, true: colors.primary }, thumbColor: colors.white } as const + const inlineSubpageOpen = (diagnosticsOpen && !onOpenDiagnostics) || (aboutOpen && !onOpenAbout) || appearanceOpen - if (diagnosticsOpen && !onOpenDiagnostics) { - return setDiagnosticsOpen(false)} /> - } - if (aboutOpen && !onOpenAbout) { - return setAboutOpen(false)} /> - } + const fontLabel = chatAppearance.fontScale === 'sm' ? zhCN.settings.fontSizeSm + : chatAppearance.fontScale === 'lg' ? zhCN.settings.fontSizeLg + : chatAppearance.fontScale === 'xl' ? zhCN.settings.fontSizeXl + : zhCN.settings.fontSizeMd + const bubbleLabel = chatAppearance.bubbleStyle === 'tinted' ? zhCN.settings.bubbleTinted + : chatAppearance.bubbleStyle === 'solid' ? zhCN.settings.bubbleSolid + : chatAppearance.bubbleStyle === 'minimal' ? zhCN.settings.bubbleMinimal + : zhCN.settings.bubbleSoft + const chatAppearanceSummary = `${fontLabel} · ${bubbleLabel}` return ( - }> + + }> {zhCN.settings.appearance} @@ -793,6 +866,13 @@ export function SettingsScreen({ onBack, onReset, onOpenDiagnostics, onOpenAbout setAppearanceOpen(true)} + /> + setActivityDockPickerOpen(true)} /> + setDrawerLayoutPickerOpen(true)} + /> + setQuickPromptActionPickerOpen(true)} + /> - - + + @@ -1115,6 +1209,90 @@ export function SettingsScreen({ onBack, onReset, onOpenDiagnostics, onOpenAbout + setDrawerLayoutPickerOpen(false)} + sheetStyle={[styles.languageDialog, { maxHeight: sheetMaxHeight }]} + > + + {zhCN.settings.drawerLayoutMode} + setDrawerLayoutPickerOpen(false)} /> + + + + {([ + { value: 'compact' as const, name: zhCN.settings.drawerLayoutCompact }, + { value: 'classic' as const, name: zhCN.settings.drawerLayoutClassic }, + ]).map((option, index) => { + const chosen = option.value === drawerLayoutMode + return ( + : undefined} + onPress={() => { + setDrawerLayoutPickerOpen(false) + void toggleDrawerLayoutMode(option.value) + }} + /> + ) + })} + + + + setQuickPromptActionPickerOpen(false)} + sheetStyle={[styles.languageDialog, { maxHeight: sheetMaxHeight }]} + > + + {zhCN.settings.quickPromptActionMode} + setQuickPromptActionPickerOpen(false)} /> + + + + {([ + { value: 'fill' as const, name: zhCN.settings.quickPromptActionFill }, + { value: 'send' as const, name: zhCN.settings.quickPromptActionSend }, + ]).map((option, index) => { + const chosen = option.value === quickPromptActionMode + return ( + : undefined} + onPress={() => { + setQuickPromptActionPickerOpen(false) + void toggleQuickPromptActionMode(option.value) + }} + /> + ) + })} + + + + + {diagnosticsOpen && !onOpenDiagnostics && ( + + setDiagnosticsOpen(false)} /> + + )} + {aboutOpen && !onOpenAbout && ( + + setAboutOpen(false)} /> + + )} + {appearanceOpen && ( + + setAppearanceOpen(false)} /> + + )} ) } @@ -1156,7 +1334,7 @@ function ThemeTile({ value, label, selected, onPress }: { value: ThemePreference ) } -export function HomeActionsMenu({ visible, onClose, onSettings, onAbout, onDevices, onRemoteHosts, onSwitchServer }: { +export function HomeActionsMenu({ visible, onClose, onSettings, onAbout, onDevices, onRemoteHosts, onSwitchServer, onPlugins, pluginsDisabled = false, onAutomationTasks }: { visible: boolean onClose: () => void onSettings: () => void @@ -1164,6 +1342,9 @@ export function HomeActionsMenu({ visible, onClose, onSettings, onAbout, onDevic onDevices?: () => void onRemoteHosts?: () => void onSwitchServer?: () => void + onPlugins?: () => void + pluginsDisabled?: boolean + onAutomationTasks?: () => void }) { const insets = useSafeAreaInsets() const { colors } = useTheme() @@ -1218,6 +1399,21 @@ export function HomeActionsMenu({ visible, onClose, onSettings, onAbout, onDevic }]} > + {onPlugins !== undefined && ( + + )} + {onAutomationTasks !== undefined && ( + + )} + {(onPlugins !== undefined || onAutomationTasks !== undefined) && ( + + )} {onDevices !== undefined && ( )} @@ -1237,6 +1433,7 @@ export function HomeActionsMenu({ visible, onClose, onSettings, onAbout, onDevic : undefined} onPress={() => void checkForUpdates()} disabled={phase !== 'idle'} + busy={phase !== 'idle'} last /> @@ -1353,12 +1550,13 @@ function useUpdateCheck() { return { phase, progress, latestVersion, checkForUpdates } } -function HomeMenuRow({ icon: Icon, label, subtitle, onPress, disabled = false, last = false }: { +function HomeMenuRow({ icon: Icon, label, subtitle, onPress, disabled = false, busy = false, last = false }: { icon: LucideIcon label: string subtitle?: string onPress: () => void disabled?: boolean + busy?: boolean last?: boolean }) { const { colors } = useTheme() @@ -1366,8 +1564,8 @@ function HomeMenuRow({ icon: Icon, label, subtitle, onPress, disabled = false, l return ( [ @@ -1377,12 +1575,12 @@ function HomeMenuRow({ icon: Icon, label, subtitle, onPress, disabled = false, l disabled && styles.homeMenuRowDisabled, ]} > - + - {label} + {label} {subtitle !== undefined && {subtitle}} - {disabled + {busy ? : null} @@ -1700,6 +1898,8 @@ function languageOptions(): Array<{ value: LanguagePreference; name: string }> { { value: 'es-ES', name: 'Español' }, { value: 'de-DE', name: 'Deutsch' }, { value: 'fr-FR', name: 'Français' }, + { value: 'ru-RU', name: 'Русский' }, + { value: 'uk-UA', name: 'Українська' }, ] } @@ -1829,6 +2029,7 @@ function createStyles(colors: ThemeColors) { // flexGrow 0 keeps the card content-sized in portrait; flexShrink lets the // capped landscape card scroll instead of clipping its last row. homeMenuScroll: { flexGrow: 0, flexShrink: 1 }, + homeMenuDivider: { height: StyleSheet.hairlineWidth, backgroundColor: colors.separator, marginVertical: spacing.xxs, marginHorizontal: spacing.sm }, homeMenuRow: { minHeight: 52, paddingHorizontal: spacing.sm, flexDirection: 'row', alignItems: 'center', gap: spacing.md, borderRadius: radius.lg }, homeMenuRowBorder: {}, homeMenuRowPressed: { backgroundColor: colors.surfaceStrong }, @@ -1836,6 +2037,7 @@ function createStyles(colors: ThemeColors) { homeMenuRowIcon: { width: 24, alignItems: 'center', justifyContent: 'center' }, homeMenuRowCopy: { flex: 1 }, homeMenuRowLabel: { ...type.body, color: colors.ink }, + homeMenuRowLabelDisabled: { color: colors.muted }, homeMenuRowSubtitle: { ...type.caption, color: colors.muted, marginTop: 1 }, aboutHero: { alignItems: 'center', paddingVertical: spacing.xxl, gap: spacing.xs }, aboutLogo: { width: 84, height: 84, borderRadius: radius.xl, marginBottom: spacing.sm },