From 8de354f3f3a7371183a4daaf66aa55b5d2c526d6 Mon Sep 17 00:00:00 2001 From: quexeky <116044207+quexeky@users.noreply.github.com> Date: Tue, 19 Aug 2025 10:52:24 +1000 Subject: [PATCH] Add umu-run discovery (#122) Signed-off-by: quexeky --- .../src/games/downloads/download_logic.rs | 5 +-- desktop/src-tauri/src/lib.rs | 9 +--- .../src-tauri/src/process/process_handlers.rs | 44 ++++++++++++++++--- desktop/src-tauri/src/remote/commands.rs | 2 +- 4 files changed, 43 insertions(+), 17 deletions(-) diff --git a/desktop/src-tauri/src/games/downloads/download_logic.rs b/desktop/src-tauri/src/games/downloads/download_logic.rs index 12951b8b..97db2c8b 100644 --- a/desktop/src-tauri/src/games/downloads/download_logic.rs +++ b/desktop/src-tauri/src/games/downloads/download_logic.rs @@ -172,7 +172,7 @@ pub fn download_game_bucket( let raw_res = response.text().map_err(|e| { ApplicationDownloadError::Communication(RemoteAccessError::FetchError(e.into())) })?; - info!("{}", raw_res); + info!("{raw_res}"); if let Ok(err) = serde_json::from_str::(&raw_res) { return Err(ApplicationDownloadError::Communication( RemoteAccessError::InvalidResponse(err), @@ -196,8 +196,7 @@ pub fn download_game_bucket( let length = raw_length.parse::().unwrap_or(0); let Some(drop) = bucket.drops.get(i) else { warn!( - "invalid number of Content-Lengths recieved: {}, {}", - i, lengths + "invalid number of Content-Lengths recieved: {i}, {lengths}" ); return Err(ApplicationDownloadError::DownloadError); }; diff --git a/desktop/src-tauri/src/lib.rs b/desktop/src-tauri/src/lib.rs index 62093910..90caf5c7 100644 --- a/desktop/src-tauri/src/lib.rs +++ b/desktop/src-tauri/src/lib.rs @@ -65,7 +65,6 @@ use std::fs::File; use std::io::Write; use std::panic::PanicHookInfo; use std::path::Path; -use std::process::{Command, Stdio}; use std::str::FromStr; use std::sync::Arc; use std::time::SystemTime; @@ -110,13 +109,7 @@ fn create_new_compat_info() -> Option { #[cfg(target_os = "windows")] return None; - let has_umu_installed = Command::new(UMU_LAUNCHER_EXECUTABLE) - .stdout(Stdio::null()) - .spawn(); - if let Err(umu_error) = &has_umu_installed { - warn!("disabling windows support with error: {umu_error}"); - } - let has_umu_installed = has_umu_installed.is_ok(); + let has_umu_installed = UMU_LAUNCHER_EXECUTABLE.is_some(); Some(CompatInfo { umu_installed: has_umu_installed, }) diff --git a/desktop/src-tauri/src/process/process_handlers.rs b/desktop/src-tauri/src/process/process_handlers.rs index 03699fa4..dcbee5cc 100644 --- a/desktop/src-tauri/src/process/process_handlers.rs +++ b/desktop/src-tauri/src/process/process_handlers.rs @@ -1,4 +1,11 @@ -use log::debug; +use std::{ + ffi::OsStr, + path::PathBuf, + process::{Command, Stdio}, + sync::LazyLock, +}; + +use log::{debug, info}; use crate::{ AppState, @@ -24,7 +31,31 @@ impl ProcessHandler for NativeGameLauncher { } } -pub const UMU_LAUNCHER_EXECUTABLE: &str = "umu-run"; +pub static UMU_LAUNCHER_EXECUTABLE: LazyLock> = LazyLock::new(|| { + let x = get_umu_executable(); + info!("{:?}", &x); + x +}); +const UMU_BASE_LAUNCHER_EXECUTABLE: &str = "umu-run"; +const UMU_INSTALL_DIRS: [&str; 4] = ["/app/share", "/use/local/share", "/usr/share", "/opt"]; + +fn get_umu_executable() -> Option { + if check_executable_exists(UMU_BASE_LAUNCHER_EXECUTABLE) { + return Some(PathBuf::from(UMU_BASE_LAUNCHER_EXECUTABLE)); + } + + for dir in UMU_INSTALL_DIRS { + let p = PathBuf::from(dir).join(UMU_BASE_LAUNCHER_EXECUTABLE); + if check_executable_exists(&p) { + return Some(p); + } + } + None +} +fn check_executable_exists>(exec: P) -> bool { + let has_umu_installed = Command::new(exec).stdout(Stdio::null()).output(); + has_umu_installed.is_ok() +} pub struct UMULauncher; impl ProcessHandler for UMULauncher { fn create_launch_process( @@ -47,8 +78,8 @@ impl ProcessHandler for UMULauncher { None => game_version.game_id.clone(), }; format!( - "GAMEID={game_id} {umu} \"{launch}\" {args}", - umu = UMU_LAUNCHER_EXECUTABLE, + "GAMEID={game_id} {umu:?} \"{launch}\" {args}", + umu = UMU_LAUNCHER_EXECUTABLE.as_ref().unwrap(), launch = launch_command, args = args.join(" ") ) @@ -80,7 +111,10 @@ impl ProcessHandler for AsahiMuvmLauncher { game_version, current_dir, ); - let mut args_cmd = umu_string.split("umu-run").collect::>().into_iter(); + let mut args_cmd = umu_string + .split("umu-run") + .collect::>() + .into_iter(); let args = args_cmd.next().unwrap().trim(); let cmd = format!("umu-run{}", args_cmd.next().unwrap()); diff --git a/desktop/src-tauri/src/remote/commands.rs b/desktop/src-tauri/src/remote/commands.rs index 14685059..3f204939 100644 --- a/desktop/src-tauri/src/remote/commands.rs +++ b/desktop/src-tauri/src/remote/commands.rs @@ -130,7 +130,7 @@ pub fn auth_initiate_code(app: AppHandle) -> Result { let code = auth_initiate_logic("code".to_string())?; let header_code = code.clone(); - println!("using code: {} to sign in", code); + println!("using code: {code} to sign in"); tauri::async_runtime::spawn(async move { let load = async || -> Result<(), RemoteAccessError> {