From f7779635481b3443ee5ca76291399bb989b71b87 Mon Sep 17 00:00:00 2001 From: Observer KRypt0n_ Date: Sun, 9 Apr 2023 17:58:23 +0200 Subject: [PATCH] feat: added wine tools to settings --- Cargo.lock | 8 ++-- Cargo.toml | 5 ++- assets/locales/en/errors.ftl | 2 + src/ui/preferences/general.rs | 75 ++++++++++++++++++++++++++++++++++- 4 files changed, 83 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c0d3483..8e61321 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -86,8 +86,8 @@ dependencies = [ [[package]] name = "anime-launcher-sdk" -version = "0.5.13" -source = "git+https://github.com/an-anime-team/anime-launcher-sdk?tag=0.5.13#66a80e5f5906b1cfc1b9716a4448dd03cf854ae8" +version = "0.5.14" +source = "git+https://github.com/an-anime-team/anime-launcher-sdk?tag=0.5.14#98de4c7d707ed7428257953526625e8f168f7d84" dependencies = [ "anime-game-core", "anyhow", @@ -1718,9 +1718,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "open" -version = "4.0.0" +version = "4.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd61e3bf9d78956c72ee864bba52431f7f43994b21a17e9e72596a81bd61075b" +checksum = "075c5203b3a2b698bc72c6c10b1f6263182135751d5013ea66e8a4b3d0562a43" dependencies = [ "pathdiff", ] diff --git a/Cargo.toml b/Cargo.toml index b042872..66ef36a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ glib-build-tools = "0.17" [dependencies.anime-launcher-sdk] git = "https://github.com/an-anime-team/anime-launcher-sdk" -tag = "0.5.13" +tag = "0.5.14" # path = "../anime-launcher-sdk" # ! for dev purposes only @@ -25,8 +25,9 @@ tag = "0.5.13" relm4 = { version = "0.6.0-alpha.2", features = ["macros", "libadwaita"] } gtk = { package = "gtk4", version = "0.6", features = ["v4_8"] } adw = { package = "libadwaita", version = "0.3", features = ["v1_2"] } + rfd = { version = "0.11", features = ["xdg-portal"], default-features = false } -open = "4.0.0" +open = "4.0" tracing = "0.1" tracing-subscriber = "0.3" diff --git a/assets/locales/en/errors.ftl b/assets/locales/en/errors.ftl index cb76fc4..8271f84 100644 --- a/assets/locales/en/errors.ftl +++ b/assets/locales/en/errors.ftl @@ -6,6 +6,8 @@ debug-file-opening-error = Failed to open debug file wish-url-search-failed = No wishes url found wish-url-opening-error = Could not open wishes url +wine-run-error = Failed to run {$executable} executable using wine + game-launching-failed = Failed to launch game failed-get-selected-wine = Failed to get selected wine version downloading-failed = Downloading failed diff --git a/src/ui/preferences/general.rs b/src/ui/preferences/general.rs index a59a3ac..8f1aa45 100644 --- a/src/ui/preferences/general.rs +++ b/src/ui/preferences/general.rs @@ -152,6 +152,7 @@ pub enum GeneralAppMsg { OpenMigrateInstallation, RepairGame, + WineOpen(&'static [&'static str]), UpdateLauncherStyle(LauncherStyle), @@ -696,6 +697,57 @@ impl SimpleAsyncComponent for GeneralApp { add = model.wine_components.widget(), }, + add = &adw::PreferencesGroup { + adw::ExpanderRow { + set_title: "Wine tools", + + add_row = &adw::ActionRow { + set_title: "Command line", + set_subtitle: "start cmd", + + set_activatable: true, + + connect_activated => GeneralAppMsg::WineOpen(&["start", "cmd"]) + }, + + add_row = &adw::ActionRow { + set_title: "Registry editor", + set_subtitle: "regedit", + + set_activatable: true, + + connect_activated => GeneralAppMsg::WineOpen(&["regedit"]) + }, + + add_row = &adw::ActionRow { + set_title: "Explorer", + set_subtitle: "explorer", + + set_activatable: true, + + connect_activated => GeneralAppMsg::WineOpen(&["explorer"]) + }, + + add_row = &adw::ActionRow { + set_title: "Task manager", + set_subtitle: "taskmgr", + + set_activatable: true, + + connect_activated => GeneralAppMsg::WineOpen(&["taskmgr"]) + }, + + add_row = &adw::ActionRow { + set_title: "Configuration", + set_subtitle: "winecfg", + + set_activatable: true, + + connect_activated => GeneralAppMsg::WineOpen(&["winecfg"]) + } + } + }, + add = &adw::PreferencesGroup { set_title: &tr("dxvk-version"), @@ -968,12 +1020,33 @@ impl SimpleAsyncComponent for GeneralApp { sender.output(Self::Output::RepairGame); } + GeneralAppMsg::WineOpen(executable) => { + let config = config::get().unwrap_or_else(|_| CONFIG.clone()); + + if let Ok(Some(wine)) = config.get_selected_wine() { + let result = wine.to_wine(config.components.path, Some(config.game.wine.builds.join(&wine.name))) + .with_prefix(config.game.wine.prefix) + .run_args(executable); + + if let Err(err) = result { + sender.input(GeneralAppMsg::Toast { + title: tr_args("wine-run-error", [ + ("executable", executable.join(" ").into()) + ]), + description: Some(err.to_string()) + }); + + tracing::error!("Failed to run {:?} using wine: {err}", executable); + } + } + } + #[allow(unused_must_use)] GeneralAppMsg::UpdateLauncherStyle(style) => { if style == LauncherStyle::Classic && !KEEP_BACKGROUND_FILE.exists() { if let Err(err) = crate::background::download_background() { tracing::error!("Failed to download background picture"); - + sender.input(GeneralAppMsg::Toast { title: tr("background-downloading-failed"), description: Some(err.to_string())