Skip to content

windows: 改用隐藏 VBS 启动器,避免登录后弹出终端 - #7

Merged
Wangnov merged 2 commits into
Wangnov:mainfrom
wendou-chen:fix/windows-hidden-startup
May 18, 2026
Merged

Wangnov merged 2 commits into
Wangnov:mainfrom
wendou-chen:fix/windows-hidden-startup

Conversation

@wendou-chen

Copy link
Copy Markdown

变更目的

修复 Windows 下 install-service 的使用体验问题。

当前 Windows 实现会在 Startup 文件夹里写入一个 .cmd 启动脚本。用户登录后,系统会拉起一个可见的控制台窗口来执行 watch。这会带来两个问题:

  1. 与“后台 watcher”的定位不一致,登录后会看到终端窗口
  2. 用户容易误关这个窗口,导致 watcher 停止工作

这次改动

本 PR 仅针对 Windows 做一个最小修复:

  • 把 Startup 自启动文件从 .cmd 改为隐藏窗口的 .vbs
  • install-service 时清理旧版遗留的 .cmd
  • uninstall-service 时兼容删除 .vbs 和旧版 .cmd
  • current_service_status() 在 Windows 下兼容识别旧版 .cmd,避免升级后误判为“未安装”
  • README 同步更新 Windows 行为说明

为什么不改成 schtasks / 真正的 Windows Service

本仓库当前已经明确选择了 Startup 文件夹方案。这次 PR 保持现有架构不变,只修复“登录时弹终端”这个核心体验问题,避免范围扩大。

有意不处理的范围

这次 PR 不尝试解决 Windows 登录后启动链路与 detached watch 的 pid/log/status 语义完全统一的问题。这个问题如果要处理,建议单独开一个 PR 做更完整的设计和讨论。

测试说明

  • 本地验证了 Windows 隐藏启动链路可正常拉起 watcher,且不再弹出控制台窗口
  • 新增了一个简单测试,确认生成的 Windows 启动配置包含 shell.Run ..., 0, False
  • 由于当前机器未安装 cargo 到 PATH,本地未完成完整 cargo test 回归;这部分建议在 CI 中继续覆盖

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ac03e157c9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/service.rs Outdated
Comment on lines 423 to 425
let command = format!(
"cmd.exe /c {}",
watch_command_line(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Wrap /c payload in outer quotes for cmd.exe

The new VBS launcher builds cmd.exe /c with an already-quoted executable path, but without outer quotes around the full /c payload. For common installs where the binary path contains spaces (for example under C:\Program Files), cmd's documented /c quote parsing will strip the leading quote pair when the payload contains multiple quoted segments, which breaks command resolution and prevents the Startup entry from launching watch at login. Please wrap the entire command string passed to /c (the usual ""..."" pattern) or invoke the executable without this extra cmd.exe /c layer.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你说得对。当前实现把已经带引号的可执行路径直接拼到了 cmd.exe /c 后面,没有再给整个 /c payload 做外层包装;在 Program Files 这类带空格路径下,这样确实可能被 cmd 误解析。

这里我已经改成直接让 VBS 调用已经正确加引号的可执行路径和参数,去掉了 cmd.exe /c 这一层,这样可以彻底绕开 cmd 的引号规则。

@Wangnov

Wangnov commented May 18, 2026

Copy link
Copy Markdown
Owner

感谢 PR,正好缺少在 Windows 上的实机测试反馈。

@Wangnov
Wangnov merged commit 8480607 into Wangnov:main May 18, 2026
5 checks passed
@wendou-chen

Copy link
Copy Markdown
Author

感谢 PR,正好缺少在 Windows 上的实机测试反馈。

感谢合并和follow-up的加固 commit。在 L 站看到了你的项目,很符合我目前遇到的问题和需求,感谢你的开源。

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.

2 participants