Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

feat(mobile): add account actions to home menu

xd-boboef9241564dce
diff --git a/apps/mobile/app/devices/index.tsx b/apps/mobile/app/devices/index.tsx
index 5a372a4063..fd9157ab67 100644
--- a/apps/mobile/app/devices/index.tsx
+++ b/apps/mobile/app/devices/index.tsx
@@ -286,6 +286,7 @@ export default function HomeScreen() {
const [chromeMenuOpen, setChromeMenuOpen] = useState(false);
const [accountSwitcherOpen, setAccountSwitcherOpen] = useState(false);
const [chromeMenuCloseInstant, setChromeMenuCloseInstant] = useState(false);
+ const [loggingOut, setLoggingOut] = useState(false);
// 菜单关闭动画完成(Modal 卸载)后要执行的动作。iOS 上两个兄弟 Modal 重叠时,第二个 Modal
// 是叠在菜单 Modal 的 VC 上 present 的,菜单淡出后卸载会把它连带 dismiss 掉——所以从菜单里
// 打开重命名 / 撤销授权弹窗必须等菜单完全卸载(onClosed)后再挂载,不能同一帧直接 set。
@@ -1327,6 +1328,16 @@ export default function HomeScreen() {
});
}, [guardedPush, home.primaryDevice, newSessionDeviceOptions, selectedDeviceId, t]);
+ const logout = useCallback(async () => {
+ if (loggingOut) return;
+ setLoggingOut(true);
+ try {
+ await auth.logout();
+ } finally {
+ setLoggingOut(false);
+ }
+ }, [auth, loggingOut]);
+
const toggleProject = useCallback((key: string) => {
configureCollapseAnimation();
setCollapsedProjectKeys((current) =>
@@ -1981,6 +1992,7 @@ export default function HomeScreen() {
/>
<HomeChromeDrawer
closeInstant={chromeMenuCloseInstant}
+ loggingOut={loggingOut}
onClose={() => {
setChromeMenuCloseInstant(false);
setChromeMenuOpen(false);
@@ -2005,6 +2017,7 @@ export default function HomeScreen() {
setChromeMenuCloseInstant(true);
setChromeMenuOpen(false);
}}
+ onLogout={() => void logout()}
open={chromeMenuOpen}
user={user}
/>
diff --git a/apps/mobile/src/__tests__/homeDesktopFirst.test.ts b/apps/mobile/src/__tests__/homeDesktopFirst.test.ts
index 077e17d3ef..8827a6a55f 100644
--- a/apps/mobile/src/__tests__/homeDesktopFirst.test.ts
+++ b/apps/mobile/src/__tests__/homeDesktopFirst.test.ts
@@ -123,6 +123,17 @@ describe('mobile home desktop-first surface', () => {
expect(chromeDrawer).toContain('testID="devices.settingsButton"');
expect(chromeDrawer).toContain('testID="home.chromeDrawer.search"');
expect(chromeDrawer).toContain('testID="home.chromeDrawer.account"');
+ expect(chromeDrawer).toContain('testID="home.chromeDrawer.accounts"');
+ expect(chromeDrawer).toContain('testID="home.chromeDrawer.logout"');
+ expect(chromeDrawer.indexOf('testID="devices.settingsButton"'))
+ .toBeLessThan(chromeDrawer.indexOf('testID="home.chromeDrawer.accounts"'));
+ expect(chromeDrawer.indexOf('testID="home.chromeDrawer.accounts"'))
+ .toBeLessThan(chromeDrawer.indexOf('testID="home.chromeDrawer.logout"'));
+ expect(chromeDrawer).toContain('<View style={styles.menuDivider} />');
+ expect(chromeDrawer.indexOf('<View style={styles.menuDivider} />'))
+ .toBeLessThan(chromeDrawer.indexOf('testID="home.chromeDrawer.logout"'));
+ expect(chromeDrawer.match(/onPress=\{onOpenAccounts\}/g)).toHaveLength(1);
+ expect(chromeDrawer).toContain("t('settings.account.logout')");
expect(chromeDrawer).toContain('openSettingsImmediately');
expect(chromeDrawer).toContain('closeInstant');
expect(chromeDrawer).not.toContain('remoteSettings');
diff --git a/apps/mobile/src/session/HomeChromeDrawer.tsx b/apps/mobile/src/session/HomeChromeDrawer.tsx
index f42f24767c..d9d5b57bbf 100644
--- a/apps/mobile/src/session/HomeChromeDrawer.tsx
+++ b/apps/mobile/src/session/HomeChromeDrawer.tsx
@@ -5,7 +5,7 @@
* 树内 overlay(不用 RN Modal),避免和首页其它 Modal 抢 present/dismiss。
* 动画 / 左滑关闭对齐 SessionListDrawer,遵循 reduce-motion。
*/
-import { Search, Settings } from 'lucide-react-native';
+import { LogOut, Search, Settings, UsersRound } from 'lucide-react-native';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import {
AccessibilityInfo,
@@ -54,6 +54,8 @@ export function HomeChromeDrawer({
onOpenSearch,
onOpenAccounts,
onOpenSettings,
+ onLogout,
+ loggingOut = false,
open,
user,
}: {
@@ -64,6 +66,8 @@ export function HomeChromeDrawer({
onOpenSearch(): void;
onOpenAccounts(): void;
onOpenSettings(): void;
+ onLogout(): void;
+ loggingOut?: boolean;
open: boolean;
user: {
avatar: string | null;
@@ -241,13 +245,7 @@ export function HomeChromeDrawer({
]}
testID="home.chromeMenu.panel"
>
- <Pressable
- accessibilityLabel={accountSubtitle ? `${accountTitle}, ${accountSubtitle}` : accountTitle}
- accessibilityRole="button"
- onPress={onOpenAccounts}
- style={({ pressed }) => [styles.accountRow, pressed && styles.pressed]}
- testID="home.chromeDrawer.account"
- >
+ <View style={styles.accountRow} testID="home.chromeDrawer.account">
<View style={styles.avatar}>
{accountImage ? (
<Image source={{ uri: accountImage }} style={styles.avatarImage} />
@@ -261,7 +259,7 @@ export function HomeChromeDrawer({
<Text numberOfLines={1} style={styles.accountEmail}>{accountSubtitle}</Text>
) : null}
</View>
- </Pressable>
+ </View>
<View style={styles.divider} />
@@ -287,6 +285,40 @@ export function HomeChromeDrawer({
<Settings color={colors.textSecondary} size={iconSize.md} strokeWidth={iconStroke.regular} />
<Text numberOfLines={1} style={styles.menuLabel}>{t('devices.list.menu.settings')}</Text>
</Pressable>
+
+ <Pressable
+ accessibilityLabel={t('devices.list.accounts.title')}
+ accessibilityRole="button"
+ onPress={onOpenAccounts}
+ style={({ pressed }) => [styles.menuRow, pressed && styles.pressed]}
+ testID="home.chromeDrawer.accounts"
+ >
+ <UsersRound color={colors.textSecondary} size={iconSize.md} strokeWidth={iconStroke.regular} />
+ <Text numberOfLines={1} style={styles.menuLabel}>{t('devices.list.accounts.title')}</Text>
+ </Pressable>
+
+ <View style={styles.menuDivider} />
+
+ <Pressable
+ accessibilityLabel={loggingOut
+ ? t('settings.account.loggingOutAccessibility')
+ : t('settings.account.logout')}
+ accessibilityRole="button"
+ accessibilityState={{ busy: loggingOut || undefined, disabled: loggingOut || undefined }}
+ disabled={loggingOut}
+ onPress={onLogout}
+ style={({ pressed }) => [
+ styles.menuRow,
+ pressed && styles.pressed,
+ loggingOut && styles.disabled,
+ ]}
+ testID="home.chromeDrawer.logout"
+ >
+ <LogOut color={colors.destructive} size={iconSize.md} strokeWidth={iconStroke.regular} />
+ <Text numberOfLines={1} style={[styles.menuLabel, styles.dangerMenuLabel]}>
+ {loggingOut ? t('settings.account.loggingOut') : t('settings.account.logout')}
+ </Text>
+ </Pressable>
</Animated.View>
</GestureDetector>
</View>
@@ -364,6 +396,12 @@ const makeStyles = (colors: ThemeColors) =>
height: StyleSheet.hairlineWidth,
marginHorizontal: spacing.lg,
},
+ menuDivider: {
+ backgroundColor: colors.border,
+ height: StyleSheet.hairlineWidth,
+ marginHorizontal: spacing.lg,
+ marginVertical: spacing.xs,
+ },
menuRow: {
alignItems: 'center',
borderRadius: radius.container,
@@ -381,6 +419,12 @@ const makeStyles = (colors: ThemeColors) =>
lineHeight: lineHeight.body,
minWidth: 0,
},
+ dangerMenuLabel: {
+ color: colors.destructive,
+ },
+ disabled: {
+ opacity: 0.48,
+ },
pressed: {
opacity: 0.72,
},