Skip to content

Commit 99b15d2

Browse files
committed
fix(desktop): .bat 运行分支限 Windows 编译,macOS 返回明确不支持提示
1 parent 1b9feef commit 99b15d2

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

‎desktop/src-tauri/src/runner.rs‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
//! - Linux:.sh 交给 sh 后台执行;文件夹用 xdg-open
66
77
use serde_json::{json, Value};
8-
use std::path::{Path, PathBuf};
8+
use std::path::Path;
99
use std::process::Command;
1010

11+
#[cfg(windows)]
12+
use std::path::PathBuf;
13+
1114
#[cfg(windows)]
1215
use std::os::windows::process::CommandExt;
1316

@@ -129,9 +132,19 @@ pub fn run_script(script_path: &str) -> Value {
129132
}
130133
}
131134
_ => {
132-
// chcp 65001 将 cmd 切换到 UTF-8 编码,避免 bat 中的中文路径乱码
133-
let inner = format!("chcp 65001 >nul && \"{}\"", path.display());
134-
spawn_in_new_console("cmd", &["/K", &inner], dir, &format!("Running: {}", basename))
135+
#[cfg(windows)]
136+
{
137+
// chcp 65001 将 cmd 切换到 UTF-8 编码,避免 bat 中的中文路径乱码
138+
let inner = format!("chcp 65001 >nul && \"{}\"", path.display());
139+
spawn_in_new_console(
140+
"cmd",
141+
&["/K", &inner],
142+
dir,
143+
&format!("Running: {}", basename),
144+
)
145+
}
146+
#[cfg(not(windows))]
147+
Err("macOS/Linux 不支持运行 .bat/.vbs,请使用 .sh 脚本".to_string())
135148
}
136149
}
137150
} else if cfg!(target_os = "macos") {

0 commit comments

Comments
 (0)