Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 处理 review——无 Liquid Glass 时不起形变、设备名按账号隔离且旧读取不覆盖新写入、保存中禁止离开、设备分组按真实在线状态
kirozenge9b732a929b5
diff --git a/apps/mobile/app/settings/device-name.tsx b/apps/mobile/app/settings/device-name.tsxindex 51a4e1429b..31a961dea5 100644--- a/apps/mobile/app/settings/device-name.tsx+++ b/apps/mobile/app/settings/device-name.tsx@@ -15,7 +15,8 @@ import { buildMobileDeviceName } from '@/device-link/mobileDeviceIdentity';import { formatRemoteError } from '@/device-link/remoteStatus';import { SimpleStackHeader, simpleScreenSafeAreaEdges } from '@/platform/chrome';import {- publishSelfDeviceName,+ publishSavedSelfDeviceName,+ selfDeviceNameKey,SETTINGS_DEVICE_TIMEOUT_MS,useSettingsDeviceDirectory,} from '@/session/settingsDeviceDirectory';@@ -74,6 +75,7 @@ export default function RenameSelfDeviceScreen() {const writeName = useCallback(async (kind: 'rename' | 'reset') => {const deviceId = auth.deviceId;+ const accountGeneration = auth.accountGeneration;if (!deviceId) {setMessage({ kind: 'error', text: t('settings.deviceNameEditor.deviceInitializing') });return;@@ -90,7 +92,7 @@ export default function RenameSelfDeviceScreen() {timeoutMs: SETTINGS_DEVICE_TIMEOUT_MS,},);- publishSelfDeviceName(deviceId, res.name);+ publishSavedSelfDeviceName(selfDeviceNameKey(accountGeneration, deviceId), res.name);if (!mountedRef.current) return;touchedRef.current = false;setDraft(res.name);@@ -122,7 +124,9 @@ export default function RenameSelfDeviceScreen() {}, [back, dirty, leaveAfterSave]);// 有未保存改动时拦截所有离开方式(顶栏返回、iOS 边缘右滑、Android 返回键)。- usePreventRemove(dirty && !leaveAfterSave, ({ data }) => {+ // 写入进行中也不能离开:已发出的请求无法可靠撤回,此时「放弃」并不能真的放弃。+ usePreventRemove(saving || (dirty && !leaveAfterSave), ({ data }) => {+ if (saving) return;Alert.alert(t('settings.deviceNameEditor.discardTitle'),t('settings.deviceNameEditor.discardBody'),diff --git a/apps/mobile/modules/cindy-composer-morph/ios/CindyComposerMorphModule.swift b/apps/mobile/modules/cindy-composer-morph/ios/CindyComposerMorphModule.swiftindex 71663b4044..aa8ecec1a1 100644--- a/apps/mobile/modules/cindy-composer-morph/ios/CindyComposerMorphModule.swift+++ b/apps/mobile/modules/cindy-composer-morph/ios/CindyComposerMorphModule.swift@@ -115,8 +115,20 @@ final class CindyComposerMorphSource: ExpoView {["id": id, "x": rect.minX, "y": rect.minY, "width": rect.width, "height": rect.height,"windowWidth": window.bounds.width, "windowHeight": window.bounds.height]}+ /// Same rule as expo-glass-effect's `isLiquidGlassAvailable`: without Liquid+ /// Glass the new-task composer mounts no morph target, so no overlay may start.+ private static let liquidGlassAvailable: Bool = {+ #if compiler(>=6.2)+ if #available(iOS 26.0, *) {+ return (Bundle.main.infoDictionary?["UIDesignRequiresCompatibility"] as? Bool) != true+ }+ #endif+ return false+ }()static func begin(source: UIView, window: UIWindow) -> [String: Any]? {current?.finish()+ // No origin → the caller navigates normally, with the regular push animation.+ guard liquidGlassAvailable else { return nil }let rect = source.convert(source.bounds, to: window)guard window.bounds.contains(rect), !rect.isEmpty,let backdrop = window.snapshotView(afterScreenUpdates: false),diff --git a/apps/mobile/src/__tests__/deviceManagementSections.test.ts b/apps/mobile/src/__tests__/deviceManagementSections.test.tsnew file mode 100644index 0000000000..101f2d0bd5--- /dev/null+++ b/apps/mobile/src/__tests__/deviceManagementSections.test.ts@@ -0,0 +1,33 @@+import { describe, expect, it } from 'vitest';+import type { DeviceAccessState, DeviceListDeviceLike, DeviceListItem } from '@cindy/maker-shared/device-list';+import { buildDeviceManagementSections } from '@/session/deviceManagementSections';++function row(id: string, online: boolean, state: DeviceAccessState, lastSeenAt: string | null = null): DeviceListItem {+ const device: DeviceListDeviceLike = {+ busy: false, deviceId: id, isSelf: false, lastSeenAt, name: `Mac ${id}`, online, platform: 'darwin', remoteControlEnabled: true,+ };+ return { canOpen: state === 'ready', device, state, statusDetail: '', statusLabel: '' };+}++describe('buildDeviceManagementSections', () => {+ it('groups by the device being online, not by the access state label', () => {+ // 状态先判「已撤销访问」再判离线:已撤销且离线的设备 state 是 access_revoked。+ const sections = buildDeviceManagementSections([+ row('ready', true, 'ready'),+ row('revoked-online', true, 'access_revoked'),+ row('revoked-offline', false, 'access_revoked'),+ row('offline', false, 'offline'),+ ]);+ expect(sections.online.map((r) => r.device.deviceId)).toEqual(['ready', 'revoked-online']);+ expect(sections.offline.map((r) => r.device.deviceId).sort()).toEqual(['offline', 'revoked-offline']);+ });++ it('puts the most recently seen offline device first', () => {+ const sections = buildDeviceManagementSections([+ row('old', false, 'offline', '2026-09-01T00:00:00Z'),+ row('never', false, 'offline', null),+ row('new', false, 'offline', '2026-09-28T00:00:00Z'),+ ]);+ expect(sections.offline.map((r) => r.device.deviceId)).toEqual(['new', 'old', 'never']);+ });+});diff --git a/apps/mobile/src/__tests__/mobileSettings.test.ts b/apps/mobile/src/__tests__/mobileSettings.test.tsindex 0ec769700b..fb5a3a4365 100644--- a/apps/mobile/src/__tests__/mobileSettings.test.ts+++ b/apps/mobile/src/__tests__/mobileSettings.test.ts@@ -214,7 +214,11 @@ describe('mobile settings overview', () => {// 名称正本仍是 device-link 设备清单。expect(directory).toContain("auth.apiFetch<{ devices: DeviceView[] }>('/api/device-link/devices'");expect(directory).toContain('const self = res.devices.find((device) => device.deviceId === selfDeviceId);');- expect(directory).toContain('export function publishSelfDeviceName');+ expect(directory).toContain('export function publishSavedSelfDeviceName');+ // 共享名称按「账号代次 + deviceId」隔离:同一台手机换账号不串名。+ expect(directory).toContain('return `${accountGeneration}:${deviceId}`;');+ // 读取发起后若已有新保存,旧快照不覆盖刚存的名称。+ expect(directory).toContain('if (selfDeviceNameWrites === writesAtStart) publish(');expect(editor).toContain('testID="settings.renameSelfDevice.screen"');expect(editor).toContain('backTestID="settings.renameSelfDevice.backButton"');@@ -226,10 +230,12 @@ describe('mobile settings overview', () => {expect(editor).toContain('`/api/device-link/devices/${encodeURIComponent(deviceId)}`');expect(editor).toContain("method: 'PATCH'");expect(editor).toContain("body: kind === 'reset' ? { name: null } : { name: trimmedDraft }");- expect(editor).toContain('publishSelfDeviceName(deviceId, res.name);');+ expect(editor).toContain('publishSavedSelfDeviceName(selfDeviceNameKey(accountGeneration, deviceId), res.name);');// 保存按钮只在有改动且非空时可用;离开时不再静默保存,有改动先确认放弃。expect(editor).toContain('const canSave = dirty && trimmedDraft.length > 0 && !saving;');- expect(editor).toContain('usePreventRemove(dirty && !leaveAfterSave');+ // 写入进行中不能离开(已发出的 PATCH 撤不回,「放弃」名不副实)。+ expect(editor).toContain('usePreventRemove(saving || (dirty && !leaveAfterSave)');+ expect(editor).toContain('if (saving) return;');expect(editor).toContain("t('settings.deviceNameEditor.discardTitle')");expect(editor).not.toContain('setTimeout(() => {');expect(editor).not.toContain('acceptClosedDraft');diff --git a/apps/mobile/src/session/deviceManagementSections.ts b/apps/mobile/src/session/deviceManagementSections.tsindex 5399af3209..2e20e874c0 100644--- a/apps/mobile/src/session/deviceManagementSections.ts+++ b/apps/mobile/src/session/deviceManagementSections.ts@@ -6,7 +6,7 @@ export const DEVICE_MANAGEMENT_OFFLINE_PREVIEW_COUNT = 3;export interface DeviceManagementSections<TDevice extends DeviceListDeviceLike> {/** 在线设备(可控在前;含未开远控 / 已撤销访问的在线设备),保持共享排序。 */online: DeviceListItem<TDevice>[];- /** 离线设备:按最近在线时间倒序(没有记录的排最后),同时间按名称。 */+ /** 离线设备(含已撤销访问的离线设备):按最近在线时间倒序(没有记录的排最后),同时间按名称。 */offline: DeviceListItem<TDevice>[];}@@ -26,7 +26,8 @@ export function buildDeviceManagementSections<TDevice extends DeviceListDeviceLiconst online: DeviceListItem<TDevice>[] = [];const offline: DeviceListItem<TDevice>[] = [];for (const row of rows) {- if (row.state === 'offline') offline.push(row);+ // 按设备真实在线状态分组:状态会先判「已撤销访问」,离线的已撤销设备 state 不是 offline。+ if (!row.device.online) offline.push(row);else online.push(row);}offline.sort((a, b) =>diff --git a/apps/mobile/src/session/settingsDeviceDirectory.ts b/apps/mobile/src/session/settingsDeviceDirectory.tsindex 963d702d96..4bf42e0a78 100644--- a/apps/mobile/src/session/settingsDeviceDirectory.ts+++ b/apps/mobile/src/session/settingsDeviceDirectory.ts@@ -14,24 +14,37 @@ export const SETTINGS_DEVICE_TIMEOUT_MS = 12_000;/*** 本机名称的进程内最新值。设置页与「设备名称」子页是两个路由:子页保存成功后* 在这里发布,设置页返回时立即显示新名称,不用等下一次设备清单请求。- * 按 deviceId 记,换账号 / 换设备 ID 后旧值自动失效。+ * 按「账号代次 + deviceId」记:同一台手机换账号时 deviceId 不变,只按 deviceId+ * 会把上一个账号的名称显示给新账号。*/-let publishedSelfDeviceName: { deviceId: string; name: string } | null = null;+let publishedSelfDeviceName: { key: string; name: string } | null = null;+/** 每次保存成功 +1;读取只在发起后没有新保存时才发布,避免旧快照盖掉刚存的名称。 */+let selfDeviceNameWrites = 0;const selfDeviceNameListeners = new Set<() => void>();-export function publishSelfDeviceName(deviceId: string, name: string | null): void {- publishedSelfDeviceName = name ? { deviceId, name } : null;+export function selfDeviceNameKey(accountGeneration: number, deviceId: string): string {+ return `${accountGeneration}:${deviceId}`;+}++function publish(value: { key: string; name: string } | null): void {+ publishedSelfDeviceName = value;selfDeviceNameListeners.forEach((listener) => listener());}+/** 保存(改名 / 恢复默认)成功后发布服务端返回的名称。 */+export function publishSavedSelfDeviceName(key: string, name: string | null): void {+ selfDeviceNameWrites += 1;+ publish(name ? { key, name } : null);+}+function subscribeSelfDeviceName(listener: () => void): () => void {selfDeviceNameListeners.add(listener);return () => selfDeviceNameListeners.delete(listener);}-function usePublishedSelfDeviceName(deviceId: string | null | undefined): string | null {+function usePublishedSelfDeviceName(key: string | null): string | null {const published = useSyncExternalStore(subscribeSelfDeviceName, () => publishedSelfDeviceName);- return deviceId && published?.deviceId === deviceId ? published.name : null;+ return key && published?.key === key ? published.name : null;}/**@@ -45,17 +58,20 @@ export function useSettingsDeviceDirectory(): {const auth = useAuth();const { lastPresenceSnapshot } = useDeviceLink();const [desktopDevices, setDesktopDevices] = useState<readonly MobileVoiceDictionaryHost[]>([]);- const publishedName = usePublishedSelfDeviceName(auth.deviceId);+ const selfKey = auth.isAuthenticated && auth.deviceId ? selfDeviceNameKey(auth.accountGeneration, auth.deviceId) : null;+ const publishedName = usePublishedSelfDeviceName(selfKey);useEffect(() => {if (!auth.isAuthenticated || !auth.deviceId) {- if (publishedSelfDeviceName) publishSelfDeviceName('', null);+ if (publishedSelfDeviceName) publish(null);// 登出/未登录才清空电脑列表 —— 拉取失败不清(见下面 catch 的说明)。setDesktopDevices([]);return;}const selfDeviceId = auth.deviceId;+ const key = selfDeviceNameKey(auth.accountGeneration, selfDeviceId);+ const writesAtStart = selfDeviceNameWrites;let cancelled = false;void auth.apiFetch<{ devices: DeviceView[] }>('/api/device-link/devices', {baseUrl: DEVICE_LINK_API_BASE_URL,@@ -64,7 +80,8 @@ export function useSettingsDeviceDirectory(): {.then((res) => {if (cancelled) return;const self = res.devices.find((device) => device.deviceId === selfDeviceId);- publishSelfDeviceName(selfDeviceId, self?.name?.trim() || null);+ // 请求期间刚保存过名称时,这份快照可能早于那次写入,不能拿来覆盖。+ if (selfDeviceNameWrites === writesAtStart) publish(self?.name?.trim() ? { key, name: self.name.trim() } : null);// 同一份设备清单顺带筛出电脑:词典正本在电脑上,手机按电脑分别展示。setDesktopDevices(collectMobileVoiceDictionaryHosts(res.devices));})