From b5fe109be691e45d93ac9ca9c235726050d402cd Mon Sep 17 00:00:00 2001 From: Observer KRypt0n_ Date: Tue, 2 Aug 2022 19:26:10 +0200 Subject: [PATCH] Several changes - added "Open launcher folder" button to settings - removed `glib::Downgrade` trait from all the `App`s' `Value`s - removed `tasks` mod; removed `tokio` dependency; rewritten `OpenPreferencesPage` to work with threads instead of futures - added `opt-level = 3` to release profile --- Cargo.toml | 2 +- assets/ui/preferences/general.blp | 4 ++++ src/lib/mod.rs | 1 - src/lib/tasks.rs | 8 -------- src/main.rs | 3 +-- src/ui/main.rs | 15 ++++++++------- src/ui/preferences/environment.rs | 2 +- src/ui/preferences/general.rs | 30 ++++++++++++++++++++++-------- 8 files changed, 37 insertions(+), 28 deletions(-) delete mode 100644 src/lib/tasks.rs diff --git a/Cargo.toml b/Cargo.toml index 8bee237..6d465e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ build = "build.rs" [profile.release] strip = true lto = true +opt-level = 3 [build-dependencies] gtk4 = "0.4" @@ -24,7 +25,6 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" dirs = "4.0.0" -tokio = { version = "1.20", features = ["rt", "rt-multi-thread", "macros"] } wait_not_await = "0.2.1" regex = "1.6.0" lazy_static = "1.4.0" diff --git a/assets/ui/preferences/general.blp b/assets/ui/preferences/general.blp index 92de540..cfe3fa0 100644 --- a/assets/ui/preferences/general.blp +++ b/assets/ui/preferences/general.blp @@ -32,6 +32,10 @@ Adw.PreferencesPage page { spacing: 8; margin-top: 16; + Gtk.Button launcher_folder { + label: "Open launcher folder"; + } + Gtk.Button repair_game { label: "Repair game"; } diff --git a/src/lib/mod.rs b/src/lib/mod.rs index 09c7153..c07ab63 100644 --- a/src/lib/mod.rs +++ b/src/lib/mod.rs @@ -1,6 +1,5 @@ pub mod consts; pub mod config; -pub mod tasks; pub mod game; pub mod dxvk; pub mod wine; diff --git a/src/lib/tasks.rs b/src/lib/tasks.rs deleted file mode 100644 index 45fe4ca..0000000 --- a/src/lib/tasks.rs +++ /dev/null @@ -1,8 +0,0 @@ -use std::future::Future; - -pub fn run(future: T) where - T: Future + Send + 'static, - ::Output: Send -{ - tokio::task::spawn(future); -} diff --git a/src/main.rs b/src/main.rs index f805dbe..c10ab11 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,8 +16,7 @@ pub const APP_ID: &str = "com.gitlab.an-anime-team.an-anime-game-launcher-gtk"; pub const APP_VERSION: &str = env!("CARGO_PKG_VERSION"); pub const APP_DEBUG: bool = cfg!(debug_assertions); -#[tokio::main] -async fn main() { +fn main() { gtk::init().expect("GTK initialization failed"); adw::init(); diff --git a/src/ui/main.rs b/src/ui/main.rs index 156f6d3..5cdc7fa 100644 --- a/src/ui/main.rs +++ b/src/ui/main.rs @@ -20,7 +20,6 @@ use super::components::progress_bar::*; use crate::lib::config; use crate::lib::game; -use crate::lib::tasks; use crate::lib::launcher::states::LauncherState; use crate::lib::wine::{ Version as WineVersion, @@ -155,9 +154,9 @@ impl Actions { /// In this example we store a counter here to know what should we increment or decrement /// /// This must implement `Default` trait -#[derive(Debug, Default, glib::Downgrade)] +#[derive(Debug, Default)] pub struct Values { - state: Rc + state: LauncherState } /// The main application structure @@ -238,7 +237,9 @@ impl App { Actions::OpenPreferencesPage => { this.widgets.leaflet.set_visible_child_name("preferences_page"); - tasks::run(clone!(@strong this => async move { + let this = this.clone(); + + std::thread::spawn(move || { if let Err(err) = this.widgets.preferences_stack.update() { glib::MainContext::default().invoke(move || { this.update(Actions::PreferencesGoBack).unwrap(); @@ -246,7 +247,7 @@ impl App { this.toast("Failed to update preferences", err); }); } - })); + }); } Actions::PreferencesGoBack => { @@ -257,7 +258,7 @@ impl App { Actions::PerformButtonEvent => { let values = this.values.take(); - let state = (*values.state).clone(); + let state = values.state.clone(); this.values.set(values); @@ -801,7 +802,7 @@ impl App { let mut values = self.values.take(); - values.state = Rc::new(state); + values.state = state; self.values.set(values); } diff --git a/src/ui/preferences/environment.rs b/src/ui/preferences/environment.rs index 08716ca..23f699c 100644 --- a/src/ui/preferences/environment.rs +++ b/src/ui/preferences/environment.rs @@ -66,7 +66,7 @@ pub enum Actions { /// This must implement `Default` trait #[derive(Debug, Default)] pub struct Values { - pub rows: HashMap + rows: HashMap } /// The main application structure diff --git a/src/ui/preferences/general.rs b/src/ui/preferences/general.rs index 2baa8f1..7e6ffdd 100644 --- a/src/ui/preferences/general.rs +++ b/src/ui/preferences/general.rs @@ -7,9 +7,11 @@ use gtk::glib::clone; use std::rc::Rc; use std::cell::Cell; use std::io::Error; +use std::process::Command; use anime_game_core::prelude::*; +use crate::lib::consts; use crate::lib::config; use crate::lib::dxvk; use crate::lib::wine; @@ -33,6 +35,7 @@ pub struct AppWidgets { pub voiceovers_row: adw::ExpanderRow, pub voieover_components: Rc>, + pub launcher_folder: gtk::Button, pub repair_game: gtk::Button, pub game_version: gtk::Label, @@ -64,6 +67,7 @@ impl AppWidgets { voiceovers_row: get_object(&builder, "voiceovers_row")?, voieover_components: Default::default(), + launcher_folder: get_object(&builder, "launcher_folder")?, repair_game: get_object(&builder, "repair_game")?, game_version: get_object(&builder, "game_version")?, @@ -163,8 +167,9 @@ impl AppWidgets { /// It may be helpful if you want to add the same event for several widgets, or call an action inside of another action #[derive(Debug, Clone, glib::Downgrade)] pub enum Actions { - VoiceoverPerformAction(Rc), + OpenLauncherFolder, RepairGame, + VoiceoverPerformAction(Rc), DxvkPerformAction(Rc), WinePerformAction(Rc<(usize, usize)>), UpdateDxvkComboRow, @@ -187,10 +192,10 @@ impl Actions { /// In this example we store a counter here to know what should we increment or decrement /// /// This must implement `Default` trait -#[derive(Debug, Default, glib::Downgrade)] +#[derive(Debug, Default)] pub struct Values { - downloaded_wine_versions: Rc>>, - downloaded_dxvk_versions: Rc>> + downloaded_wine_versions: Option>, + downloaded_dxvk_versions: Option> } /// The main application structure @@ -231,6 +236,7 @@ impl App { /// Add default events and values to the widgets fn init_events(self) -> Self { + self.widgets.launcher_folder.connect_clicked(Actions::OpenLauncherFolder.into_fn(&self)); self.widgets.repair_game.connect_clicked(Actions::RepairGame.into_fn(&self)); // Voiceover download/delete button event @@ -332,6 +338,14 @@ impl App { println!("[general page] [update] action: {:?}", &action); match action { + Actions::OpenLauncherFolder => { + if let Some(launcher_folder) = consts::launcher_dir(){ + if let Err(err) = Command::new("xdg-open").arg(launcher_folder).spawn() { + this.toast("Failed to open launcher folder", err); + } + } + } + Actions::RepairGame => { let option = (&*this.app).take(); this.app.set(option.clone()); @@ -472,7 +486,7 @@ impl App { let mut values = this.values.take(); - values.downloaded_dxvk_versions = Rc::new(Some(raw_list)); + values.downloaded_dxvk_versions = Some(raw_list); this.values.set(values); @@ -491,7 +505,7 @@ impl App { Actions::SelectDxvkVersion(i) => { let values = this.values.take(); - if let Some(dxvk_versions) = &*values.downloaded_dxvk_versions { + if let Some(dxvk_versions) = &values.downloaded_dxvk_versions { let version = dxvk_versions[*i].clone(); if config.game.dxvk.selected != Some(version.name.clone()) { @@ -535,7 +549,7 @@ impl App { let mut values = this.values.take(); - values.downloaded_wine_versions = Rc::new(Some(list)); + values.downloaded_wine_versions = Some(list); this.values.set(values); @@ -554,7 +568,7 @@ impl App { Actions::SelectWineVersion(i) => { let values = this.values.take(); - if let Some(wine_versions) = &*values.downloaded_wine_versions { + if let Some(wine_versions) = &values.downloaded_wine_versions { match *i { 0 => config.game.wine.selected = None, i => config.game.wine.selected = Some(wine_versions[i - 1].name.clone())