fix(desktop): close the window with Cmd+W from the Platform page

Refs #8244
This commit is contained in:
Turtle committed 2026-11-10 17:13:14 +08:00
1 parent d79851e05d
commit 3d445a7ce6
10 files changed
+29 -10

No files matched your search

@@ -15,8 +15,8 @@
en: c26f81e8adf0128b
zh: e11ab371f51f66bc
/deepseek-ai-dsh-client-ui-settings-account/use-this-package:
en: ece8b18503977bdd
zh: 2d47640fb8367a3d
en: 9e61a6adc39fddbc
zh: fbcb4852ca4eded1
/deepseek-ai-dsh-client-ui-settings-account/use-this-package/desktop-onboarding:
en: 7ae4e68f9491b068
zh: f7478269bf8d28b3
@@ -38,7 +38,7 @@ Account operations carry this UI's client identity to the Host: build version, a
Balances use Platform Web currency formatting: two decimal places and digit grouping, positive amounts truncated to cents, positive sub-cent amounts shown as <0.01, and negative amounts rounded with a minimum displayed magnitude of 0.01. Raw Host balance strings remain unchanged.
Desktop usage, top-up, and onboarding recharge actions open one isolated native Platform view below a 48px return bar. The Desktop host owns a single such view, and opening a page destroys the previous one, so the plugin registers one shared host entry in `shell.overlay` and the Account settings page, the account quota notice, and the Desktop onboarding recharge page all request a page through its `PlatformPages` request channel instead of mounting their own container. Each request retires the previous owner before the newer page shows, and its identity-safe release clears only that request, so a stale owner cannot close a page it no longer owns. On Windows Electron the return bar and the native view start below the Desktop caption strip, so the Application and Edit menu text cannot cover the Back to DeepSeek Harness label. Back destroys the view, restores focus before any deferred Modal takes it, and preserves the Account settings page. Leaving a top-up page waits for any read already running and then reads again, because a top-up may have changed what the account holds. The Account settings page and the account quota notice re-read profile and balance and publish an account refresh for extensions; the onboarding recharge return re-reads profile and balance only. Superseding a page, releasing a request, plugin unload, and leaving usage all read nothing. Loading failures retain the return action and show a centered localized error with Retry. Retry reloads the same destination; renderer commands never receive the account token.
Desktop usage, top-up, and onboarding recharge actions open one isolated native Platform view below a 48px return bar. The Desktop host owns a single such view, and opening a page destroys the previous one, so the plugin registers one shared host entry in `shell.overlay` and the Account settings page, the account quota notice, and the Desktop onboarding recharge page all request a page through its `PlatformPages` request channel instead of mounting their own container. Each request retires the previous owner before the newer page shows, and its identity-safe release clears only that request, so a stale owner cannot close a page it no longer owns. On Windows Electron the return bar and the native view start below the Desktop caption strip, so the Application and Edit menu text cannot cover the Back to DeepSeek Harness label. Back destroys the view, restores focus before any deferred Modal takes it, and preserves the Account settings page. The page layer declares shortcut modal `platform` for the [right sidebar close command](../ui-sidebar-right/README.md). Leaving a top-up page waits for any read already running and then reads again, because a top-up may have changed what the account holds. The Account settings page and the account quota notice re-read profile and balance and publish an account refresh for extensions; the onboarding recharge return re-reads profile and balance only. Superseding a page, releasing a request, plugin unload, and leaving usage all read nothing. Loading failures retain the return action and show a centered localized error with Retry. Retry reloads the same destination; renderer commands never receive the account token.
Chat offers each live quota failure from a bound Session to the frame-wide `shell.quota-notice` chain from its host in `shell.overlay`, so the notice outlives the Chat panel that reported it. The account entry claims `ACCOUNT_QUOTA`: while an account credential is stored and the shared host entry exists, the Modal offers Cancel and Top up. While a page requested through the shared request channel is showing, the native view covers this document, so the entry paints neither the Modal nor the Toast. A quota failure that arrives while a Settings-opened page is already showing is not retained: it stays subject to newest-notice replacement, and the Modal appears after the viewer returns while that notice is still current. That Modal reports the failure of the original request, not the account's current balance: the top-up re-read is a separate read, and returning neither proves a successful payment nor dismisses the notice on its own. The notice's own Top up is the retained case: it calls `keepOpen()` and requests the `top-up` page through the shared request channel, keeping that notice and its page mounted through later quota failures. With the shared host entry the entry waits for the first account snapshot instead of rendering a Toast that its own timer could discard; a snapshot that reports no stored credential, or a failed account stream with no snapshot, then renders the same neutral warning Toast itself, and without that host entry the entry renders that Toast immediately, instead of relying on the chat host fallback. The entry owns the hold and its page request and releases both when it unmounts, so a later quota failure publishes again without replaying the dropped ones; dismissal or sign-out clears the hold and the page request. Close, Cancel, a sign-out, or leaving the notice's own embedded page takes the notice down without retrying the request.
@@ -38,7 +38,7 @@ Desktop 与普通 Web 客户端都挂载侧边栏账号菜单、账号设置、
余额沿用 Platform Web 的金额格式:两位小数和千分位分组,正金额截断至分,小于一分的正金额显示为 <0.01,负金额按舍入规则处理且显示绝对值至少为 0.01。Host 返回的原始余额字符串保持不变。
Desktop 的用量、充值与引导充值操作在 48px 返回栏下方打开同一个隔离的原生 Platform 视图。Desktop 宿主只有一个这样的视图,打开新页面会销毁上一个,因此插件在 `shell.overlay` 注册一个共享宿主条目,Account 设置页、账号欠费提示与 Desktop 引导充值页都通过其 `PlatformPages` 请求通道申请页面,而不再各自挂载容器。新请求会在新页面显示前退掉上一个持有者,其身份安全的释放只清除本次请求,因此过期的持有者无法关闭它已不再持有的页面。在 Windows Electron 中,返回栏与原生视图都从 Desktop 顶栏下方开始,Application 和 Edit 菜单文字不会盖住“返回 DeepSeek Harness”。返回操作销毁视图并保留 Account 设置页,且先恢复焦点,再由任何被延后的 Modal 接管。从充值页返回时会等待任何已在进行的读取结束后再读取,因为充值可能改变账号持有的内容。Account 设置页与账号欠费提示会重读资料、余额,并向扩展发布账号刷新事件;引导充值返回则只重读资料与余额。替换页面、释放请求、插件卸载与从用量页返回均不读取。加载失败时保留返回操作,居中显示本地化错误提示和“重试”按钮。重试重新加载同一目标页面;渲染进程命令不接收账号 token。
Desktop 的用量、充值与引导充值操作在 48px 返回栏下方打开同一个隔离的原生 Platform 视图。Desktop 宿主只有一个这样的视图,打开新页面会销毁上一个,因此插件在 `shell.overlay` 注册一个共享宿主条目,Account 设置页、账号欠费提示与 Desktop 引导充值页都通过其 `PlatformPages` 请求通道申请页面,而不再各自挂载容器。新请求会在新页面显示前退掉上一个持有者,其身份安全的释放只清除本次请求,因此过期的持有者无法关闭它已不再持有的页面。在 Windows Electron 中,返回栏与原生视图都从 Desktop 顶栏下方开始,Application 和 Edit 菜单文字不会盖住“返回 DeepSeek Harness”。返回操作销毁视图并保留 Account 设置页,且先恢复焦点,再由任何被延后的 Modal 接管。页面层为[右栏关闭命令](../ui-sidebar-right/README.zh.md)声明快捷键弹窗 `platform`。从充值页返回时会等待任何已在进行的读取结束后再读取,因为充值可能改变账号持有的内容。Account 设置页与账号欠费提示会重读资料、余额,并向扩展发布账号刷新事件;引导充值返回则只重读资料与余额。替换页面、释放请求、插件卸载与从用量页返回均不读取。加载失败时保留返回操作,居中显示本地化错误提示和“重试”按钮。重试重新加载同一目标页面;渲染进程命令不接收账号 token。
Chat 通过 `shell.overlay` 中的宿主把已绑定 Session 的实时欠费交给全局 `shell.quota-notice` 链,提示的生命周期因此长于上报它的 Chat 面板。账号条目认领 `ACCOUNT_QUOTA`:已存储账号凭证且存在共享宿主条目时,Modal 提供取消和去充值。只要通过该共享请求通道请求的页面正在显示,原生视图就会盖住本页,因此该条目既不绘制 Modal 也不绘制 Toast。在 Account 设置页已打开页面的情况下新到达的欠费不会被保持:它仍受最新提示替换规则约束,返回后若该提示仍是最新一条就显示 Modal。该 Modal 报告的是原始请求的失败,而不是账号当前余额:返回时的重读是一次独立读取,返回本身既不证明支付成功,也不会自动撤下该提示。提示自身的去充值属于被保持的情形:它调用 `keepOpen()` 并通过共享请求通道申请 `top-up` 页面,使该提示与其页面在后续欠费期间保持挂载。存在共享宿主条目时,该条目会等待首个账号快照,而不是渲染一个可能被自身计时器丢弃的 Toast;快照报告未存储凭证,或账号流失败且无快照时,才由该条目自行渲染同一段中立警告 Toast,缺少该宿主条目时则立即渲染该 Toast,而不依赖 Chat 宿主回退。该条目持有保持与页面请求,并在自身卸载时释放二者,因此后续欠费会重新发布而不重放已丢弃的提示;关闭与退出登录也会清除保持和页面请求。关闭、取消、退出登录或离开该提示自己的内嵌页面都会撤下提示,且不会重试请求。
@@ -66,7 +66,8 @@ export function PlatformOverlay({ bridge, page, backLabel, loadingLabel, failure
})
}
}, [bridge, page, attempt])
return createPortal(<div ref={layer} className={css.overlay} role="dialog" aria-modal="true" aria-label={backLabel}>
return createPortal(<div ref={layer} className={css.overlay} role="dialog" aria-modal="true" aria-label={backLabel}
data-shortcut-modal="platform">
<header className={css.header} data-window-drag>
<div className={css.controls}>
<span className={css.trafficLights} aria-hidden="true" />
@@ -309,6 +309,7 @@ it('opens usage inside Desktop and returns to the same Account settings', async
expect(platform.open).toHaveBeenCalledWith('usage', { x: 0, y: 0, width: 0, height: 0 })
const back = screen.getByRole('button', { name: en.backToHarness })
await expect(`${back.parentElement!.parentElement!.textContent}\n`).toMatchFileSnapshot('./expected/platform-header-en.txt')
expect(screen.getByRole('dialog', { name: en.backToHarness }).dataset.shortcutModal).toBe('platform')
await act(async () => { fireEvent.click(back) })
expect(platform.close).toHaveBeenCalledOnce()
expect(screen.queryByRole('button', { name: en.backToHarness })).toBeNull()
@@ -33,8 +33,8 @@
en: ce5622d6d18ed8d1
zh: 292932d8edb6e1c3
/deepseek-ai-dsh-client-ui-sidebar-right/the-tab-domain:
en: 717b86e05b44ebdd
zh: 0f4f694d0ea1d7f8
en: dd84612e98aa84ab
zh: a41ade6082222fd6
/deepseek-ai-dsh-client-ui-sidebar-right/the-guide:
en: 68fd575ef382223e
zh: 1ab1653ee20c64e9
+1 -1
View File
@@ -113,7 +113,7 @@ A type's `keepMounted: true` retains visited bodies across tab and Session chang
Tab owners register `registerCloseHandler(kind, handler)` through an effect. A handler synchronously retains any background cleanup before allowing explicit close or replacement. The resource owner tracks completion and retry; the sidebar does not wait. A thrown handler preserves the tab. Collapse, presentation changes and plugin disposal do not invoke close handlers; the tab abort signal identifies occurrence disposal, not an explicit close.
Close and refresh commands resolve the focused pane and tab occurrence. Page bodies bind their refresh operation through `tab.actions.bindCommands()` and release it on unmount; ended occurrences cannot regain capabilities. Refresh never reloads the application. Shortcut page opens, sidebar expansion, and all splits focus the selected dock or floating pane after its DOM commits, including singleton reveals and guide replacements. Sidebar expansion focuses the active dock pane; collapse preserves focus inside floating panes. Pane focus preserves existing text selections. If a focused page input or iframe is replaced, focus returns to its visible pane only while no other element owns focus; an outside pointer gesture or explicit blur cancels this restoration. Close checks the captured identity again and uses resource cleanup. After a keyboard or native-menu close, focus moves to a surviving visible pane in the same Session so consecutive close commands continue there. Stale targets and cleanup failures never fall back to closing a window. Modal restrictions follow the [shortcut service](../shortcuts/README.md). The close command first requests the foreground modal’s close action; a modal that declines dismissal, a menu, or an unregistered dialog blocks closing the sidebar or window behind it. Closing the sole docked guide with a shortcut or native menu collapses the sidebar and retains the guide. Desktop requests window closure through the shortcut service only when no modal is open and no sidebar page owns focus; Web leaves the browser open.
Close and refresh commands resolve the focused pane and tab occurrence. Page bodies bind their refresh operation through `tab.actions.bindCommands()` and release it on unmount; ended occurrences cannot regain capabilities. Refresh never reloads the application. Shortcut page opens, sidebar expansion, and all splits focus the selected dock or floating pane after its DOM commits, including singleton reveals and guide replacements. Sidebar expansion focuses the active dock pane; collapse preserves focus inside floating panes. Pane focus preserves existing text selections. If a focused page input or iframe is replaced, focus returns to its visible pane only while no other element owns focus; an outside pointer gesture or explicit blur cancels this restoration. Close checks the captured identity again and uses resource cleanup. After a keyboard or native-menu close, focus moves to a surviving visible pane in the same Session so consecutive close commands continue there. Stale targets and cleanup failures never fall back to closing a window. Modal restrictions follow the [shortcut service](../shortcuts/README.md). The close command first requests the foreground modal’s close action; a modal that declines dismissal, a menu, or an unregistered dialog blocks closing the sidebar or window behind it. Closing the sole docked guide with a shortcut or native menu collapses the sidebar and retains the guide. Desktop requests window closure through the shortcut service only when no modal is open and no sidebar page owns focus, or when the foreground modal is the Desktop Platform page (`platform`), which has only a back action; Web leaves the browser open.
<a id="the-guide"></a>
## The guide
@@ -113,7 +113,7 @@ Tab 域按(Session,Tab id)保留品牌化 occurrence id、导航、中止
标签页所有者通过 effect 注册 `registerCloseHandler(kind, handler)`。handler 在允许显式关闭或替换前同步保存后台清理任务。资源所有者跟踪完成和重试,侧栏不等待清理。handler 抛错时保留标签页。折叠、展示方式改变和插件卸载不调用关闭 handler;tab abort signal 标识 occurrence 卸载,不代表显式关闭。
关闭与刷新命令解析聚焦 pane 和 tab occurrence。页面通过 `tab.actions.bindCommands()` 绑定刷新操作,并在卸载时释放;已结束的 occurrence 不能重新获得能力。刷新不会重载应用。通过快捷键打开页面、展开侧栏或执行分栏操作后,焦点在 DOM 提交后移至选中的停靠或浮动分栏,包括显示已有单例页面和替换引导页。展开侧栏时聚焦活动停靠分栏;收起时保留浮动分栏内的焦点。分栏获得焦点时保留现有文本选区。聚焦的页面输入框或 iframe 被替换时,仅在没有其他元素持有焦点的情况下将焦点交还其可见分栏;外部指针操作或显式失焦会取消此次恢复。关闭会再次检查捕获的身份并执行资源清理。通过快捷键或原生菜单关闭后,焦点移至同一 Session 中仍可见的分栏,让连续关闭继续作用于右栏。过期目标和清理失败均不会回退为关窗。模态限制遵循[快捷键服务](../shortcuts/README.zh.md)。关闭命令优先请求前台弹窗的关闭操作;弹窗拒绝关闭、菜单或未注册的对话框都会阻止关闭后方侧栏或窗口。通过快捷键或原生菜单关闭唯一的停靠引导页时,收起右栏并保留引导页。Desktop 仅在没有弹窗且焦点没有所属的右栏页面时通过快捷键服务请求关闭窗口;Web 保留浏览器窗口。
关闭与刷新命令解析聚焦 pane 和 tab occurrence。页面通过 `tab.actions.bindCommands()` 绑定刷新操作,并在卸载时释放;已结束的 occurrence 不能重新获得能力。刷新不会重载应用。通过快捷键打开页面、展开侧栏或执行分栏操作后,焦点在 DOM 提交后移至选中的停靠或浮动分栏,包括显示已有单例页面和替换引导页。展开侧栏时聚焦活动停靠分栏;收起时保留浮动分栏内的焦点。分栏获得焦点时保留现有文本选区。聚焦的页面输入框或 iframe 被替换时,仅在没有其他元素持有焦点的情况下将焦点交还其可见分栏;外部指针操作或显式失焦会取消此次恢复。关闭会再次检查捕获的身份并执行资源清理。通过快捷键或原生菜单关闭后,焦点移至同一 Session 中仍可见的分栏,让连续关闭继续作用于右栏。过期目标和清理失败均不会回退为关窗。模态限制遵循[快捷键服务](../shortcuts/README.zh.md)。关闭命令优先请求前台弹窗的关闭操作;弹窗拒绝关闭、菜单或未注册的对话框都会阻止关闭后方侧栏或窗口。通过快捷键或原生菜单关闭唯一的停靠引导页时,收起右栏并保留引导页。Desktop 仅在没有弹窗且焦点没有所属的右栏页面时,或前台弹窗为只有返回操作的 Desktop Platform 页面(`platform`)时,通过快捷键服务请求关闭窗口;Web 保留浏览器窗口。
<a id="the-guide"></a>
## 引导页
@@ -69,8 +69,10 @@ export function registerSidebarShortcuts(shortcuts: Pick<Shortcuts, 'register' |
id: `page.${kind}` as ShortcutCommandId, label: () => t(`command.${kind}`), aliases: [kind, 'page'],
defaults: { 'desktop:macos': desktop, 'desktop:windows': desktop, 'desktop:linux': desktop,
'web:windows': web, ...(kind === 'close' ? { 'web:macos': web } : {}) },
regions: ['page', 'editable', 'terminal'], modals: kind === 'close' ? ['settings', 'shortcuts', 'other'] : [],
regions: ['page', 'editable', 'terminal'], modals: kind === 'close' ? ['settings', 'shortcuts', 'platform', 'other'] : [],
resolve: ({ target: element, source, modal }) => {
// The Desktop Platform page offers only a back action, so Close page closes the window as on a page.
if (kind === 'close' && modal === 'platform') return { status: 'handled', run: closeWindow }
if (kind === 'close' && modal !== null) {
return { status: 'handled', run: () => { closeTopModal(document) } }
}
@@ -608,6 +608,21 @@ describe('page close and refresh', () => {
expect(h.layout().expanded).toBe(true)
})
it.each(['macos', 'windows', 'linux'] as const)('closes the window from the Platform page above Settings on %s', (platform) => {
const h = harness()
const registry = new ShortcutRegistry('desktop', platform)
const closeWindow = vi.fn(), closeModal = vi.fn()
releases.push(registerSidebarShortcuts({ register: command => registry.register(command), runtime: 'desktop' }, h.controller, makeTranslate(en), closeWindow))
render(createElement(Modal, { open: true, title: 'Settings', shortcutModal: 'settings', closeLabel: 'Close', onClose: closeModal }))
const context = { target: document.activeElement, region: 'page' as const, modal: 'platform' }
const gesture = { code: 'KeyW', meta: platform === 'macos', control: platform !== 'macos', alt: false,
shift: false, repeat: false, composing: false, defaultPrevented: false }
registry.dispatch(gesture, context, vi.fn())
registry.invoke('page.close' as ShortcutCommandId, context)
expect(closeWindow).toHaveBeenCalledTimes(2)
expect(closeModal).not.toHaveBeenCalled()
})
it('preserves a page when cleanup fails and never falls back to closing the window', () => {
const h = harness()
h.controller.openTab('terminal')