From 1b076ccea9df57a9622c2aa7a347eb15a32f0456 Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Thu, 21 Jul 2022 19:49:51 -0700 Subject: [PATCH] open with cwd, restore akebi option stuff --- src-tauri/src/main.rs | 1 + src-tauri/src/system_helpers.rs | 19 +++++++++++++++++++ src/ui/components/ServerLaunchSection.tsx | 2 +- src/ui/components/menu/Options.tsx | 3 +++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 63c45f9..9a0b715 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -34,6 +34,7 @@ fn main() { get_theme_list, system_helpers::run_command, system_helpers::run_program, + system_helpers::run_program_relative, system_helpers::run_jar, system_helpers::open_in_browser, system_helpers::install_location, diff --git a/src-tauri/src/system_helpers.rs b/src-tauri/src/system_helpers.rs index 0280a2c..88028db 100644 --- a/src-tauri/src/system_helpers.rs +++ b/src-tauri/src/system_helpers.rs @@ -9,6 +9,25 @@ pub fn run_program(path: String) { }); } +#[tauri::command] +pub fn run_program_relative(path: String) { + // Save the current working directory + let cwd = std::env::current_dir().unwrap(); + + // Set the new working directory to the path before the executable + let mut path_buf = std::path::PathBuf::from(&path); + path_buf.pop(); + + // Open in new thread to prevent blocking. + std::thread::spawn(move || { + // Without unwrap_or, this can crash when UAC prompt is denied + open::that(&path).unwrap_or(()); + }); + + // Restore the original working directory + std::env::set_current_dir(&cwd).unwrap(); +} + #[tauri::command] pub fn run_command(program: &str, args: Vec<&str>) { cmd(program, args).run().expect("Failed to run command"); diff --git a/src/ui/components/ServerLaunchSection.tsx b/src/ui/components/ServerLaunchSection.tsx index cf23f9d..c2ee88a 100644 --- a/src/ui/components/ServerLaunchSection.tsx +++ b/src/ui/components/ServerLaunchSection.tsx @@ -157,7 +157,7 @@ export default class ServerLaunchSection extends React.Component<{}, IState> { path: exe || config.game_install_path, }) - if (gameExists) await invoke('run_program', { path: exe || config.game_install_path }) + if (gameExists) await invoke('run_program_relative', { path: exe || config.game_install_path }) else alert('Game not found! At: ' + (exe || config.game_install_path)) } diff --git a/src/ui/components/menu/Options.tsx b/src/ui/components/menu/Options.tsx index 8e7e9bf..11947f2 100644 --- a/src/ui/components/menu/Options.tsx +++ b/src/ui/components/menu/Options.tsx @@ -308,6 +308,9 @@ export default class Options extends React.Component { + )}