[Bug] Windows「在文件资源管理器中显示」一次点击打开两个窗口(桌面 + 文件所在目录),explorer 退出码误判触发兜底二次打开
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 22
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
问题类别 · Category
文件 / 项目操作 · File / Project ops
涉及的 Agent 框架 · Agent framework
ZCode Agent(自研)
严重程度 · Severity
影响体验 · Major (功能可用但体验受损 / works but degraded)
复现频率 · Reproducibility
必现 · Always
问题描述 · Description
Windows 桌面端对文件点「选择打开方式」→「文件资源管理器」(Reveal in Explorer)后,一次点击同时打开两个资源管理器窗口:一个是「桌面」,一个是文件所在目录。每次点击必现(日志一天 5 条)。
复现步骤 · Steps to reproduce
- 会话中找到消息里的任意一个文件(例如
dist目录下的 exe) - 点文件条目上的「选择打开方式」→ 选「文件资源管理器」
- 观察桌面:出现两个资源管理器窗口
期望表现 · Expected behavior
只打开1 个窗口:文件所在目录,并选中该文件。
实际表现 · Actual behavior
打开 2 个窗口:
- 「桌面」窗口——第一步
explorer /select,畸形参数的产物 - 文件所在目录窗口(选中文件)——catch 兜底
shell.showItemInFolder的产物
根因(主进程 editors 模块,三重叠加):
- 文件分支执行
execFile(explorer.exe, ["/select,", path]),其中有两个问题:"/select,"与路径拆成了两个参数,而 explorer 要求逗号后紧跟路径(同一参数)path为正斜杠形式(C:/...),explorer 的 select 解析失败,退化为打开「桌面」
explorer.exe无论命令是否执行成功,进程退出码恒为 1,execFile将其判定为失败并进入 catch- catch 分支回退调用
shell.showItemInFolder(path),第二次打开——这一次才正确打开所在目录并选中文件
日志证据(~/.zcode/v2/logs/*.log,每次点击必产生一条):
[warn] [main] [editors] 打开 Windows 资源管理器失败,回退到 shell.openPath
{"path":"C:/.../dist/xxx.exe","args":["/select,","C:/.../dist/xxx.exe"],
"error":"Command failed: C:\Windows\explorer.exe /select, C:/.../dist/xxx.exe\n"}
已通过独立脚本验证:explorer.exe /select, C:/正斜杠/路径 单独调用即复现"打开桌面"行为;反斜杠合并参数写法则正常。
ZCode 版本 · ZCode version
3.10.2 (3.10.2.6414)
设备 / 系统 / 浏览器 · Device / OS / Browser
Windows 11 Pro (build 26200) x64,ZCode 桌面端(Electron)
截图 / 录屏 / 日志 · Screenshots / Recordings / Logs
修复建议:
- 首选:explorer 分支直接改用
shell.showItemInFolder(path),删除execFile调 explorer 命令行的分支——Electron 该 API 本身就是"打开父目录并选中",行为正确且无退出码误判问题 - 保守改法(如需保留 explorer 命令行):
- 路径转反斜杠后再传给 explorer
"/select,"与路径合并为单参数"/select," + path- 不要把退出码当失败依据(explorer 恒返回 1),仅 ENOENT 之类 spawn 错误才算失败
- 顺带:fallback 日志文案写的是 "回退到 shell.openPath",实际调用的是
shell.showItemInFolder,可一并更正
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in the main-process editors module and locate the Windows File Explorer branch that calls execFile with explorer.exe, then reproduce the issue on Windows using the supplied steps. Compare that path with Electron's shell.showItemInFolder fallback and verify that one click opens only the containing directory with the file selected, without triggering the fallback twice.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- electron
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 72/100