From 7e20abf991d24a679a6a2676e3c9eb6837a7cd3c Mon Sep 17 00:00:00 2001 From: Observer KRypt0n_ Date: Wed, 29 Mar 2023 18:45:31 +0200 Subject: [PATCH] feat(ui): added initial installation migration window support --- Cargo.toml | 2 + src/ui/first_run/main.rs | 4 +- src/ui/main/mod.rs | 6 +-- src/ui/migrate_installation.rs | 71 ++++++++++++++++++++++++++++++++++ src/ui/mod.rs | 1 + src/ui/preferences/general.rs | 22 +++++++++++ 6 files changed, 101 insertions(+), 5 deletions(-) create mode 100644 src/ui/migrate_installation.rs diff --git a/Cargo.toml b/Cargo.toml index 3f625fe..fd2c196 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,8 @@ glib-build-tools = "0.17" git = "https://github.com/an-anime-team/anime-launcher-sdk" tag = "0.5.7" +# path = "../anime-launcher-sdk" # ! for dev purposes only + [dependencies] relm4 = { version = "0.6.0-alpha.2", features = ["macros", "libadwaita"] } gtk = { package = "gtk4", version = "0.6", features = ["v4_8"] } diff --git a/src/ui/first_run/main.rs b/src/ui/first_run/main.rs index c2d0fc2..03863b4 100644 --- a/src/ui/first_run/main.rs +++ b/src/ui/first_run/main.rs @@ -17,7 +17,7 @@ use super::select_voiceovers::*; use super::download_components::*; use super::finish::*; -pub static mut MAIN_WINDOW: Option = None; +pub static mut MAIN_WINDOW: Option = None; // TODO: add special page for launcher style selection @@ -61,7 +61,7 @@ impl SimpleComponent for FirstRunApp { type Output = (); view! { - window = adw::Window { + window = adw::ApplicationWindow { set_default_size: (780, 560), #[watch] diff --git a/src/ui/main/mod.rs b/src/ui/main/mod.rs index 3fbf1e5..4fb1b31 100644 --- a/src/ui/main/mod.rs +++ b/src/ui/main/mod.rs @@ -38,9 +38,9 @@ relm4::new_stateless_action!(WishUrl, WindowActionGroup, "wish_url"); relm4::new_stateless_action!(About, WindowActionGroup, "about"); -static mut MAIN_WINDOW: Option = None; -static mut PREFERENCES_WINDOW: Option> = None; -static mut ABOUT_DIALOG: Option> = None; +pub static mut MAIN_WINDOW: Option = None; +pub static mut PREFERENCES_WINDOW: Option> = None; +pub static mut ABOUT_DIALOG: Option> = None; pub struct App { progress_bar: AsyncController, diff --git a/src/ui/migrate_installation.rs b/src/ui/migrate_installation.rs new file mode 100644 index 0000000..76187a2 --- /dev/null +++ b/src/ui/migrate_installation.rs @@ -0,0 +1,71 @@ +use relm4::prelude::*; +use relm4::component::*; + +use gtk::prelude::*; +use adw::prelude::*; + +use crate::*; + +use super::first_run::default_paths::DefaultPathsApp; + +pub struct MigrateInstallationApp { + default_paths: AsyncController, +} + +#[derive(Debug)] +pub enum MigrateInstallationAppMsg { + Migrate +} + +#[relm4::component(pub)] +impl SimpleComponent for MigrateInstallationApp { + type Init = (); + type Input = MigrateInstallationAppMsg; + type Output = (); + + view! { + adw::Window { + set_default_size: (780, 560), + set_modal: true, + + #[watch] + set_title: Some("Migrate installation"), + + gtk::Box { + set_orientation: gtk::Orientation::Vertical, + + adw::HeaderBar { + add_css_class: "flat" + }, + + append = model.default_paths.widget(), + } + } + } + + fn init( + _init: Self::Init, + root: &Self::Root, + sender: ComponentSender, + ) -> ComponentParts { + tracing::info!("Initializing migration window"); + + let model = Self { + default_paths: DefaultPathsApp::builder() + .launch(()) + .detach() + }; + + let widgets = view_output!(); + + ComponentParts { model, widgets } + } + + fn update(&mut self, msg: Self::Input, _sender: ComponentSender) { + match msg { + MigrateInstallationAppMsg::Migrate => { + todo!() + } + } + } +} diff --git a/src/ui/mod.rs b/src/ui/mod.rs index e5365c9..eae6545 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -3,3 +3,4 @@ pub mod about; pub mod preferences; pub mod components; pub mod first_run; +pub mod migrate_installation; diff --git a/src/ui/preferences/general.rs b/src/ui/preferences/general.rs index c44e97c..a16412c 100644 --- a/src/ui/preferences/general.rs +++ b/src/ui/preferences/general.rs @@ -17,6 +17,7 @@ use anime_launcher_sdk::components::wine::WincompatlibWine; use anime_launcher_sdk::wincompatlib::prelude::*; use super::main::PreferencesAppMsg; +use crate::ui::migrate_installation::MigrateInstallationApp; use crate::ui::components; use crate::ui::components::*; use crate::i18n::*; @@ -102,6 +103,7 @@ impl AsyncFactoryComponent for VoicePackageComponent { pub struct GeneralApp { voice_packages: AsyncFactoryVecDeque, + migrate_installation: Controller, wine_components: AsyncController>, dxvk_components: AsyncController>, @@ -145,6 +147,7 @@ pub enum GeneralAppMsg { RemoveVoicePackage(DynamicIndex), SetVoicePackageSensitivity(DynamicIndex, bool), + OpenMigrateInstallation, RepairGame, UpdateLauncherStyle(LauncherStyle), @@ -307,6 +310,13 @@ impl SimpleAsyncComponent for GeneralApp { set_spacing: 8, set_margin_top: 16, + gtk::Button { + set_label: "Migrate installation", + set_tooltip_text: Some("Open special window where you can change your game installation folder"), + + connect_clicked => GeneralAppMsg::OpenMigrateInstallation + }, + gtk::Button { set_label: &tr("repair-game"), @@ -674,6 +684,10 @@ impl SimpleAsyncComponent for GeneralApp { let mut model = Self { voice_packages: AsyncFactoryVecDeque::new(adw::ExpanderRow::new(), sender.input_sender()), + migrate_installation: MigrateInstallationApp::builder() + .launch(()) + .detach(), + wine_components: ComponentsList::builder() .launch(ComponentsListInit { pattern: ComponentsListPattern { @@ -839,6 +853,14 @@ impl SimpleAsyncComponent for GeneralApp { } } + GeneralAppMsg::OpenMigrateInstallation => unsafe { + if let Some(window) = crate::ui::main::PREFERENCES_WINDOW.as_ref() { + self.migrate_installation.widget().set_transient_for(Some(window.widget())); + } + + self.migrate_installation.widget().show(); + } + #[allow(unused_must_use)] GeneralAppMsg::RepairGame => { sender.output(Self::Output::RepairGame);