Menghuan1918
f6f7629b23
fix(open-external): Windows「在应用中打开」改为 cmd start → rundll32 候选链,全失败不再静默成功(#412)
现象(#412):Windows 上右键「在应用中打开」经常没反应。核实:`urlCommand` 的 win32 分支
只有 `rundll32.exe url.dll,FileProtocolHandler <url>` 一条候选,而 rundll32.exe 在任何
Windows 上都存在、spawn 必然成功 → 路由回 `{started:true}`,UI 拿不到任何失败信息。
修法:
① `urlCommand` → `urlCommands(...): ExternalCommand[]`(有序候选链):win32 为
`cmd.exe /d /c start "" <url>` → `rundll32.exe url.dll,FileProtocolHandler <url>`
(空首参是 start 的窗口标题,缺了它带引号的 URL 会被当成标题、只弹空控制台);
darwin / linux / android / WSL 仍是单元素,语义逐字不变。
② URL 含 cmd 元字符(& % ^ ! | < > ")或控制字符时**跳过 cmd 分支**直接走 rundll32:
Node 的 argv 引用拦不住 `cmd /c` 的第二次解析(%VAR% 展开、&/| 截断、^ 吞字符、"
打乱引用),而 rundll32 以单个 argv 收到 URL、什么都不解释。
③ `launchExternal` 顺序尝试候选:只有 Node 发出 `spawn` 才算成功,同步抛错与 `error`
事件都推进到下一候选;**全部候选失败**时抛 `SidebarError('internal', …)`,消息里逐个
列出命令与底层报错(走既有 `{ok:false,error:{code,message}}` 信封)。
④ 调用方一并改形状:`EditorHost.openWith` 返回「是否被接受」(失败仍 console.error 留痕),
`FileTree` 据此把失败渲染进既有 `openInAppFailed` 错误条——复用词条,未新增词典 key。
测试:
- tests/open-external.spec.ts:候选链顺序、元字符跳过规则、空格 URL 仍是单个 argv、
失败回退顺序、全失败错误形状(含 `&` URL 只尝试 rundll32、reveal 分支的 path 措辞)。
- tests/open-external-windows.spec.ts(Windows lane,pnpm test:windows):只注入两个
「不可能存在」的可执行名(`WindowsOpenerOptions` 测试缝),走**真实 spawn** 断言两条
候选都失败时错误被回报而不是静默成功;**绝不拉起任何应用**(detached:true 会开真窗口,
所以生产命令名一个都不在测试里出现)。
- tests/file-tree-open-with.spec.tsx / tests/editor-host.spec.tsx:被拒(返回 false)与
抛错的打开都必须落进错误条,console-only 即红。
判别性(临时还原源码改动后跑新增用例,随后逐字恢复、md5 校验一致):
- 候选链退回单 rundll32(`if (false && …)`)→ 9 red(含 Windows lane 两条)
- spawn error 仍回 `{started:true}`(旧的「从不失败」契约)→ 6 red
- 去掉元字符跳过 → 11 red
- FileTree 不再上报失败 → 3 red
- EditorHost 恢复吞错 → 1 red
限制(写入设计文档):`start` 与 rundll32 在 handler 忽略 URL 时都退出 0,
「已启动但没打开」仍不可从退出码探测。
2026-10-05 22:58:01 +08:00
..
2026-10-05 02:58:04 +08:00
2026-08-18 20:29:14 +08:00
2026-10-05 02:35:18 +08:00
2026-09-03 20:29:50 +08:00
2026-08-27 21:44:04 +08:00
2026-08-15 00:28:59 +08:00
2026-10-05 02:22:03 +08:00
2026-09-09 11:15:30 +08:00
2026-10-05 02:22:03 +08:00
2026-08-21 23:49:13 +08:00
2026-08-12 18:27:28 +08:00
2026-10-05 02:22:03 +08:00
2026-10-05 02:38:21 +08:00
2026-09-21 20:35:11 +08:00
2026-09-09 23:09:48 +08:00
2026-10-05 22:39:22 +08:00
2026-09-28 18:20:08 +08:00
2026-10-05 22:39:22 +08:00
2026-09-27 22:18:19 +08:00
2026-10-05 02:22:03 +08:00
2026-10-05 02:19:58 +08:00
2026-10-05 02:19:58 +08:00
2026-09-21 20:35:11 +08:00
2026-09-07 18:52:18 +08:00
2026-10-05 21:59:14 +08:00
2026-10-05 21:59:14 +08:00
2026-09-14 00:08:38 +08:00
2026-09-03 12:04:35 +08:00
2026-09-07 23:51:10 +08:00
2026-09-28 00:27:31 +08:00
2026-09-01 23:05:26 +08:00
2026-10-05 01:29:00 +08:00
2026-09-29 17:54:53 +08:00
2026-09-03 17:32:04 +08:00
2026-09-15 10:42:46 +08:00
2026-10-05 22:36:10 +08:00
2026-10-05 22:58:01 +08:00
2026-08-11 11:16:36 +08:00
2026-09-09 15:18:06 +08:00
2026-09-21 02:14:46 +08:00
2026-10-05 01:58:18 +08:00
2026-10-05 02:13:53 +08:00
2026-09-11 15:28:49 +08:00
2026-10-01 17:21:10 +08:00
2026-09-30 01:52:59 +08:00
2026-09-30 01:56:11 +08:00
2026-10-05 02:13:53 +08:00
2026-10-05 02:13:53 +08:00
2026-10-05 02:22:03 +08:00
2026-09-28 20:37:56 +08:00
2026-09-28 20:37:56 +08:00
2026-10-05 21:46:13 +08:00
2026-10-01 17:13:10 +08:00
2026-10-01 17:15:49 +08:00
2026-09-28 20:37:56 +08:00
2026-09-28 20:37:56 +08:00
2026-09-28 20:37:56 +08:00
2026-09-28 20:37:56 +08:00
2026-10-05 22:58:01 +08:00
2026-09-02 10:55:03 +08:00
2026-09-28 20:37:56 +08:00
2026-09-28 20:37:56 +08:00
2026-09-28 20:37:56 +08:00
2026-09-29 17:04:42 +08:00
2026-08-18 18:05:01 +08:00
2026-09-27 22:18:57 +08:00
2026-08-22 22:50:13 +08:00
2026-09-28 20:37:56 +08:00
2026-10-01 18:41:27 +08:00
2026-10-05 02:37:39 +08:00
2026-10-05 02:13:53 +08:00
2026-10-05 02:13:53 +08:00
2026-08-16 23:35:57 +08:00
2026-09-28 20:37:56 +08:00
2026-09-28 20:37:56 +08:00
2026-10-01 17:26:29 +08:00
2026-10-05 01:58:18 +08:00
2026-10-05 22:25:51 +08:00
2026-10-05 02:41:34 +08:00
2026-10-05 02:41:34 +08:00
2026-09-14 00:08:38 +08:00
2026-10-05 02:50:34 +08:00
2026-10-05 02:19:58 +08:00
2026-10-05 22:19:26 +08:00
2026-10-05 22:19:26 +08:00
2026-10-05 22:19:26 +08:00
2026-09-12 17:30:58 +08:00
2026-10-01 18:41:27 +08:00
2026-10-05 01:54:17 +08:00
2026-09-11 12:02:41 +08:00
2026-09-01 16:01:34 +08:00
2026-09-09 15:18:06 +08:00
2026-09-21 20:35:11 +08:00
2026-09-22 17:09:08 +08:00
2026-09-27 22:18:35 +08:00
2026-09-27 22:18:19 +08:00
2026-08-13 10:26:57 +08:00
2026-09-02 23:15:19 +08:00
2026-10-05 02:22:03 +08:00
2026-08-24 12:05:14 +08:00
2026-08-23 22:02:47 +08:00
2026-09-09 15:18:06 +08:00
2026-09-28 21:21:45 +08:00
2026-09-03 12:04:35 +08:00
2026-09-28 18:08:21 +08:00
2026-08-18 01:22:28 +08:00
2026-09-23 22:24:56 +08:00
2026-08-18 01:22:28 +08:00
2026-09-28 11:09:30 +08:00
2026-10-01 17:25:16 +08:00
2026-10-05 02:19:58 +08:00
2026-09-13 18:36:46 +08:00
2026-09-03 19:59:00 +08:00
2026-10-05 02:22:03 +08:00
2026-10-05 22:58:01 +08:00
2026-10-05 22:58:01 +08:00
2026-09-28 00:27:31 +08:00
2026-09-28 18:08:21 +08:00
2026-09-28 18:20:08 +08:00
2026-09-21 20:35:11 +08:00
2026-10-05 21:46:26 +08:00
2026-10-01 22:05:56 +08:00
2026-10-05 02:22:03 +08:00
2026-08-16 23:35:57 +08:00
2026-09-03 19:59:00 +08:00
2026-09-23 20:46:11 +08:00
2026-09-28 20:37:56 +08:00
2026-10-05 22:25:51 +08:00
2026-09-23 22:36:05 +08:00
2026-09-27 22:18:35 +08:00
2026-09-27 22:18:35 +08:00
2026-09-06 23:46:46 +08:00
2026-10-05 01:55:36 +08:00
2026-10-05 01:55:36 +08:00
2026-09-09 23:09:48 +08:00
2026-10-05 02:22:03 +08:00
2026-10-05 03:09:38 +08:00
2026-08-13 01:39:59 +08:00
2026-09-03 12:04:35 +08:00
2026-09-28 20:11:46 +08:00
2026-10-01 18:41:27 +08:00
2026-08-16 16:24:28 +08:00
2026-09-09 11:15:30 +08:00
2026-10-05 21:59:14 +08:00
2026-09-21 20:35:11 +08:00
2026-10-05 02:13:53 +08:00
2026-09-27 22:18:57 +08:00
2026-10-05 11:32:16 +08:00
2026-09-09 15:18:06 +08:00
2026-09-07 18:52:18 +08:00
2026-10-05 00:56:36 +08:00
2026-10-01 17:18:08 +08:00
2026-10-01 17:17:57 +08:00
2026-09-22 17:09:08 +08:00
2026-10-05 01:41:40 +08:00
2026-10-05 02:13:53 +08:00
2026-10-05 00:53:09 +08:00
2026-09-22 17:09:08 +08:00
2026-09-27 22:19:05 +08:00
2026-09-27 22:18:35 +08:00
2026-09-27 22:18:35 +08:00
2026-09-27 22:18:35 +08:00
2026-10-05 21:53:08 +08:00
2026-09-09 15:18:06 +08:00
2026-10-01 16:03:14 +08:00
2026-09-09 15:18:06 +08:00
2026-09-21 20:35:11 +08:00
2026-09-27 22:18:35 +08:00
2026-09-27 22:19:05 +08:00
2026-10-05 00:54:34 +08:00
2026-09-30 02:24:36 +08:00
2026-09-27 22:19:05 +08:00
2026-09-03 12:04:24 +08:00
2026-10-05 22:25:51 +08:00
2026-10-05 01:58:18 +08:00
2026-10-03 20:54:00 +00:00
2026-10-05 01:42:41 +08:00
2026-09-27 22:18:57 +08:00
2026-10-05 21:59:14 +08:00
2026-10-01 17:18:31 +08:00
2026-09-28 18:20:08 +08:00
2026-08-20 18:28:57 +08:00
2026-08-21 01:28:17 +08:00
2026-09-27 22:18:14 +08:00
2026-09-27 22:18:14 +08:00
2026-10-05 02:22:03 +08:00