This commit is contained in:
Renaud Lepage 2023-03-05 20:29:54 +00:00
parent e475fa9d89
commit e1e53d4b49
5 changed files with 66 additions and 46 deletions

17
Cargo.lock generated
View file

@ -64,6 +64,7 @@ dependencies = [
"lazy_static", "lazy_static",
"libadwaita", "libadwaita",
"md-5", "md-5",
"open",
"relm4", "relm4",
"rfd", "rfd",
"serde_json", "serde_json",
@ -1684,6 +1685,16 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" 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]] [[package]]
name = "openssl-probe" name = "openssl-probe"
version = "0.1.5" version = "0.1.5"
@ -1785,6 +1796,12 @@ dependencies = [
"subtle", "subtle",
] ]
[[package]]
name = "pathdiff"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd"
[[package]] [[package]]
name = "pbkdf2" name = "pbkdf2"
version = "0.11.0" version = "0.11.0"

View file

@ -34,3 +34,5 @@ anyhow = "1.0"
cached = { version = "0.42", features = ["proc_macro"] } cached = { version = "0.42", features = ["proc_macro"] }
serde_json = "1" serde_json = "1"
md-5 = { version = "0.10", features = ["asm"] } md-5 = { version = "0.10", features = ["asm"] }
open = "3.2.0"

View file

@ -208,12 +208,9 @@ impl SimpleComponent for FirstRunApp {
#[allow(unused_must_use)] #[allow(unused_must_use)]
dialog.connect_response(Some("save"), |_, _| { dialog.connect_response(Some("save"), |_, _| {
let result = std::process::Command::new("xdg-open") match open::that(crate::DEBUG_FILE.as_os_str()) {
.arg(crate::DEBUG_FILE.as_os_str()) Ok(()) => {},
.output(); Err(err) => tracing::error!("Failed to open debug file: {}", err)
if let Err(err) = result {
tracing::error!("Failed to open debug file: {}", err);
} }
}); });

View file

@ -22,6 +22,8 @@ use crate::ui::components::*;
use super::preferences::main::*; use super::preferences::main::*;
use super::about::*; use super::about::*;
use open::*;
relm4::new_action_group!(WindowActionGroup, "win"); relm4::new_action_group!(WindowActionGroup, "win");
relm4::new_stateless_action!(LauncherFolder, WindowActionGroup, "launcher_folder"); relm4::new_stateless_action!(LauncherFolder, WindowActionGroup, "launcher_folder");
@ -517,48 +519,56 @@ impl SimpleComponent for App {
// TODO: reduce code somehow // TODO: reduce code somehow
group.add_action::<LauncherFolder>(&RelmAction::new_stateless(clone!(@strong sender => move |_| { group.add_action::<LauncherFolder>(&RelmAction::new_stateless(clone!(@strong sender => move |_| {
if let Err(err) = std::process::Command::new("xdg-open").arg(LAUNCHER_FOLDER.as_path()).spawn() { match open::that(LAUNCHER_FOLDER.as_path()) {
sender.input(AppMsg::Toast { Ok(()) => {},
title: tr("launcher-folder-opening-error"), Err(err) => {
description: Some(err.to_string()) sender.input(AppMsg::Toast {
}); title: tr("launcher-folder-opening-error"),
description: Some(err.to_string())
tracing::error!("Failed to open launcher folder: {err}"); });
tracing::error!("Failed to open launcher folder: {err}");
}
} }
}))); })));
group.add_action::<GameFolder>(&RelmAction::new_stateless(clone!(@strong sender => move |_| { group.add_action::<GameFolder>(&RelmAction::new_stateless(clone!(@strong sender => move |_| {
if let Err(err) = std::process::Command::new("xdg-open").arg(&CONFIG.game.path).spawn() { match open::that(&CONFIG.game.path) {
sender.input(AppMsg::Toast { Ok(()) => {},
title: tr("game-folder-opening-error"), Err(err) => {
description: Some(err.to_string()) sender.input(AppMsg::Toast {
}); title: tr("game-folder-opening-error"),
description: Some(err.to_string())
tracing::error!("Failed to open game folder: {err}"); });
tracing::error!("Failed to open game folder: {err}");
}
} }
}))); })));
group.add_action::<ConfigFile>(&RelmAction::new_stateless(clone!(@strong sender => move |_| { group.add_action::<ConfigFile>(&RelmAction::new_stateless(clone!(@strong sender => move |_| {
if let Some(file) = anime_launcher_sdk::consts::config_file() { if let Some(file) = anime_launcher_sdk::consts::config_file() {
if let Err(err) = std::process::Command::new("xdg-open").arg(file).spawn() { match open::that(file) {
sender.input(AppMsg::Toast { Ok(()) => {},
title: tr("config-file-opening-error"), Err(err) => {
description: Some(err.to_string()) sender.input(AppMsg::Toast {
}); title: tr("config-file-opening-error"),
description: Some(err.to_string())
tracing::error!("Failed to open config file: {err}"); });
tracing::error!("Failed to open config file: {err}");
}
} }
} }
}))); })));
group.add_action::<DebugFile>(&RelmAction::new_stateless(clone!(@strong sender => move |_| { group.add_action::<DebugFile>(&RelmAction::new_stateless(clone!(@strong sender => move |_| {
if let Err(err) = std::process::Command::new("xdg-open").arg(DEBUG_FILE.as_os_str()).spawn() { match open::that(crate::DEBUG_FILE.as_os_str()) {
sender.input(AppMsg::Toast { Ok(()) => {},
title: tr("debug-file-opening-error"), Err(err) => {
description: Some(err.to_string()) sender.input(AppMsg::Toast {
}); title: tr("debug-file-opening-error"),
description: Some(err.to_string())
tracing::error!("Failed to open debug file: {err}"); });
tracing::error!("Failed to open debug file: {err}");
}
} }
}))); })));
@ -1119,12 +1129,9 @@ impl App {
#[allow(unused_must_use)] #[allow(unused_must_use)]
dialog.connect_response(Some("save"), |_, _| { dialog.connect_response(Some("save"), |_, _| {
let result = std::process::Command::new("xdg-open") match open::that(crate::DEBUG_FILE.as_os_str()) {
.arg(crate::DEBUG_FILE.as_os_str()) Ok(()) => {},
.output(); Err(err) => tracing::error!("Failed to open debug file: {}", err),
if let Err(err) = result {
tracing::error!("Failed to open debug file: {}", err);
} }
}); });

View file

@ -158,12 +158,9 @@ impl SimpleAsyncComponent for PreferencesApp {
#[allow(unused_must_use)] #[allow(unused_must_use)]
dialog.connect_response(Some("save"), |_, _| { dialog.connect_response(Some("save"), |_, _| {
let result = std::process::Command::new("xdg-open") match open::that(crate::DEBUG_FILE.as_os_str()) {
.arg(crate::DEBUG_FILE.as_os_str()) Ok(()) => {},
.output(); Err(err) => tracing::error!("Failed to open debug file: {}", err)
if let Err(err) = result {
tracing::error!("Failed to open debug file: {}", err);
} }
}); });