mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-04-05 10:36:40 +08:00
fix(windows): prevent terminal windows from appearing during version check
On Windows, opening the Settings > About section would spawn three terminal windows when checking CLI tool versions (claude, codex, gemini). Root cause: - scan_cli_version() directly executed .cmd files, but child processes (node.exe) spawned by these batch scripts didn't inherit CREATE_NO_WINDOW - PATH separator used Unix-style ":" instead of Windows ";" Fix: - Wrap command execution with `cmd /C` to ensure all child processes run within the same hidden console session - Use platform-specific PATH separators via conditional compilation
This commit is contained in:
@@ -248,12 +248,18 @@ fn scan_cli_version(tool: &str) -> (Option<String>, Option<String>) {
|
||||
if tool_path.exists() {
|
||||
// 构建 PATH 环境变量,确保 node 可被找到
|
||||
let current_path = std::env::var("PATH").unwrap_or_default();
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
let new_path = format!("{};{}", path.display(), current_path);
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
let new_path = format!("{}:{}", path.display(), current_path);
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
let output = {
|
||||
Command::new(&tool_path)
|
||||
.arg("--version")
|
||||
// 使用 cmd /C 包装执行,确保子进程也在隐藏的控制台中运行
|
||||
Command::new("cmd")
|
||||
.args(["/C", &format!("\"{}\" --version", tool_path.display())])
|
||||
.env("PATH", &new_path)
|
||||
.creation_flags(CREATE_NO_WINDOW)
|
||||
.output()
|
||||
|
||||
Reference in New Issue
Block a user