DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(desktop): 移除壳层「编辑」菜单,不再抢走 iframe 聚焦
hairyf25c787ab08b0
diff --git a/packages/dsh-tauri/src/client/register/shortcuts.test.ts b/packages/dsh-tauri/src/client/register/shortcuts.test.tsindex 6d488e3c..d7986873 100644--- a/packages/dsh-tauri/src/client/register/shortcuts.test.ts+++ b/packages/dsh-tauri/src/client/register/shortcuts.test.ts@@ -1,17 +1,16 @@/**- * register/shortcuts.test.ts — 快捷键桥的三条契约。+ * register/shortcuts.test.ts — 快捷键桥的两条契约。** 1. iframe → 宿主:核心 `ctx.shortcuts.catalog` 的目录投影后经 `dsh://shortcuts` 回报* (壳层菜单右侧的按键提示都读它),配置变更后重发;- * 2. 宿主 → iframe:`dsh://edit` 在文档上执行对应编辑命令,非法 action 不进文档;- * 3. 宿主 → iframe:`dsh://shortcuts:open` 按官方 `shortcuts.open` 的**生效**绑定补一次+ * 2. 宿主 → iframe:`dsh://shortcuts:open` 按官方 `shortcuts.open` 的**生效**绑定补一次* 合成 keydown,弹出官方弹层与官方蒙版(壳层不自建对话框)。** 核心没有 `shortcuts` 服务(老核心)时全部保持沉默,不得抛错。*/import type { ClientContext, ParentMessage } from '../types'import { afterEach, describe, expect, it, vi } from 'vitest'-import { CMD_EDIT, CMD_SHORTCUTS_OPEN, EVENT_SHORTCUTS, shortcutsFeature } from './shortcuts'+import { CMD_SHORTCUTS_OPEN, EVENT_SHORTCUTS, shortcutsFeature } from './shortcuts'const dispatchers = new Set<(event: KeyboardEvent) => void>()@@ -117,20 +116,6 @@ describe('shortcutsFeature', () => {expect(env.listeners()).toBe(0)})- it('runs the edit command and ignores unknown actions', () => {- const env = stubEnv()- const exec = vi.fn(() => true)- vi.stubGlobal('document', { execCommand: exec })-- shortcutsFeature.call(fakeCtx(catalogService([])))- env.dispatch({ type: CMD_EDIT, action: 'copy' })- env.dispatch({ type: CMD_EDIT, action: 'rm -rf' })- env.dispatch({ type: 'dsh://sidebar:toggle' })-- expect(exec).toHaveBeenCalledTimes(1)- expect(exec).toHaveBeenCalledWith('copy')- })-/** 官方弹层:用目录里的生效绑定合成 keydown(官方适配器只看 code + 修饰键)。 */it('opens the official reference with the effective binding', () => {const env = stubEnv()diff --git a/packages/dsh-tauri/src/client/register/shortcuts.ts b/packages/dsh-tauri/src/client/register/shortcuts.tsindex e8ee3e58..a932853c 100644--- a/packages/dsh-tauri/src/client/register/shortcuts.ts+++ b/packages/dsh-tauri/src/client/register/shortcuts.ts@@ -5,8 +5,7 @@* `dsh://shortcuts` 送达壳层;壳层的「文件」「帮助」菜单右侧按键提示与「显示键盘快捷键」* 清单都读这一份(配置变更后重发,用户改键即时生效)。*- * 宿主 → iframe:`dsh://edit` 由壳层的「编辑」菜单发出,在文档上执行对应编辑命令;- * 剪贴板仍走系统快捷键(WebView 的原生粘贴不对脚本开放)。+ * 宿主 → iframe:`dsh://shortcuts:open` 打开官方「键盘快捷键」弹层。** 协议字面量与宿主侧 `src/layout/components/webview.tsx` / `navbar.tsx` 逐字一致。*/@@ -18,17 +17,9 @@ import { defineRegister } from './index'/** iframe → 宿主:快捷键目录回报。 */export const EVENT_SHORTCUTS = 'dsh://shortcuts'-/** 宿主 → iframe:编辑菜单命令。 */-export const CMD_EDIT = 'dsh://edit'-/** 宿主 → iframe:打开官方「键盘快捷键」弹层(官方 `shortcuts.open` 命令,含官方蒙版)。 */export const CMD_SHORTCUTS_OPEN = 'dsh://shortcuts:open'-/** 菜单可执行的编辑动作(`document.execCommand` 的命令名)。 */-export const EDIT_ACTIONS = ['undo', 'redo', 'cut', 'copy', 'paste', 'selectAll'] as const--export type EditAction = typeof EDIT_ACTIONS[number]-/** 上报给壳层的一行目录(官方 `ShortcutCatalogEntry` 的投影)。 */export interface ShortcutRowReport {id: string@@ -63,12 +54,9 @@ export const shortcutsFeature = defineRegister((controller, ctx) => {controller.add(catalog.subscribe(report))controller.add(listenParent<ParentMessage>((data) => {- if (data.type === CMD_SHORTCUTS_OPEN) {+ if (data.type === CMD_SHORTCUTS_OPEN)openReference(snapshot.call(catalog))- return- }- runEdit(data.action)- }, [CMD_EDIT, CMD_SHORTCUTS_OPEN]))+ }, [CMD_SHORTCUTS_OPEN]))})/** 目录投影:只保留有 id 与文案的行,`keys` 逐项取字符串。 */@@ -95,20 +83,6 @@ function project(rows: unknown): ShortcutRowReport[] {return out}-/** 编辑命令:文档级 `document.execCommand`;失败只告警(原生快捷键仍是主路径)。 */-function runEdit(action: unknown): void {- if (typeof action !== 'string' || !EDIT_ACTIONS.includes(action as EditAction))- return- if (typeof document === 'undefined')- return- try {- document.execCommand(action)- }- catch (error) {- console.warn('[dsh-tauri] running the edit command failed:', error)- }-}-/*** 打开官方「键盘快捷键」弹层:官方命令没有公开的调用口,按其**生效**绑定补一次合成* keydown(官方键盘适配器只读 `event.code` 与修饰键,不校验 `isTrusted`),diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.jsonindex 0e22914f..37429e44 100644--- a/src/i18n/locales/en-US.json+++ b/src/i18n/locales/en-US.json@@ -70,13 +70,6 @@"menu.about": "About Desktop","menu.run_logs": "Run Logs","menu.file": "File",- "menu.edit": "Edit",- "menu.undo": "Undo",- "menu.redo": "Redo",- "menu.cut": "Cut",- "menu.copy": "Copy",- "menu.paste": "Paste",- "menu.select_all": "Select All","menu.keyboard_shortcuts": "Show Keyboard Shortcuts","menu.run": "Run","menu.new_window": "New Window",diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.jsonindex c968633f..bf124182 100644--- a/src/i18n/locales/zh-CN.json+++ b/src/i18n/locales/zh-CN.json@@ -70,13 +70,6 @@"menu.about": "关于 Desktop","menu.run_logs": "运行日志","menu.file": "文件",- "menu.edit": "编辑",- "menu.undo": "撤销",- "menu.redo": "重做",- "menu.cut": "剪切",- "menu.copy": "复制",- "menu.paste": "粘贴",- "menu.select_all": "全选","menu.keyboard_shortcuts": "显示键盘快捷键","menu.run": "运行","menu.new_window": "新建窗口",diff --git a/src/layout/components/navbar.tsx b/src/layout/components/navbar.tsxindex 56cc2fb6..d1298aa2 100644--- a/src/layout/components/navbar.tsx+++ b/src/layout/components/navbar.tsx@@ -84,18 +84,6 @@ const DOCS_URL = 'https://dshtauri.mintlify.site'/** 「文件」菜单的动作 id(宿主侧统一分发,避免菜单项内散落逻辑)。 */type FileAction = 'new-window' | 'new-chat' | 'open-folder' | 'close' | 'quit'-/**- * 「编辑」菜单项:`dsh://edit` 的 action 与平台加速键(macOS 用 ⌘,与官方桌面端一致)。- */-const EDIT_ITEMS = [- { id: 'undo', labelKey: 'menu.undo', key: 'Z', shift: false },- { id: 'redo', labelKey: 'menu.redo', key: 'Z', shift: true },- { id: 'cut', labelKey: 'menu.cut', key: 'X', shift: false },- { id: 'copy', labelKey: 'menu.copy', key: 'C', shift: false },- { id: 'paste', labelKey: 'menu.paste', key: 'V', shift: false },- { id: 'selectAll', labelKey: 'menu.select_all', key: 'A', shift: false },-] as const-/** 「帮助」菜单的动作 id。 */type HelpAction = 'keyboard-shortcuts' | 'copy-run-logs' | 'check-update' | 'about' | 'documentation'@@ -222,13 +210,6 @@ function ShortcutLabel({ label, hint }: { label: string, hint?: string }) {)}-/** 编辑菜单的加速键文本:macOS 用 ⌘,其余平台用 Ctrl(与官方桌面端同一组)。 */-function editAccelerator(key: string, shift: boolean): string {- if (IS_MACOS)- return `⌘${shift ? '⇧' : ''}${key}`- return `Ctrl+${shift ? 'Shift+' : ''}${key}`-}-export interface NavbarProps { /** iframe 回报的 dsh 侧边栏折叠状态(导航桥逻辑在 `iframe.tsx`) */sidebarCollapsed?: boolean/** 切换 iframe 内 dsh 侧边栏(向 iframe 发 `dsh://sidebar:toggle`);传入时启用左侧导航控制 */@@ -241,13 +222,11 @@ export interface NavbarProps { /** iframe 回报的 dsh 侧边栏折叠状态(onOpenSyncToRemote?: () => void/** 打开文件夹:向 iframe 发 `dsh://workspace:add`(dsh 官方「添加工作区」);传入时该项可用 */onOpenFolder?: () => void- /** 编辑菜单动作:向 iframe 发 `dsh://edit`(dsh-tauri 的 `client/register/shortcuts.ts` 执行) */- onEditAction?: (action: string) => void/** 显示键盘快捷键:向 iframe 发 `dsh://shortcuts:open`,弹官方 `shortcuts.open` 弹层(官方蒙版) */onOpenShortcuts?: () => void}-export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, onOpenFolder, onEditAction, onOpenShortcuts, onOpenMachineManager, onOpenSyncToRemote }: NavbarProps) {+export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, onOpenFolder, onOpenShortcuts, onOpenMachineManager, onOpenSyncToRemote }: NavbarProps) {const { t } = useTranslation()const isFullscreen = useMacOSFullscreen()const isMaximized = useMaximized()@@ -542,38 +521,6 @@ export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, o</Dropdown.Menu></Dropdown.Popover></Dropdown>- {/* 「编辑」:与官方桌面端同一组编辑命令(撤销/重做/剪切/复制/粘贴/全选)。- 动作经 `dsh://edit` 交给 iframe 内的 dsh-tauri 插件在文档上执行,- 未安装插件(没有接收方)时整组禁用;加速键是系统/WebView 真实绑定,- 只作为提示(粘贴仍走原生快捷键,脚本无权读剪贴板)。 */}- <Dropdown>- <Button- className="rounded-lg h-6 text-[12.5px] px-1.5"- size="sm"- variant="ghost"- aria-label={t('menu.edit')}- data-testid="dsh-navbar-menu-edit"- >- {t('menu.edit')}- </Button>- <Dropdown.Popover className="rounded-md min-w-55" data-testid="dsh-navbar-menu-popover">- <Dropdown.Menu>- {EDIT_ITEMS.map(item => (- <Dropdown.Item- key={item.id}- className="rounded-md"- id={item.id}- data-testid={`dsh-navbar-item-edit-${item.id}`}- isDisabled={onEditAction == null}- textValue={t(item.labelKey)}- onAction={() => onEditAction?.(item.id)}- >- <ShortcutLabel label={t(item.labelKey)} hint={editAccelerator(item.key, item.shift)} />- </Dropdown.Item>- ))}- </Dropdown.Menu>- </Dropdown.Popover>- </Dropdown><Dropdown isOpen={runMenuOpen} onOpenChange={setRunMenuOpen}>{' '}<Buttondiff --git a/src/layout/components/webview.tsx b/src/layout/components/webview.tsxindex dd5d06e3..17294449 100644--- a/src/layout/components/webview.tsx+++ b/src/layout/components/webview.tsx@@ -91,7 +91,6 @@ export function Webview() {onToggleSidebar: () => post({ type: 'dsh://sidebar:toggle' }),onNewChat: () => post({ type: 'dsh://session:new' }),onOpenFolder: () => post({ type: 'dsh://workspace:add' }),- onEditAction: (action: string) => post({ type: 'dsh://edit', action }),onOpenShortcuts: () => post({ type: 'dsh://shortcuts:open' }),}: {}