DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(clipboard): 修复 Linux 贴图回包被按 source 过滤丢弃
hairyfdb4eb65b85ff
diff --git a/docs/testing/desktop/18-notification-download.md b/docs/testing/desktop/18-notification-download.mdindex 12f6a7ab..25b77aff 100644--- a/docs/testing/desktop/18-notification-download.md+++ b/docs/testing/desktop/18-notification-download.md@@ -24,7 +24,7 @@| 「在文件夹中显示」→ `reveal_in_folder` | `src/layout/index.tsx:116` || 新下载完成时关闭上一条同源 toast | `src/layout/index.tsx:97-98`、`:122-124` || 剪贴板图片桥 `dsh://clipboard-image:read` → `read_clipboard_image` | `src/layout/components/iframe.tsx:98-101`、`:156-169` |-| 回包 `source: 'dsh://clipboard-image:reply'` | `src/layout/components/iframe.tsx:160-162` |+| 回包 `type: 'dsh://clipboard-image:reply'`(注入脚本按 `type` 匹配) | `src/layout/components/iframe.tsx:160-162`;`src-tauri/src/desktop/paste.rs` || 打开外部链接(`window.open` / `target=_blank`) | `src-tauri/src/desktop/window.rs:22-35` |---@@ -127,7 +127,7 @@[前置条件] 系统剪贴板中已放入一张图片[测试数据] 桥消息 `{ type: 'dsh://clipboard-image:read', id }`[测试步骤] 1. 由 iframe 侧发出读取请求。2. 等待回包。3. 读取回包内容。-[预期结果] 1. 请求发出成功。2. 回包到达。3. 回包 `source` 为 `dsh://clipboard-image:reply`,`id` 与请求一致,`data_url` 以 `data:image/png` 开头。+[预期结果] 1. 请求发出成功。2. 回包到达。3. 回包 `type` 为 `dsh://clipboard-image:reply`,`id` 与请求一致,`data_url` 以 `data:image/png` 开头。[清理] 清空剪贴板;`DELETE /session/<id>`---diff --git a/src-tauri/src/desktop/paste.rs b/src-tauri/src/desktop/paste.rsindex 30c5c9ed..5d182a87 100644--- a/src-tauri/src/desktop/paste.rs+++ b/src-tauri/src/desktop/paste.rs@@ -17,10 +17,12 @@ pub(crate) const PASTE_SHIM_JS: &str = r#"(function () {if (window.__dsh_clipboard_image_bridge__) return;window.__dsh_clipboard_image_bridge__ = true;- // 请求方向:iframe → 宿主;响应方向:宿主 → iframe+ // 请求方向:iframe → 宿主;响应方向:宿主 → iframe。+ // 两个方向都按 `type` 识别:宿主 → iframe 的桥统一由 useIframePost 补+ // `source: 'dsh-desktop'`,这里只比对 `type`,不再比对 `source`。var REQ_SRC = 'dsh-clipboard-image-bridge';- var RES_SRC = 'dsh-desktop-clipboard';var REQ_TYPE = 'dsh://clipboard-image:read';+ var RES_TYPE = 'dsh://clipboard-image:reply';var reqSeq = 0;var pending = {}; // id -> { resolve, target }@@ -39,10 +41,11 @@ pub(crate) const PASTE_SHIM_JS: &str = r#"(function () {});}- // 宿主回包+ // 宿主回包:只接受直接父窗口发来、`type` 匹配的回包window.addEventListener('message', function (event) {+ if (event.source !== window.parent) return;var data = event.data;- if (!data || typeof data !== 'object' || data.source !== RES_SRC) return;+ if (!data || typeof data !== 'object' || data.type !== RES_TYPE) return;var item = pending[data.id];if (!item) return;delete pending[data.id];diff --git a/src/layout/components/iframe.tsx b/src/layout/components/iframe.tsxindex 1b86a307..bcba4069 100644--- a/src/layout/components/iframe.tsx+++ b/src/layout/components/iframe.tsx@@ -158,7 +158,7 @@ export function Iframe({ iframeRef }: IframeProps) {returnconst reqId = data.idfunction reply(dataUrl: string | null) {- post({ source: 'dsh://clipboard-image:reply', id: reqId, data_url: dataUrl })+ post({ type: 'dsh://clipboard-image:reply', id: reqId, data_url: dataUrl })}void invoke<{ data_url?: string } | null>('read_clipboard_image').then(result => reply(result?.data_url ?? null))diff --git a/test/clipboard-image-bridge.test.ts b/test/clipboard-image-bridge.test.tsnew file mode 100644index 00000000..6b5681d3--- /dev/null+++ b/test/clipboard-image-bridge.test.ts@@ -0,0 +1,41 @@+// @vitest-environment node+import { readFileSync } from 'node:fs'+import { describe, expect, it } from 'vitest'++/**+ * 剪贴板图片回退桥的协议契约(issue #610)。+ *+ * Linux/WebKitGTK 下 iframe 的 paste 事件拿不到图片,由注入脚本+ * (`src-tauri/src/desktop/paste.rs` 的 `PASTE_SHIM_JS`)向宿主请求原生读取,+ * 宿主(`src/layout/components/iframe.tsx`)回包后重新合成一次 paste。+ *+ * 宿主 → iframe 的桥统一由 `useIframePost` 补 `source: 'dsh-desktop'`,只按 `type`+ * 识别。回包若改用自定义 `source`,注入脚本仍按 `source` 过滤就会把回包丢掉,+ * 贴图静默失败(0.15.5 的回归)。这些用例把两端的字面量与匹配方式锁在一起。+ */+function readSource(relativePath: string): string {+ return readFileSync(new URL(relativePath, import.meta.url), 'utf8')+}++const REPLY_TYPE = 'dsh://clipboard-image:reply'++describe('clipboard image bridge protocol', () => {+ const shim = readSource('../src-tauri/src/desktop/paste.rs')+ const iframe = readSource('../src/layout/components/iframe.tsx')++ it('replies with the type the injected shim waits for', () => {+ expect(shim).toContain(`var RES_TYPE = '${REPLY_TYPE}'`)+ expect(iframe).toContain(`type: '${REPLY_TYPE}'`)+ })++ it('identifies the host reply by type instead of source', () => {+ expect(shim).toContain('data.type !== RES_TYPE')+ expect(shim).not.toContain('RES_SRC')+ expect(shim).not.toContain('data.source !==')+ expect(iframe).not.toContain(`source: '${REPLY_TYPE}'`)+ })++ it('only accepts replies from the direct parent window', () => {+ expect(shim).toContain('event.source !== window.parent')+ })+})