|
1 | 1 | use serde::{Deserialize, Serialize}; |
2 | 2 | use std::process::Command; |
3 | 3 |
|
| 4 | +#[cfg(windows)] |
| 5 | +use tokio::process::Command as TokioCommand; |
| 6 | + |
4 | 7 | mod uv_installer; |
5 | 8 |
|
6 | 9 | #[derive(Debug, Serialize, Deserialize)] |
@@ -236,16 +239,39 @@ async fn is_command_available(cmd: &str) -> bool { |
236 | 239 | .unwrap_or(false) |
237 | 240 | } |
238 | 241 |
|
239 | | -// Fixed: Improved command existence check |
| 242 | +// Fixed: Improved command existence check with hidden window on Windows |
240 | 243 | #[tauri::command] |
241 | 244 | pub async fn check_command_exists(command: String) -> Result<bool, String> { |
242 | 245 | let exists = match std::env::consts::OS { |
243 | | - "windows" => tokio::process::Command::new("cmd") |
244 | | - .args(&["/C", "where", &command]) |
245 | | - .output() |
246 | | - .await |
247 | | - .map(|output| output.status.success()) |
248 | | - .unwrap_or(false), |
| 246 | + "windows" => { |
| 247 | + use std::process::Stdio; |
| 248 | + #[cfg(windows)] |
| 249 | + { |
| 250 | + use std::os::windows::process::CommandExt; |
| 251 | + tokio::process::Command::new("cmd") |
| 252 | + .args(&["/C", "where", &command]) |
| 253 | + .stdout(Stdio::null()) |
| 254 | + .stderr(Stdio::null()) |
| 255 | + .stdin(Stdio::null()) |
| 256 | + .creation_flags(0x08000000) // CREATE_NO_WINDOW |
| 257 | + .output() |
| 258 | + .await |
| 259 | + .map(|output| output.status.success()) |
| 260 | + .unwrap_or(false) |
| 261 | + } |
| 262 | + #[cfg(not(windows))] |
| 263 | + { |
| 264 | + tokio::process::Command::new("cmd") |
| 265 | + .args(&["/C", "where", &command]) |
| 266 | + .stdout(Stdio::null()) |
| 267 | + .stderr(Stdio::null()) |
| 268 | + .stdin(Stdio::null()) |
| 269 | + .output() |
| 270 | + .await |
| 271 | + .map(|output| output.status.success()) |
| 272 | + .unwrap_or(false) |
| 273 | + } |
| 274 | + }, |
249 | 275 | _ => tokio::process::Command::new("which") |
250 | 276 | .arg(&command) |
251 | 277 | .output() |
|
0 commit comments