bug修复调整

This commit is contained in:
zhongluofeng
2026-08-31 18:05:27 +08:00
parent 28e0c4664a
commit 6b9f71da08
35 changed files with 1004 additions and 296 deletions
+24
View File
@@ -505,11 +505,35 @@ pub fn quickpanel_run_custom_command(command: String, args: Vec<String>) -> Resu
/// 运行系统命令(不设置 CREATE_NO_WINDOW,使 cmd/powershell/regedit 等显示自身窗口)
/// 适用于内置系统工具:regedit、shutdown、cmd、powershell、taskmgr 等。
/// - 控制台类交互程序(cmd/powershell/pwsh)额外设置 CREATE_NEW_CONSOLE
/// 否则从 GUI 宿主启动时无可见控制台窗口(表现为"点击没反应")。
/// - .msc 控制台文件(如 devmgmt.msc)不可被 CreateProcess 直接执行,
/// 改由 mmc 打开(路径解析到 System32,不受当前工作目录影响)。
#[tauri::command]
#[specta::specta]
pub fn quickpanel_run_system_command(command: String, args: Vec<String>) -> Result<(), String> {
let lower = command.to_lowercase();
if lower.ends_with(".msc") {
// 控制台文件:通过 mmc 打开(GUI 程序,无需新控制台)
let system_root = std::env::var("SystemRoot").unwrap_or_else(|_| "C:\\Windows".into());
let path = format!("{}\\System32\\{}", system_root, command);
let mut c = std::process::Command::new("mmc");
c.arg(&path);
return c
.spawn()
.map(|_| ())
.map_err(|e| format!("运行系统命令失败: {}", e));
}
let mut cmd = std::process::Command::new(&command);
cmd.args(&args);
#[cfg(windows)]
{
use std::os::windows::process::CommandExt;
let c = lower;
if c == "cmd" || c == "powershell" || c == "pwsh" {
cmd.creation_flags(crate::process_manager::CREATE_NEW_CONSOLE);
}
}
cmd.spawn().map_err(|e| format!("运行系统命令失败: {}", e))?;
Ok(())
}