Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 收口旧入口迁移与模式切换键盘行为
nana3a6d06ec29d0
diff --git a/apps/mobile/app/resources/[collectionId].tsx b/apps/mobile/app/resources/[collectionId].tsxindex 7b6a9bc05a..72764dfeb1 100644--- a/apps/mobile/app/resources/[collectionId].tsx+++ b/apps/mobile/app/resources/[collectionId].tsx@@ -1,6 +1,6 @@import { useRemoteResourceList } from '@/session/useRemoteResourceList';import { isRemoteResourceUnread } from '@/device-link/remoteResourceCache';-import { Redirect, useLocalSearchParams, useRouter } from 'expo-router';+import { Redirect, useIsFocused, useLocalSearchParams, useRouter } from 'expo-router';import { useCallback, useEffect, useMemo } from 'react';import {ActivityIndicator,@@ -18,7 +18,7 @@ import {} from '@cindy/device-link';import { Text } from '@/components/AppText';-import { useHomeMode } from '@/session/useHomeMode';+import { useTeammateNavigation } from '@/session/useTeammateNavigation';import { TEAMMATE_COLLECTION_ID } from '@/session/useTeammateRoster';import { RemoteCompanionAvatar } from '@/components/RemoteCompanionAvatar';import { MainWindowActionButton, MainWindowEmptyState, RemoteListSyncingPlaceholder, StatusDot } from '@/components/MobilePrimitives';@@ -56,12 +56,12 @@ export default function RemoteCollectionScreen() {}function LegacyTeammatesHomeRedirect() {- const navigation = useHomeMode();+ const navigation = useTeammateNavigation();+ const focused = useIsFocused();useEffect(() => {- if (navigation.hydrated && navigation.mode !== 'teammates') void navigation.setMode('teammates');- }, [navigation.hydrated, navigation.mode, navigation.setMode]);- if (!navigation.hydrated || navigation.mode !== 'teammates') return null;- return <Redirect href="/devices" />;+ if (focused && navigation.hydrated) void navigation.chooseMode('teammates');+ }, [focused, navigation.hydrated, navigation.chooseMode]);+ return null;}function RemoteCollectionScreenContent() {diff --git a/apps/mobile/src/__tests__/homeChromeMenusAndroid.test.ts b/apps/mobile/src/__tests__/homeChromeMenusAndroid.test.tsindex f533c21691..fc18103d84 100644--- a/apps/mobile/src/__tests__/homeChromeMenusAndroid.test.ts+++ b/apps/mobile/src/__tests__/homeChromeMenusAndroid.test.ts@@ -4,6 +4,7 @@ import { describe, expect, it, vi } from "vitest";import type { MobileHomeDeviceFilterItem } from "@/session/mobileHome";vi.mock("react-native", () => ({+ Keyboard: { dismiss: vi.fn() },Platform: { OS: "android" },NativeModules: {},UIManager: { getViewManagerConfig: () => ({}) },@@ -13,6 +14,7 @@ vi.mock("@/theme", () => ({ useTheme: () => ({ colors: {} }) }));vi.mock("@/platform/chrome/AnchoredPullDownMenu", () => ({ AnchoredPullDownMenu: () => null }));import { usesNativePullDownMenu } from "@/platform/chrome/NativePullDownMenu";+import { Keyboard } from "react-native";import { buildPullDownMenuSections, resolvePullDownSubmenu } from "@/platform/chrome/pullDownMenuModel";import {buildHomeDisplayPullDownActions,@@ -139,6 +141,7 @@ describe("Android home chrome menus follow the iOS pull-down", () => {});it("opens Teammates from both scope menus through the teammate home path", () => {+ vi.mocked(Keyboard.dismiss).mockClear();const collections = [{ id: "teammates", title: "Teammates", resourceKind: "bot", targets: [{ deviceId: "mac", deviceName: "Mac" }] },{ id: "tools", title: "Tools", resourceKind: "tool", targets: [{ deviceId: "mac", deviceName: "Mac" }] },@@ -151,14 +154,17 @@ describe("Android home chrome menus follow the iOS pull-down", () => {const parsed = parseHomeScopePullDownAction(action.id);const collection = parsed.kind === "collection" ? collections.find(item => item.id === parsed.collectionId) : undefined;expect(collection).toBeDefined();- openHomeRemoteCollection({ collection: collection!, teammateCollectionId: "teammates", embedded: true, setMode, push, onModeChange });+ openHomeRemoteCollection({ collection: collection!, teammateCollectionId: "teammates", embedded: true, setMode, push, onModeChange, dismissKeyboard: Keyboard.dismiss });}expect(setMode).toHaveBeenCalledExactlyOnceWith("teammates");expect(push).toHaveBeenNthCalledWith(1, "/devices");expect(push).toHaveBeenNthCalledWith(2, expect.objectContaining({ pathname: "/resources/[collectionId]", params: expect.objectContaining({ collectionId: "tools", targets: JSON.stringify(collections[1].targets) }) }));expect(onModeChange).not.toHaveBeenCalled();- openHomeRemoteCollection({ collection: collections[0], teammateCollectionId: "teammates", embedded: false, setMode, push, onModeChange });+ expect(Keyboard.dismiss).toHaveBeenCalledOnce();+ onModeChange.mockImplementation(() => expect(Keyboard.dismiss).toHaveBeenCalledTimes(2));+ openHomeRemoteCollection({ collection: collections[0], teammateCollectionId: "teammates", embedded: false, setMode, push, onModeChange, dismissKeyboard: Keyboard.dismiss });expect(onModeChange).toHaveBeenCalledExactlyOnceWith("teammates");+ expect(push).toHaveBeenCalledTimes(2);});it("routes settings pickers and local-log options through the pull-down on Android", () => {diff --git a/apps/mobile/src/__tests__/remoteCollectionRead.test.tsx b/apps/mobile/src/__tests__/remoteCollectionRead.test.tsxindex 78c50caf66..5326aee0c8 100644--- a/apps/mobile/src/__tests__/remoteCollectionRead.test.tsx+++ b/apps/mobile/src/__tests__/remoteCollectionRead.test.tsx@@ -1,10 +1,11 @@// @vitest-environment jsdomimport { act, createElement } from 'react';import { createRoot } from 'react-dom/client';-import { expect, it, vi } from 'vitest';+import { beforeEach, expect, it, vi } from 'vitest';const h = vi.hoisted(() => ({push: vi.fn(), markRead: vi.fn(), list: vi.fn(), setMode: vi.fn(), homeMode: 'tasks',+ hydrated: true, focused: true, dismiss: vi.fn(), dismissTo: vi.fn(), reset: vi.fn(), routes: [] as Array<{ name: string; params?: unknown }>,params: { collectionId: 'tools', targets: JSON.stringify([{ deviceId: 'mac', deviceName: 'My Mac' }]) },translation: { t: (key: string) => key, i18n: { language: 'en' } },link: { connectionEpoch: 1, status: 'online', presenceVersion: 1, getPresenceAvailability: () => true, openLink: vi.fn(async () => {}), invoke: vi.fn(), onRemoteResourceChanged: vi.fn((_listener: (deviceId: string, payload: { collectionId: string }) => void) => () => {}), subscribe: vi.fn(), unsubscribe: vi.fn() },@@ -26,9 +27,9 @@ vi.mock('react-native', async () => {});vi.mock('expo-router', async () => {const { useEffect } = await import('react');- return { Redirect: ({ href }: { href: string }) => <output data-target>{href}</output>, useFocusEffect: (effect: () => void | (() => void)) => useEffect(effect, [effect]), useLocalSearchParams: () => h.params, useRouter: () => ({}), useNavigation: () => ({ getState: () => ({ index: 0, routes: [] }) }) };+ return { Redirect: ({ href }: { href: string }) => <output data-target>{href}</output>, useIsFocused: () => h.focused, useFocusEffect: (effect: () => void | (() => void)) => useEffect(effect, [effect]), useLocalSearchParams: () => h.params, useRouter: () => ({ dismiss: h.dismiss, dismissTo: h.dismissTo }), useNavigation: () => ({ reset: h.reset, getState: () => ({ index: h.routes.length - 1, routes: h.routes }) }) };});-vi.mock('@/session/useHomeMode', () => ({ useHomeMode: () => ({ hydrated: true, mode: h.homeMode, setMode: h.setMode }) }));+vi.mock('@/session/useHomeMode', () => ({ useHomeMode: () => ({ hydrated: h.hydrated, mode: h.homeMode, setMode: h.setMode }) }));vi.mock('react-i18next', () => ({ useTranslation: () => h.translation }));vi.mock('@/i18n', () => ({ i18n: { t: (key: string) => key } }));vi.mock('react-native-safe-area-context', () => ({ SafeAreaView: 'div' }));@@ -61,19 +62,48 @@ vi.mock('@/device-link/remoteResources', async (original) => ({listRemoteCollection: h.list,}));import RemoteCollectionScreen from '../../app/resources/[collectionId]';+import { StackRouter, StackActions } from 'expo-router/build/react-navigation/routers/StackRouter';Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });+beforeEach(() => { vi.clearAllMocks(); h.hydrated = true; h.focused = true; h.routes = []; });-it('redirects the retired teammates collection to the teammate home', async () => {+it('does not migrate a hidden legacy route underneath an active task', async () => {+ h.params.collectionId = 'teammates'; h.focused = false;+ h.routes = [{ name: 'resources/[collectionId]', params: { collectionId: 'teammates' } }, { name: 'sessions/[sessionId]' }];+ const root = createRoot(document.createElement('div'));+ try {+ await act(async () => root.render(createElement(RemoteCollectionScreen)));+ expect(h.setMode).not.toHaveBeenCalled();+ expect(h.reset).not.toHaveBeenCalled();+ expect(h.dismiss).not.toHaveBeenCalled();+ expect(h.dismissTo).not.toHaveBeenCalled();+ } finally { h.params.collectionId = 'tools'; act(() => root.unmount()); }+});++it.each(['index', 'devices/index'])('migrates the retired collection by returning to the existing %s without duplicating home', async name => {h.params.collectionId = 'teammates';+ h.hydrated = false;+ const router = StackRouter({ initialRouteName: name });+ const options = { routeNames: [name, 'resources/[collectionId]'], routeParamList: {}, routeGetIdList: {}, routeKeyChanges: [] };+ let state = router.getInitialState(options);+ const home = state.routes[0];+ state = router.getStateForAction(state, StackActions.push('resources/[collectionId]', { collectionId: 'teammates' }), options)! as typeof state;+ h.routes = state.routes;+ h.dismiss.mockImplementationOnce(count => { state = router.getStateForAction(state, StackActions.pop(count), options)! as typeof state; });const container = document.createElement('div');const root = createRoot(container);try {await act(async () => root.render(createElement(RemoteCollectionScreen)));expect(container.querySelector('[data-target]')).toBeNull();- expect(h.setMode).toHaveBeenCalledWith('teammates');- h.homeMode = 'teammates';+ expect(h.setMode).not.toHaveBeenCalled();+ expect(h.dismiss).not.toHaveBeenCalled();+ h.hydrated = true;await act(async () => root.render(createElement(RemoteCollectionScreen)));- expect(container.querySelector('[data-target]')?.textContent).toBe('/devices');+ expect(h.setMode).toHaveBeenCalledWith('teammates');+ expect(h.dismiss).toHaveBeenCalledExactlyOnceWith(1);+ expect(h.dismissTo).not.toHaveBeenCalled();+ expect(state.routes).toEqual([home]);+ expect(state.routes[0]).toBe(home);+ expect(container.querySelector('[data-target]')).toBeNull();expect(h.list).not.toHaveBeenCalled();} finally {h.params.collectionId = 'tools';diff --git a/apps/mobile/src/session/HomeSurface.tsx b/apps/mobile/src/session/HomeSurface.tsxindex cc27a3f2ef..d84cc1246e 100644--- a/apps/mobile/src/session/HomeSurface.tsx+++ b/apps/mobile/src/session/HomeSurface.tsx@@ -24,6 +24,7 @@ import {Alert,Animated,AppState,+ Keyboard,Platform,Modal,type NativeScrollEvent,@@ -134,7 +135,6 @@ import { useDeviceLink } from '@/device-link/DeviceLinkContext';import {discoverRemoteHomeCollections,remoteResourceDiscoveryTargets,- serializeRemoteResourceTargets,type RemoteHomeCollection,} from '@/device-link/remoteResources';import {@@ -2784,7 +2784,7 @@ function HomeScreenContent({ active = true, onModeChange, width, newSessionInSysconst openRemoteCollection = useCallback((collection: RemoteHomeCollection) => {openHomeRemoteCollection({collection, teammateCollectionId: TEAMMATE_COLLECTION_ID, embedded,- setMode: homeNavigation.setMode, push: guardedPush, onModeChange,+ setMode: homeNavigation.setMode, push: guardedPush, onModeChange, dismissKeyboard: Keyboard.dismiss,});}, [embedded, guardedPush, homeNavigation.setMode, onModeChange]);const homeScopePullDownActions = useMemo(diff --git a/apps/mobile/src/session/homeChromeMenus.ts b/apps/mobile/src/session/homeChromeMenus.tsindex c502516a27..c8d8f990bb 100644--- a/apps/mobile/src/session/homeChromeMenus.ts+++ b/apps/mobile/src/session/homeChromeMenus.ts@@ -74,6 +74,7 @@ export function openHomeRemoteCollection({collection,teammateCollectionId,embedded,+ dismissKeyboard,setMode,push,onModeChange,@@ -81,11 +82,13 @@ export function openHomeRemoteCollection({collection: RemoteHomeCollection;teammateCollectionId: string;embedded: boolean;+ dismissKeyboard(): void;setMode(mode: "teammates"): void | Promise<void>;push(href: string | { pathname: string; params: Record<string, string> }): void;onModeChange?: (mode: "teammates") => void;}) {if (collection.id === teammateCollectionId) {+ dismissKeyboard();if (embedded) {void setMode("teammates");push("/devices");