From a67119845d4f1cc0b4baf552aaa41300f245464a Mon Sep 17 00:00:00 2001 From: winewill Date: Thu, 24 Sep 2026 01:17:20 +0800 Subject: [PATCH] fix(desktop): align update fixtures and clear deferred startup focus --- apps/desktop/README.i18n.yaml | 4 ++-- apps/desktop/README.md | 2 +- apps/desktop/README.zh.md | 2 +- apps/desktop/src/locale.ts | 18 ++++++++++++++++++ apps/desktop/src/main.ts | 12 ++++++------ apps/desktop/tests/fixtures/update-dialogs.mjs | 10 ++++------ .../tests/fixtures/workspace-updates.mjs | 7 ++++--- apps/desktop/tests/main-startup.spec.ts | 7 ++++--- apps/desktop/tests/welcome-startup.spec.ts | 15 ++++++++++++++- 9 files changed, 54 insertions(+), 23 deletions(-) diff --git a/apps/desktop/README.i18n.yaml b/apps/desktop/README.i18n.yaml index 934c13fa16..7bfcfed3a5 100644 --- a/apps/desktop/README.i18n.yaml +++ b/apps/desktop/README.i18n.yaml @@ -48,8 +48,8 @@ en: 8efe3498dbe8686d zh: a88c16f20a9430f3 /deepseek-harness-desktop/updates: - en: 3165f47019b67cda - zh: 73e209b372e59d43 + en: a40f7aa2b00ed6fb + zh: d852a2d9de576dc5 /deepseek-harness-desktop/updates/mandatory-update-policy: en: 2f789a4949fafb12 zh: d8b28c01cfee11b7 diff --git a/apps/desktop/README.md b/apps/desktop/README.md index 26516b5628..c1175659fe 100644 --- a/apps/desktop/README.md +++ b/apps/desktop/README.md @@ -354,7 +354,7 @@ An unpacked artifact contains Electron, the materialized dsh production tree, pn ## Updates -On Windows, the downloaded-update confirmation explains that the application closes during installation, reopens automatically, and should not be launched again while updating. An installer restart carrying `--updated` raises and focuses the main window once after the workspace opens, without enabling always-on-top. Ordinary launches and other platforms do not use this foregrounding step. +On Windows, the downloaded-update confirmation explains that the application closes during installation, reopens automatically, and should not be launched again while updating. An installer restart carrying `--updated` raises and focuses the main window once when startup opens the workspace directly, without enabling always-on-top. Startup into the welcome page discards that request so a later login keeps its normal activation behavior. Ordinary launches and other platforms do not use this foregrounding step. Native update overlays wait for a ready document and a visible parent, and reappear when that parent is shown again. Closing an overlay releases its background blur, input interception, and parent listeners. The [local window qualification](tests/README.md#verification-overlay) exercises these transitions without starting a workspace. diff --git a/apps/desktop/README.zh.md b/apps/desktop/README.zh.md index 55dd003a7e..16f8ddbee7 100644 --- a/apps/desktop/README.zh.md +++ b/apps/desktop/README.zh.md @@ -356,7 +356,7 @@ macOS 打包在组装 App 时、代码签名前写入 `Contents/Resources/app-up ## 更新 -Windows 下载完成后的更新确认说明应用会在安装期间关闭、完成后自动打开,并提示期间不要重复启动。安装器携带 `--updated` 重启应用时,壳会在工作区打开后将主窗口前置并聚焦一次,不启用永久置顶。普通启动和其他平台不执行此前置步骤。 +Windows 下载完成后的更新确认说明应用会在安装期间关闭、完成后自动打开,并提示期间不要重复启动。安装器携带 `--updated` 重启应用并直接打开工作区时,壳会将主窗口前置并聚焦一次,不启用永久置顶。启动进入欢迎页时会清除此请求,使后续登录保留正常的激活行为。普通启动和其他平台不执行此前置步骤。 原生更新浮层在文档就绪且父窗口可见时显示,并在父窗口再次显示时恢复。关闭浮层会释放背景模糊、输入拦截和父窗口监听。[本地窗口验证](tests/README.zh.md#verification-overlay)无需启动工作区即可检查这些切换。 diff --git a/apps/desktop/src/locale.ts b/apps/desktop/src/locale.ts index bd27dbe54d..7c589df70b 100644 --- a/apps/desktop/src/locale.ts +++ b/apps/desktop/src/locale.ts @@ -303,3 +303,21 @@ export function formatDesktopMessage( ): string { return message.replaceAll(/\{([^{}]+)\}/gu, (placeholder, key: string) => values[key] ?? placeholder) } + +/** + * Select localized copy for an ordinary downloaded-update confirmation. + * @param messages - Selected Desktop dictionary. + * @param version - Prepared update version without a leading v. + * @param platform - Operating system presenting the confirmation. + * @returns The versioned title and installation guidance. + */ +export function desktopUpdateReadyConfirmation( + messages: DesktopMessages, + version: string, + platform: string, +): { message: string; detail: string } { + return { + message: formatDesktopMessage(platform === 'win32' ? messages.updateDownloadedTitleWindows : messages.updateDownloadedTitle, { version }), + detail: platform === 'win32' ? messages.updateDownloadedDetailWindows : messages.updateDownloadedDetail, + } +} diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts index 2e3aa65904..b10ff30716 100644 --- a/apps/desktop/src/main.ts +++ b/apps/desktop/src/main.ts @@ -28,7 +28,7 @@ import { installDesktopDirectoryPicker } from './directory-picker.ts' import { installMicrophonePermissions } from './microphone-permissions.ts' import { DesktopBackendController } from './backend-controller.ts' import { DESKTOP_IPC, SCHEME, assertDesktopSender, type DesktopUpdateState } from './ipc.ts' -import { formatDesktopMessage, resolveDesktopLocale, resolveDesktopStartupLocale } from './locale.ts' +import { desktopUpdateReadyConfirmation, formatDesktopMessage, resolveDesktopLocale, resolveDesktopStartupLocale } from './locale.ts' import { claimDesktopSingleInstance } from './single-instance.ts' import { DesktopUpdateCoordinator } from './update-coordinator.ts' import { serveWebDocument, authenticateWebHost, forwardWebRequest } from './web-document.ts' @@ -529,13 +529,11 @@ async function main(): Promise { const host = backend.host if (host === undefined) throw new DesktopUpdatePreparationError('tasks-unavailable', locale.messages.updateTasksUnavailable) const active = await host.updateTasks('inspect') + const ready = desktopUpdateReadyConfirmation(locale.messages, updates.state.version ?? '', process.platform) const confirmation: Electron.MessageBoxOptions = { type: active ? 'warning' : 'info', title: locale.messages.updateTitle, - message: active ? locale.messages.updateActiveTasks : formatDesktopMessage( - process.platform === 'win32' ? locale.messages.updateDownloadedTitleWindows : locale.messages.updateDownloadedTitle, - { version: updates.state.version ?? '' }), - detail: active ? locale.messages.updateActiveTasksDetail - : process.platform === 'win32' ? locale.messages.updateDownloadedDetailWindows : locale.messages.updateDownloadedDetail, + message: active ? locale.messages.updateActiveTasks : ready.message, + detail: active ? locale.messages.updateActiveTasksDetail : ready.detail, buttons: active ? [locale.messages.updateStopTasks, locale.messages.updateLater] : [locale.messages.installAndRestart], defaultId: 1, cancelId: 1, } @@ -1053,6 +1051,8 @@ async function main(): Promise { windowsLanguage = locale.id refreshApplicationMenu() if (!enteredWorkspace && needsWelcome({ loggedIn: state.loggedIn, hasApiKey: state.hasApiKey })) { + // A later login must retain its own activation policy instead of replaying startup focus. + raiseAfterUpdate = false await showWelcome() } else { await enterWorkspace() diff --git a/apps/desktop/tests/fixtures/update-dialogs.mjs b/apps/desktop/tests/fixtures/update-dialogs.mjs index 0282a26c75..9cb07be7c9 100644 --- a/apps/desktop/tests/fixtures/update-dialogs.mjs +++ b/apps/desktop/tests/fixtures/update-dialogs.mjs @@ -6,7 +6,7 @@ import { join } from 'node:path' import { fileURLToPath } from 'node:url' import { app, BrowserWindow, protocol } from 'electron' import { DesktopUpdateDialog } from '../../lib/types/update-dialog.js' -import { formatDesktopMessage, resolveDesktopLocale } from '../../lib/types/locale.js' +import { desktopUpdateReadyConfirmation, resolveDesktopLocale } from '../../lib/types/locale.js' async function rendered(window) { await window.webContents.executeJavaScript(`new Promise((resolve, reject) => { @@ -38,13 +38,11 @@ export async function qualifyUpdateDialogs(root, fixture) { await f.coordinator.download(available.version) assert.equal(f.installations.length, 0) for (const active of [false, true]) { + const ready = desktopUpdateReadyConfirmation(messages, available.version, process.platform) const options = { title: messages.updateTitle, - message: active ? messages.updateActiveTasks : formatDesktopMessage( - process.platform === 'win32' ? messages.updateDownloadedTitleWindows : messages.updateDownloadedTitle, - { version: available.version }), - detail: active ? messages.updateActiveTasksDetail - : process.platform === 'win32' ? messages.updateDownloadedDetailWindows : messages.updateDownloadedDetail, + message: active ? messages.updateActiveTasks : ready.message, + detail: active ? messages.updateActiveTasksDetail : ready.detail, buttons: active ? [messages.updateStopTasks, messages.updateLater] : [messages.installAndRestart], cancelId: 1, } f.restart(async () => (await dialogs.show(parent, options)).response === 0) diff --git a/apps/desktop/tests/fixtures/workspace-updates.mjs b/apps/desktop/tests/fixtures/workspace-updates.mjs index 51e930cb2f..b136c79ce0 100644 --- a/apps/desktop/tests/fixtures/workspace-updates.mjs +++ b/apps/desktop/tests/fixtures/workspace-updates.mjs @@ -11,7 +11,7 @@ import updaterModule from 'electron-updater' import { createUpdateServer } from './update-server.mjs' import { fixture } from './workspace-update-adapters.mjs' import { DesktopUpdateHttpExecutor } from '../../lib/types/update-http-executor.js' -import { resolveDesktopLocale } from '../../lib/types/locale.js' +import { desktopUpdateReadyConfirmation, resolveDesktopLocale } from '../../lib/types/locale.js' const root = process.env.DSH_WORKSPACE_UPDATE_ROOT assert.ok(root) @@ -252,7 +252,8 @@ async function qualify() { assert.equal(BrowserWindow.getAllWindows().some(window => window.webContents.getURL() === 'dsh-app://shell/update-dialog.html'), false) await screenshot(mainWindow, 'downloading.png') server.release() - const ready = await dialogWith(messages.updateDownloadedTitle.replace('{version}', '0.1.6-nightly.1')) + const confirmation = desktopUpdateReadyConfirmation(messages, '0.1.6-nightly.1', process.platform) + const ready = await dialogWith(confirmation.message) assert.equal(fixture.installations.length, 0) await screenshot(ready, 'install-confirmation.png') cases.push('sidebar-retry-direct-download-and-separate-install-dialog') @@ -337,7 +338,7 @@ async function qualify() { await waitFor(() => fixture.host !== stoppedHost && fixture.readyHosts.has(fixture.host), 'replacement Host after non-graceful shutdown') await waitFor(async () => !await fixture.host.updateTasks('inspect'), 'replacement Host ready without active work') await press(mainWindow, `document.querySelector('button[data-error="true"]')`) - const retryInstall = await dialogWith(messages.updateDownloadedTitle.replace('{version}', '0.1.6-nightly.1')) + const retryInstall = await dialogWith(confirmation.message) assert.equal(fixture.installations.length, 0) await screenshot(retryInstall, 'recovered-install-confirmation.png') await press(retryInstall, `document.getElementById('close')`) diff --git a/apps/desktop/tests/main-startup.spec.ts b/apps/desktop/tests/main-startup.spec.ts index 255cfe9e5d..a52cd60e0b 100644 --- a/apps/desktop/tests/main-startup.spec.ts +++ b/apps/desktop/tests/main-startup.spec.ts @@ -77,7 +77,8 @@ const harness = await vi.hoisted(async () => { if (channel === 'dsh-desktop:mandatory-state' && state.policy?.blocking) policyBlocked.resolve() }), }) - readonly show = vi.fn() + readonly shown = deferred() + readonly show = vi.fn(() => { this.shown.resolve() }) readonly hide = vi.fn() readonly focus = vi.fn() readonly moveTop = vi.fn() @@ -989,7 +990,7 @@ describe('desktop main startup', () => { harness.prepared.resolve() await harness.hostStarted.promise harness.hosts[0]!.ready.resolve() - await vi.advanceTimersByTimeAsync(0) + await window.shown.promise expect(window.show).toHaveBeenCalledOnce() expect(window.moveTop).toHaveBeenCalledTimes(raises ? 1 : 0) expect(window.focus).toHaveBeenCalledTimes(raises ? 1 : 0) @@ -999,8 +1000,8 @@ describe('desktop main startup', () => { } window.destroy() harness.app.emit('second-instance') - await vi.advanceTimersByTimeAsync(0) const replacement = harness.windows[1]! + await replacement.shown.promise expect(replacement.show).toHaveBeenCalledOnce() expect(replacement.moveTop).not.toHaveBeenCalled() expect(replacement.setAlwaysOnTop).not.toHaveBeenCalled() diff --git a/apps/desktop/tests/welcome-startup.spec.ts b/apps/desktop/tests/welcome-startup.spec.ts index 0629083a8a..6e1f469eef 100644 --- a/apps/desktop/tests/welcome-startup.spec.ts +++ b/apps/desktop/tests/welcome-startup.spec.ts @@ -26,6 +26,7 @@ const state = vi.hoisted(() => ({ showWorkspace: vi.fn(), showInactiveWorkspace: vi.fn(), focusWorkspace: vi.fn(), + moveTopWorkspace: vi.fn(), openDevTools: vi.fn(), closeWelcome: vi.fn(), welcomeLocale: undefined as DesktopLocale | undefined, @@ -77,6 +78,7 @@ vi.mock('electron', () => ({ isMinimized() { return false } restore = vi.fn() focus = state.focusWorkspace + moveTop = state.moveTopWorkspace hide = vi.fn() show = state.showWorkspace showInactive = state.showInactiveWorkspace @@ -157,10 +159,18 @@ afterEach(() => { vi.clearAllTimers() vi.useRealTimers() vi.unstubAllEnvs() + vi.unstubAllGlobals() vi.restoreAllMocks() }) -it('starts the Host for welcome onboarding and opens the workspace on skip without quitting', async () => { +it.each([false, true])('starts welcome onboarding without carrying update focus into login or skip (Windows update=%s)', async (updated) => { + vi.resetModules() + vi.clearAllMocks() + state.preference = 'zh' + state.hasApiKey = false + state.operations = undefined + state.accountState.mockResolvedValue({ status: 'signed-out', attempt: null, links: { usageUrl: '', topUpUrl: '' } }) + if (updated) vi.stubGlobal('process', { ...process, platform: 'win32', argv: ['desktop', '--updated'] }) vi.useFakeTimers() vi.stubEnv('DSH_DESKTOP_DEV_PROJECT_DIR', '/development-profile') vi.stubEnv('DSH_DESKTOP_NODE_BINARY', '/runtime/node') @@ -217,6 +227,8 @@ it('starts the Host for welcome onboarding and opens the workspace on skip witho await state.operations!.skip() expect(state.loadWorkspace).not.toHaveBeenCalled() expect(state.showWorkspace).toHaveBeenCalledOnce() + expect(state.moveTopWorkspace).not.toHaveBeenCalled() + expect(state.focusWorkspace).not.toHaveBeenCalled() expect(state.windowOptions).toMatchObject({ ...(process.platform === 'darwin' ? { titleBarStyle: 'hiddenInset', trafficLightPosition: { x: 16, y: 18 }, vibrancy: 'sidebar' } : {}), webPreferences: { contextIsolation: true, sandbox: true }, @@ -271,6 +283,7 @@ it('starts the Host for welcome onboarding and opens the workspace on skip witho await vi.waitFor(() => { expect(state.showInactiveWorkspace).toHaveBeenCalledOnce() }) expect(state.showWorkspace).not.toHaveBeenCalled() expect(state.focusWorkspace).not.toHaveBeenCalled() + expect(state.moveTopWorkspace).not.toHaveBeenCalled() expect(state.openDevTools).not.toHaveBeenCalled() state.appListeners.get('open-url')!({ preventDefault: vi.fn() }, 'dsh://open') expect(state.showWorkspace).toHaveBeenCalledOnce()