Skip to content

Commit 5fb0025

Browse files
quexekyDecDuck
authored andcommitted
Add umu-run discovery (#122)
Signed-off-by: quexeky <[email protected]>
1 parent 5eef2bf commit 5fb0025

File tree

4 files changed

+43
-17
lines changed

4 files changed

+43
-17
lines changed

src-tauri/src/games/downloads/download_logic.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ pub fn download_game_bucket(
172172
let raw_res = response.text().map_err(|e| {
173173
ApplicationDownloadError::Communication(RemoteAccessError::FetchError(e.into()))
174174
})?;
175-
info!("{}", raw_res);
175+
info!("{raw_res}");
176176
if let Ok(err) = serde_json::from_str::<DropServerError>(&raw_res) {
177177
return Err(ApplicationDownloadError::Communication(
178178
RemoteAccessError::InvalidResponse(err),
@@ -196,8 +196,7 @@ pub fn download_game_bucket(
196196
let length = raw_length.parse::<usize>().unwrap_or(0);
197197
let Some(drop) = bucket.drops.get(i) else {
198198
warn!(
199-
"invalid number of Content-Lengths recieved: {}, {}",
200-
i, lengths
199+
"invalid number of Content-Lengths recieved: {i}, {lengths}"
201200
);
202201
return Err(ApplicationDownloadError::DownloadError);
203202
};

src-tauri/src/lib.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ use std::fs::File;
6565
use std::io::Write;
6666
use std::panic::PanicHookInfo;
6767
use std::path::Path;
68-
use std::process::{Command, Stdio};
6968
use std::str::FromStr;
7069
use std::sync::Arc;
7170
use std::time::SystemTime;
@@ -110,13 +109,7 @@ fn create_new_compat_info() -> Option<CompatInfo> {
110109
#[cfg(target_os = "windows")]
111110
return None;
112111

113-
let has_umu_installed = Command::new(UMU_LAUNCHER_EXECUTABLE)
114-
.stdout(Stdio::null())
115-
.spawn();
116-
if let Err(umu_error) = &has_umu_installed {
117-
warn!("disabling windows support with error: {umu_error}");
118-
}
119-
let has_umu_installed = has_umu_installed.is_ok();
112+
let has_umu_installed = UMU_LAUNCHER_EXECUTABLE.is_some();
120113
Some(CompatInfo {
121114
umu_installed: has_umu_installed,
122115
})

src-tauri/src/process/process_handlers.rs

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
use log::debug;
1+
use std::{
2+
ffi::OsStr,
3+
path::PathBuf,
4+
process::{Command, Stdio},
5+
sync::LazyLock,
6+
};
7+
8+
use log::{debug, info};
29

310
use crate::{
411
AppState,
@@ -24,7 +31,31 @@ impl ProcessHandler for NativeGameLauncher {
2431
}
2532
}
2633

27-
pub const UMU_LAUNCHER_EXECUTABLE: &str = "umu-run";
34+
pub static UMU_LAUNCHER_EXECUTABLE: LazyLock<Option<PathBuf>> = LazyLock::new(|| {
35+
let x = get_umu_executable();
36+
info!("{:?}", &x);
37+
x
38+
});
39+
const UMU_BASE_LAUNCHER_EXECUTABLE: &str = "umu-run";
40+
const UMU_INSTALL_DIRS: [&str; 4] = ["/app/share", "/use/local/share", "/usr/share", "/opt"];
41+
42+
fn get_umu_executable() -> Option<PathBuf> {
43+
if check_executable_exists(UMU_BASE_LAUNCHER_EXECUTABLE) {
44+
return Some(PathBuf::from(UMU_BASE_LAUNCHER_EXECUTABLE));
45+
}
46+
47+
for dir in UMU_INSTALL_DIRS {
48+
let p = PathBuf::from(dir).join(UMU_BASE_LAUNCHER_EXECUTABLE);
49+
if check_executable_exists(&p) {
50+
return Some(p);
51+
}
52+
}
53+
None
54+
}
55+
fn check_executable_exists<P: AsRef<OsStr>>(exec: P) -> bool {
56+
let has_umu_installed = Command::new(exec).stdout(Stdio::null()).output();
57+
has_umu_installed.is_ok()
58+
}
2859
pub struct UMULauncher;
2960
impl ProcessHandler for UMULauncher {
3061
fn create_launch_process(
@@ -47,8 +78,8 @@ impl ProcessHandler for UMULauncher {
4778
None => game_version.game_id.clone(),
4879
};
4980
format!(
50-
"GAMEID={game_id} {umu} \"{launch}\" {args}",
51-
umu = UMU_LAUNCHER_EXECUTABLE,
81+
"GAMEID={game_id} {umu:?} \"{launch}\" {args}",
82+
umu = &*UMU_LAUNCHER_EXECUTABLE,
5283
launch = launch_command,
5384
args = args.join(" ")
5485
)
@@ -80,7 +111,10 @@ impl ProcessHandler for AsahiMuvmLauncher {
80111
game_version,
81112
current_dir,
82113
);
83-
let mut args_cmd = umu_string.split("umu-run").collect::<Vec<&str>>().into_iter();
114+
let mut args_cmd = umu_string
115+
.split("umu-run")
116+
.collect::<Vec<&str>>()
117+
.into_iter();
84118
let args = args_cmd.next().unwrap().trim();
85119
let cmd = format!("umu-run{}", args_cmd.next().unwrap());
86120

src-tauri/src/remote/commands.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub fn auth_initiate_code(app: AppHandle) -> Result<String, RemoteAccessError> {
130130
let code = auth_initiate_logic("code".to_string())?;
131131
let header_code = code.clone();
132132

133-
println!("using code: {} to sign in", code);
133+
println!("using code: {code} to sign in");
134134

135135
tauri::async_runtime::spawn(async move {
136136
let load = async || -> Result<(), RemoteAccessError> {

0 commit comments

Comments
 (0)