Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 区分更新卡的稍后与取消操作
Dashc6f852047305
diff --git a/apps/mobile/src/update/androidInstallController.test.ts b/apps/mobile/src/update/androidInstallController.test.tsindex 26c1354f7e..f319c9e7a7 100644--- a/apps/mobile/src/update/androidInstallController.test.ts+++ b/apps/mobile/src/update/androidInstallController.test.ts@@ -26,6 +26,51 @@ function setup(overrides: Partial<AndroidInstallIO> = {}) {}describe('Android in-app installation', () => {+ // PR #6977 discussion_r4359353797 (unit): the previous Later fix also+ // suppressed Cancel. Drive manual close -> automatic rediscovery -> stale+ // resolve/reject; existing tests only reopened manually, bypassing suppression.+ it.each(['downloading', 'installing'] as const)('Cancel during %s still allows automatic rediscovery', async (phase) => {+ const oldDownload = deferred<string>();+ const oldInstall = deferred<void>();+ let oldSignal!: AbortSignal;+ let waitingDownload = phase === 'downloading';+ const { controller, io } = setup({+ hasPermission: vi.fn(async () => true),+ download: vi.fn(async (_url: string, signal: AbortSignal) => {+ if (waitingDownload) {+ waitingDownload = false;+ oldSignal = signal;+ return oldDownload.promise;+ }+ return file;+ }),+ install: vi.fn(async (_file: string, _version: string, signal: AbortSignal) => {+ oldSignal = signal;+ return oldInstall.promise;+ }),+ });+ controller.start(target); await settle();+ expect(controller.getSnapshot().phase).toBe(phase);+ controller.close();+ expect(oldSignal.aborted).toBe(true);+ controller.start(target, { automatic: true }); await settle();+ expect(controller.getSnapshot().phase).toBe('ready');+ if (phase === 'downloading') oldDownload.resolve(file);+ else oldInstall.reject(new Error('cancelled old install'));+ await settle();+ expect(controller.getSnapshot().phase).toBe('ready');+ expect(io.install).toHaveBeenCalledTimes(phase === 'installing' ? 1 : 0);+ });++ it('replacing a ready target does not count as choosing Later', async () => {+ const { controller } = setup();+ const newer = { ...target, version: '1.2.4' };+ controller.start(target, { automatic: true }); await settle();+ controller.start(newer, { automatic: true }); await settle();+ controller.start(target, { automatic: true }); await settle();+ expect(controller.getSnapshot()).toMatchObject({ phase: 'ready', target });+ });+// PR #6977: permission/denial cards also expose Later. Existing dismissal// coverage only closed ready; the same target must stay suppressed here too.it.each([false, true])('remembers Later from the permission card (denied=%s)', async (denied) => {diff --git a/apps/mobile/src/update/androidInstallController.ts b/apps/mobile/src/update/androidInstallController.tsindex c1dee1c679..c5009c5dd9 100644--- a/apps/mobile/src/update/androidInstallController.ts+++ b/apps/mobile/src/update/androidInstallController.ts@@ -26,6 +26,12 @@ export interface AndroidInstallIO {}const IDLE: AndroidInstallState = { phase: 'idle', target: null, progress: null };+/** The button label and its effect share one rule: Cancel stops this operation;+ * Later suppresses subsequent automatic offers for the target. */+export function androidUpdateDismissAction(phase: AndroidInstallPhase): 'later' | 'cancel' {+ return phase === 'downloading' || phase === 'installing' ? 'cancel' : 'later';+}+export function isDirectApkUrl(value: string): boolean {try {const url = new URL(value);@@ -64,7 +70,7 @@ export class AndroidInstallController {// obsolete silent target, but must not interrupt a user's installation.if (same && options.automatic) return true;if (!this.state.silent && !(this.state.phase === 'ready' && !same && !this.operation)) return true;- this.close();+ this.cancel();}this.awaitingConfirm = options.confirm === true;this.update({ phase: 'permission', target, progress: null, silent: options.automatic === true });@@ -145,7 +151,7 @@ export class AndroidInstallController {}close = (): void => {- if (!this.state.silent && this.state.target) {+ if (!this.state.silent && this.state.target && androidUpdateDismissAction(this.state.phase) === 'later') {this.dismissedAutomaticTarget = JSON.stringify([this.state.target.installUrl, this.state.target.version]);}this.cancel();diff --git a/apps/mobile/src/update/androidUpdatePresentation.ts b/apps/mobile/src/update/androidUpdatePresentation.tsindex 9d7eeae560..738597a93e 100644--- a/apps/mobile/src/update/androidUpdatePresentation.ts+++ b/apps/mobile/src/update/androidUpdatePresentation.ts@@ -1,4 +1,4 @@-import type { AndroidInstallPhase } from './androidInstallController';+import { androidUpdateDismissAction, type AndroidInstallPhase } from './androidInstallController';/** What the single Android update card shows for each installer phase. No React/native imports. */export interface AndroidUpdatePresentation {@@ -15,7 +15,7 @@ export interface AndroidUpdatePresentation {}export function presentAndroidUpdate(phase: AndroidInstallPhase, progress: number | null): AndroidUpdatePresentation {- const base: AndroidUpdatePresentation = { note: null, progress: null, ready: false, primary: null, dismiss: 'later', browser: false };+ const base: AndroidUpdatePresentation = { note: null, progress: null, ready: false, primary: null, dismiss: androidUpdateDismissAction(phase), browser: false };switch (phase) {case 'offer':return { ...base, primary: { label: 'updateNow', busy: false } };@@ -26,9 +26,9 @@ export function presentAndroidUpdate(phase: AndroidInstallPhase, progress: numbecase 'permission-denied':return { ...base, note: 'denied', primary: { label: 'grantAgain', busy: false }, browser: true };case 'downloading':- return { ...base, progress: { value: progress, label: 'downloading' }, dismiss: 'cancel' };+ return { ...base, progress: { value: progress, label: 'downloading' } };case 'installing':- return { ...base, progress: { value: 1, label: 'installing' }, dismiss: 'cancel' };+ return { ...base, progress: { value: 1, label: 'installing' } };case 'ready':return { ...base, ready: true, primary: { label: 'install', busy: false }, browser: true };case 'error':diff --git a/docs/dev-rules/mobile-development.md b/docs/dev-rules/mobile-development.mdindex 409f5f0a75..aa9b1c8ffa 100644--- a/docs/dev-rules/mobile-development.md+++ b/docs/dev-rules/mobile-development.md@@ -405,6 +405,8 @@ JS OTA 仍按现有通道检查,设置页手动检查只报告内容更新。选择「稍后」后,本进程不再重复提示同一目标;手动检查仍可打开更新卡,明确确认后可在移动网络下载。权限说明或拒绝权限卡上的「稍后」也沿用同一规则。根部自动检查 hook 持有共享安装器的通道生命周期,通道变化或卸载时取消已启动的下载与安装卡,回前台启动的下载同样受此约束;取消不视为用户选择「稍后」。+ 下载与打开安装器期间按钮显示「取消」,仅终止当前操作,后续自动检查仍可在 Wi-Fi 下续传;+ 通道变化和目标替换也只取消旧操作,不记作「稍后」。按钮文案与抑制提示的行为共用同一阶段判据。强更屏的「去更新」本身就是确认,不再出现确认步骤。旧原生包、网页地址与 Play 安装仍走原系统对话框和既有出口。- 点击安装时已授权则直接使用已下载的包;未授权时卡内先说明权限,用户点「允许并更新」才打开系统设置,