Skip to content

fix: hide PowerShell and other child process windows on Windows - #79

Open
yaojin3616 wants to merge 1 commit into
mainfrom
fix/windows-hide-child-processes
Open

fix: hide PowerShell and other child process windows on Windows#79
yaojin3616 wants to merge 1 commit into
mainfrom
fix/windows-hide-child-processes

Conversation

@yaojin3616

Copy link
Copy Markdown
Contributor

问题

在 Windows 上使用 DSH Desktop 时,Harness 执行 PowerShell 命令会反复打开用户可见的 pwsh 窗口,并将该窗口切换为前台活动窗口,打断用户正常使用。

根因

桌面层启动 Harness Node.js 进程时已经设置了 windowsHide: true,但 DSH 内部通过 child_process 启动的子进程(如 pwsh)没有设置该标志。由于父进程使用 CREATE_NO_WINDOW 没有控制台,子进程(控制台应用)会创建新的可见控制台窗口。

修复

harness-node-entry.mjs 中加入 monkey-patch,在 Windows 平台上对所有 child_process 函数(spawnspawnSyncexecexecSyncexecFileexecFileSyncfork)默认注入 windowsHide: true

调用方仍可显式设置 windowsHide: false 来覆盖此默认值。

变更文件

  • build/harness-node-entry.mjs — 在加载 DSH 前安装 windowsHide monkey-patch(仅 win32)
  • test/harness-node-entry.test.ts — 新增 19 个单元测试覆盖所有 child_process 函数的签名和覆盖行为

验证

  • 所有 17 个测试文件、100 个测试全部通过
  • TypeScript 类型检查通过

Closes #35

The harness Node.js process was already started with windowsHide: true,
but DSH spawns its own child processes (pwsh, etc.) without that flag,
causing visible console windows that steal focus on Windows.

Add a monkey-patch in harness-node-entry.mjs that defaults windowsHide
to true for all child_process functions (spawn, spawnSync, exec,
execSync, execFile, execFileSync, fork) when running on win32.

Callers can still explicitly set windowsHide: false to override.

Closes #35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: pwsh 窗口反复显示并抢占前台焦点

1 participant