From 4c5a38dfc20ae6015ddac1d3bc6fb1cb0f5416b3 Mon Sep 17 00:00:00 2001 From: Observer KRypt0n_ Date: Fri, 29 Jul 2022 22:20:06 +0200 Subject: [PATCH] 0.4.0 - added "Settings" option for main window menu - added working default paths selection in first run window From previous commits: - added subfolders support for blueprint compiler; moved first_run and preferences pages to subfolders - added 2 first run pages: + when you don't have some required components + to select default folders paths --- Cargo.toml | 2 +- assets/ui/main.blp | 1 + src/ui/first_run/mod.rs | 3 +++ src/ui/first_run/page_4.rs | 42 ++++++++++++++++++++++++++++++++++---- src/ui/main.rs | 5 +++++ 5 files changed, 48 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a21abc5..655325d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "anime-game-launcher" -version = "0.3.1" +version = "0.4.0" description = "Anime Game launcher" authors = ["Nikita Podvirnyy "] license = "GPL-3.0" diff --git a/assets/ui/main.blp b/assets/ui/main.blp index 6c3a781..9d23867 100644 --- a/assets/ui/main.blp +++ b/assets/ui/main.blp @@ -125,5 +125,6 @@ Gtk.AboutDialog about { menu app_menu { item ("Check for updates") + item ("Settings", "open-settings.open-settings") item ("About", "show-about-dialog.show-about-dialog") } diff --git a/src/ui/first_run/mod.rs b/src/ui/first_run/mod.rs index 12697bc..62f39dd 100644 --- a/src/ui/first_run/mod.rs +++ b/src/ui/first_run/mod.rs @@ -35,6 +35,7 @@ pub struct AppWidgets { pub window: adw::ApplicationWindow, pub carousel: adw::Carousel, + // TODO: use names instead of numbers pub page_1: page_1::Page, pub page_2: page_2::Page, pub page_3: page_3::Page, @@ -192,6 +193,8 @@ impl App { } Actions::FourthPageContinue => { + config::update_raw(this.widgets.page_4.update_config(config::get().unwrap())).unwrap(); + this.widgets.carousel.scroll_to(&this.widgets.page_5.page, true); } diff --git a/src/ui/first_run/page_4.rs b/src/ui/first_run/page_4.rs index 37bfd68..0df71f4 100644 --- a/src/ui/first_run/page_4.rs +++ b/src/ui/first_run/page_4.rs @@ -23,8 +23,10 @@ pub fn choose_dir>(current_folder: String, parent: &T) -> Aw dialogue.connect_response(move |dialogue, response| { if response == gtk::ResponseType::Accept { - sender.send(dialogue.current_folder().unwrap().to_string()).unwrap(); + sender.send(dialogue.current_folder().unwrap().path().unwrap().to_str().unwrap().to_string()).unwrap(); } + + dialogue.close(); }); dialogue.show(); @@ -72,6 +74,7 @@ impl Page { Err(err) => return Err(err.to_string()) }; + // Add paths to subtitles result.runners_folder.set_subtitle(&config.game.wine.builds); result.dxvk_folder.set_subtitle(&config.game.dxvk.builds); result.prefix_folder.set_subtitle(&config.game.wine.prefix); @@ -81,10 +84,41 @@ impl Page { None => String::from("/tmp") }); - result.runners_folder.connect_activated(clone!(@strong result.window as window => move |row| { - choose_dir(row.subtitle().unwrap().to_string(), &window); - })); + // Connect path selection events + result.connect_activated(&result.runners_folder); + result.connect_activated(&result.dxvk_folder); + result.connect_activated(&result.prefix_folder); + result.connect_activated(&result.game_folder); + result.connect_activated(&result.temp_folder); Ok(result) } + + fn connect_activated(&self, row: &adw::ActionRow) { + row.connect_activated(clone!(@strong self.window as window => move |row| { + let (sender, receiver) = glib::MainContext::channel::(glib::PRIORITY_DEFAULT); + + choose_dir(row.subtitle().unwrap().to_string(), &window).then(move |path| { + sender.send(path.clone()).unwrap(); + }); + + let row = row.clone(); + + receiver.attach(None, move |path| { + row.set_subtitle(&path); + + glib::Continue(false) + }); + })); + } + + pub fn update_config(&self, mut config: config::Config) -> config::Config { + config.game.wine.builds = self.runners_folder.subtitle().unwrap().to_string(); + config.game.dxvk.builds = self.dxvk_folder.subtitle().unwrap().to_string(); + config.game.wine.prefix = self.prefix_folder.subtitle().unwrap().to_string(); + config.game.path = self.game_folder.subtitle().unwrap().to_string(); + config.launcher.temp = Some(self.temp_folder.subtitle().unwrap().to_string()); + + config + } } diff --git a/src/ui/main.rs b/src/ui/main.rs index 927a7fe..bd2597a 100644 --- a/src/ui/main.rs +++ b/src/ui/main.rs @@ -192,10 +192,15 @@ impl App { /// Add default events and values to the widgets fn init_events(self) -> Self { + // Add menu actions add_action(&self.widgets.menu, "show-about-dialog", clone!(@strong self.widgets.about as about => move || { about.show(); })); + add_action(&self.widgets.menu, "open-settings", clone!(@strong self as this => move || { + this.update(Actions::OpenPreferencesPage).unwrap(); + })); + // Open preferences page self.widgets.open_preferences.connect_clicked(Actions::OpenPreferencesPage.into_fn(&self));