From 9c366b8d5c3f68d19bb87ed354b42b48c99b66c5 Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Fri, 16 Jan 2026 14:40:02 +0800 Subject: feat: improve Java command execution on Windows Enhanced the Java command execution by adding support for Windows-specific creation flags in both the installer and candidate checking functions. This change ensures better compatibility and performance when running Java commands on Windows systems. --- src-tauri/src/core/java.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src-tauri/src/core/java.rs') diff --git a/src-tauri/src/core/java.rs b/src-tauri/src/core/java.rs index ac52da6..7aa43b8 100644 --- a/src-tauri/src/core/java.rs +++ b/src-tauri/src/core/java.rs @@ -1,4 +1,6 @@ use serde::{Deserialize, Serialize}; +#[cfg(target_os = "windows")] +use std::os::windows::process::CommandExt; use std::path::PathBuf; use std::process::Command; use tauri::AppHandle; @@ -636,10 +638,12 @@ fn get_java_candidates() -> Vec { let mut candidates = Vec::new(); // Check PATH first - if let Ok(output) = Command::new(if cfg!(windows) { "where" } else { "which" }) - .arg("java") - .output() - { + let mut cmd = Command::new(if cfg!(windows) { "where" } else { "which" }); + cmd.arg("java"); + #[cfg(target_os = "windows")] + cmd.creation_flags(0x08000000); + + if let Ok(output) = cmd.output() { if output.status.success() { let paths = String::from_utf8_lossy(&output.stdout); for line in paths.lines() { @@ -788,7 +792,12 @@ fn get_java_candidates() -> Vec { /// Check a specific Java installation and get its version info fn check_java_installation(path: &PathBuf) -> Option { - let output = Command::new(path).arg("-version").output().ok()?; + let mut cmd = Command::new(path); + cmd.arg("-version"); + #[cfg(target_os = "windows")] + cmd.creation_flags(0x08000000); + + let output = cmd.output().ok()?; // Java outputs version info to stderr let version_output = String::from_utf8_lossy(&output.stderr); -- cgit v1.2.3-70-g09d2