diff --git a/Cargo.lock b/Cargo.lock index 99e4778..8f9e11a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -64,6 +64,7 @@ dependencies = [ "lazy_static", "libadwaita", "md-5", + "open", "relm4", "rfd", "serde_json", @@ -1684,6 +1685,16 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +[[package]] +name = "open" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2078c0039e6a54a0c42c28faa984e115fb4c2d5bf2208f77d1961002df8576f8" +dependencies = [ + "pathdiff", + "windows-sys 0.42.0", +] + [[package]] name = "openssl-probe" version = "0.1.5" @@ -1785,6 +1796,12 @@ dependencies = [ "subtle", ] +[[package]] +name = "pathdiff" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" + [[package]] name = "pbkdf2" version = "0.11.0" diff --git a/Cargo.toml b/Cargo.toml index bd2d8b3..5c41406 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,3 +34,5 @@ anyhow = "1.0" cached = { version = "0.42", features = ["proc_macro"] } serde_json = "1" md-5 = { version = "0.10", features = ["asm"] } + +open = "3.2.0" diff --git a/src/ui/first_run/main.rs b/src/ui/first_run/main.rs index da8dd0c..cfb9ff2 100644 --- a/src/ui/first_run/main.rs +++ b/src/ui/first_run/main.rs @@ -208,12 +208,9 @@ impl SimpleComponent for FirstRunApp { #[allow(unused_must_use)] dialog.connect_response(Some("save"), |_, _| { - let result = std::process::Command::new("xdg-open") - .arg(crate::DEBUG_FILE.as_os_str()) - .output(); - - if let Err(err) = result { - tracing::error!("Failed to open debug file: {}", err); + match open::that(crate::DEBUG_FILE.as_os_str()) { + Ok(()) => {}, + Err(err) => tracing::error!("Failed to open debug file: {}", err) } }); diff --git a/src/ui/main.rs b/src/ui/main.rs index 3373f8a..73eabab 100644 --- a/src/ui/main.rs +++ b/src/ui/main.rs @@ -24,6 +24,8 @@ use crate::ui::components::*; use super::preferences::main::*; use super::about::*; +use open::*; + relm4::new_action_group!(WindowActionGroup, "win"); relm4::new_stateless_action!(LauncherFolder, WindowActionGroup, "launcher_folder"); @@ -526,48 +528,56 @@ impl SimpleComponent for App { // TODO: reduce code somehow group.add_action::(&RelmAction::new_stateless(clone!(@strong sender => move |_| { - if let Err(err) = std::process::Command::new("xdg-open").arg(LAUNCHER_FOLDER.as_path()).spawn() { - sender.input(AppMsg::Toast { - title: tr("launcher-folder-opening-error"), - description: Some(err.to_string()) - }); - - tracing::error!("Failed to open launcher folder: {err}"); + match open::that(LAUNCHER_FOLDER.as_path()) { + Ok(()) => {}, + Err(err) => { + sender.input(AppMsg::Toast { + title: tr("launcher-folder-opening-error"), + description: Some(err.to_string()) + }); + tracing::error!("Failed to open launcher folder: {err}"); + } } }))); group.add_action::(&RelmAction::new_stateless(clone!(@strong sender => move |_| { - if let Err(err) = std::process::Command::new("xdg-open").arg(&CONFIG.game.path).spawn() { - sender.input(AppMsg::Toast { - title: tr("game-folder-opening-error"), - description: Some(err.to_string()) - }); - - tracing::error!("Failed to open game folder: {err}"); + match open::that(&CONFIG.game.path) { + Ok(()) => {}, + Err(err) => { + sender.input(AppMsg::Toast { + title: tr("game-folder-opening-error"), + description: Some(err.to_string()) + }); + tracing::error!("Failed to open game folder: {err}"); + } } }))); group.add_action::(&RelmAction::new_stateless(clone!(@strong sender => move |_| { if let Some(file) = anime_launcher_sdk::consts::config_file() { - if let Err(err) = std::process::Command::new("xdg-open").arg(file).spawn() { - sender.input(AppMsg::Toast { - title: tr("config-file-opening-error"), - description: Some(err.to_string()) - }); - - tracing::error!("Failed to open config file: {err}"); + match open::that(file) { + Ok(()) => {}, + Err(err) => { + sender.input(AppMsg::Toast { + title: tr("config-file-opening-error"), + description: Some(err.to_string()) + }); + tracing::error!("Failed to open config file: {err}"); + } } } }))); group.add_action::(&RelmAction::new_stateless(clone!(@strong sender => move |_| { - if let Err(err) = std::process::Command::new("xdg-open").arg(DEBUG_FILE.as_os_str()).spawn() { - sender.input(AppMsg::Toast { - title: tr("debug-file-opening-error"), - description: Some(err.to_string()) - }); - - tracing::error!("Failed to open debug file: {err}"); + match open::that(crate::DEBUG_FILE.as_os_str()) { + Ok(()) => {}, + Err(err) => { + sender.input(AppMsg::Toast { + title: tr("debug-file-opening-error"), + description: Some(err.to_string()) + }); + tracing::error!("Failed to open debug file: {err}"); + } } }))); @@ -1277,12 +1287,9 @@ impl App { #[allow(unused_must_use)] dialog.connect_response(Some("save"), |_, _| { - let result = std::process::Command::new("xdg-open") - .arg(crate::DEBUG_FILE.as_os_str()) - .output(); - - if let Err(err) = result { - tracing::error!("Failed to open debug file: {}", err); + match open::that(crate::DEBUG_FILE.as_os_str()) { + Ok(()) => {}, + Err(err) => tracing::error!("Failed to open debug file: {}", err), } }); diff --git a/src/ui/preferences/main.rs b/src/ui/preferences/main.rs index ec641d6..3940aba 100644 --- a/src/ui/preferences/main.rs +++ b/src/ui/preferences/main.rs @@ -166,12 +166,9 @@ impl SimpleAsyncComponent for PreferencesApp { #[allow(unused_must_use)] dialog.connect_response(Some("save"), |_, _| { - let result = std::process::Command::new("xdg-open") - .arg(crate::DEBUG_FILE.as_os_str()) - .output(); - - if let Err(err) = result { - tracing::error!("Failed to open debug file: {}", err); + match open::that(crate::DEBUG_FILE.as_os_str()) { + Ok(()) => {}, + Err(err) => tracing::error!("Failed to open debug file: {}", err) } });