diff --git a/assets/locales/en/main.ftl b/assets/locales/en/main.ftl index 11dd709..96d198e 100644 --- a/assets/locales/en/main.ftl +++ b/assets/locales/en/main.ftl @@ -6,6 +6,10 @@ close = Close save = Save +loading-game-version = Loading game version +loading-patch-status = Loading patch status + + checking-free-space = Checking free space downloading = Downloading unpacking = Unpacking diff --git a/assets/locales/ru/main.ftl b/assets/locales/ru/main.ftl index 8b613a0..bf203d0 100644 --- a/assets/locales/ru/main.ftl +++ b/assets/locales/ru/main.ftl @@ -6,6 +6,10 @@ close = Закрыть save = Сохранить +loading-game-version = Загрузка версии игры +loading-patch-status = Загрузка статуса патча + + checking-free-space = Проверка свободного места downloading = Загрузка unpacking = Распаковка diff --git a/src/ui/main.rs b/src/ui/main.rs index 8c4114f..00fccea 100644 --- a/src/ui/main.rs +++ b/src/ui/main.rs @@ -1,5 +1,6 @@ use relm4::{ prelude::*, + component::*, actions::*, MessageBroker }; @@ -23,7 +24,7 @@ relm4::new_stateless_action!(ConfigFile, WindowActionGroup, "config_file"); relm4::new_stateless_action!(About, WindowActionGroup, "about"); -static mut PREFERENCES_WINDOW: Option> = None; +static mut PREFERENCES_WINDOW: Option> = None; static mut ABOUT_DIALOG: Option> = None; pub struct App { @@ -41,6 +42,7 @@ pub enum AppMsg { /// was retrieved from remote repos UpdatePatch(Option), + UpdateLoadingStatus(Option>), PerformAction, OpenPreferences, ClosePreferences, @@ -225,7 +227,7 @@ impl SimpleComponent for App { tracing::info!("Initializing main window"); let model = App { - loading: None, + loading: Some(None), style: CONFIG.launcher.style }; @@ -276,10 +278,13 @@ impl SimpleComponent for App { tracing::info!("Initializing heavy tasks"); // Update initial game version status + + sender.input(AppMsg::UpdateLoadingStatus(Some(Some(tr("loading-game-version"))))); + sender.input(AppMsg::UpdateGameDiff(match GAME.try_get_diff() { Ok(diff) => Some(diff), Err(err) => { - tracing::error!("Failed to get game diff {err}"); + tracing::error!("Failed to get game diff: {err}"); None } @@ -288,10 +293,13 @@ impl SimpleComponent for App { tracing::info!("Updated game version status"); // Update initial patch status + + sender.input(AppMsg::UpdateLoadingStatus(Some(Some(tr("loading-patch-status"))))); + sender.input(AppMsg::UpdatePatch(match Patch::try_fetch(&CONFIG.patch.servers, None) { Ok(patch) => Some(patch), Err(err) => { - tracing::error!("Failed to fetch patch info {err}"); + tracing::error!("Failed to fetch patch info: {err}"); None } @@ -299,6 +307,10 @@ impl SimpleComponent for App { tracing::info!("Updated patch status"); + // Hide loading page + sender.input(AppMsg::UpdateLoadingStatus(None)); + + // Mark app as loaded unsafe { crate::READY = true; } @@ -323,6 +335,10 @@ impl SimpleComponent for App { PREFERENCES_WINDOW.as_ref().unwrap_unchecked().sender().send(PreferencesAppMsg::UpdatePatch(patch)); }, + AppMsg::UpdateLoadingStatus(status) => { + self.loading = status; + }, + AppMsg::PerformAction => { anime_launcher_sdk::game::run().expect("Failed to run the game"); } diff --git a/src/ui/preferences/enhancements.rs b/src/ui/preferences/enhancements.rs index f4b4436..98d79ff 100644 --- a/src/ui/preferences/enhancements.rs +++ b/src/ui/preferences/enhancements.rs @@ -1,4 +1,5 @@ use relm4::prelude::*; +use relm4::component::*; use adw::prelude::*; @@ -10,8 +11,8 @@ use crate::*; pub struct EnhancementsApp; -#[relm4::component(pub)] -impl SimpleComponent for EnhancementsApp { +#[relm4::component(async, pub)] +impl SimpleAsyncComponent for EnhancementsApp { type Init = (); type Input = (); type Output = (); @@ -398,20 +399,20 @@ impl SimpleComponent for EnhancementsApp { } } - fn init( + async fn init( _init: Self::Init, - root: &Self::Root, - _sender: ComponentSender, - ) -> ComponentParts { + root: Self::Root, + _sender: AsyncComponentSender, + ) -> AsyncComponentParts { tracing::info!("Initializing enhancements settings"); let model = Self; let widgets = view_output!(); - ComponentParts { model, widgets } + AsyncComponentParts { model, widgets } } - fn update(&mut self, msg: Self::Input, _sender: ComponentSender) { + async fn update(&mut self, msg: Self::Input, _sender: AsyncComponentSender) { tracing::debug!("Called enhancements settings event: {:?}", msg); } } diff --git a/src/ui/preferences/general.rs b/src/ui/preferences/general.rs index eb91760..498d8cf 100644 --- a/src/ui/preferences/general.rs +++ b/src/ui/preferences/general.rs @@ -59,8 +59,8 @@ pub enum GeneralAppMsg { ResetDxvkSelection(usize) } -#[relm4::component(pub)] -impl SimpleComponent for GeneralApp { +#[relm4::component(async, pub)] +impl SimpleAsyncComponent for GeneralApp { type Init = (); type Input = GeneralAppMsg; type Output = super::main::PreferencesAppMsg; @@ -457,11 +457,11 @@ impl SimpleComponent for GeneralApp { } } - fn init( + async fn init( _init: Self::Init, - root: &Self::Root, - sender: ComponentSender, - ) -> ComponentParts { + root: Self::Root, + sender: AsyncComponentSender, + ) -> AsyncComponentParts { tracing::info!("Initializing general settings"); let model = Self { @@ -504,10 +504,10 @@ impl SimpleComponent for GeneralApp { let widgets = view_output!(); - ComponentParts { model, widgets } + AsyncComponentParts { model, widgets } } - fn update(&mut self, msg: Self::Input, sender: ComponentSender) { + async fn update(&mut self, msg: Self::Input, sender: AsyncComponentSender) { tracing::debug!("Called general settings event: {:?}", msg); match msg { diff --git a/src/ui/preferences/main.rs b/src/ui/preferences/main.rs index 1df97d3..9b44ab4 100644 --- a/src/ui/preferences/main.rs +++ b/src/ui/preferences/main.rs @@ -1,4 +1,5 @@ use relm4::prelude::*; +use relm4::component::*; use gtk::prelude::*; use adw::prelude::*; @@ -15,8 +16,8 @@ use super::enhancements::*; pub static mut PREFERENCES_WINDOW: Option = None; pub struct PreferencesApp { - general: Controller, - enhancements: Controller + general: AsyncController, + enhancements: AsyncController } #[derive(Debug, Clone)] @@ -36,8 +37,8 @@ pub enum PreferencesAppMsg { UpdateLauncherStyle(LauncherStyle) } -#[relm4::component(pub)] -impl SimpleComponent for PreferencesApp { +#[relm4::component(async, pub)] +impl SimpleAsyncComponent for PreferencesApp { type Init = gtk::Window; type Input = PreferencesAppMsg; type Output = crate::ui::main::AppMsg; @@ -65,11 +66,11 @@ impl SimpleComponent for PreferencesApp { } } - fn init( + async fn init( parent: Self::Init, - root: &Self::Root, - sender: ComponentSender, - ) -> ComponentParts { + root: Self::Root, + sender: AsyncComponentSender, + ) -> AsyncComponentParts { tracing::info!("Initializing preferences window"); let model = Self { @@ -95,10 +96,10 @@ impl SimpleComponent for PreferencesApp { model.general.sender().send(GeneralAppMsg::UpdateDownloadedDxvk); } - ComponentParts { model, widgets } + AsyncComponentParts { model, widgets } } - fn update(&mut self, msg: Self::Input, sender: ComponentSender) { + async fn update(&mut self, msg: Self::Input, sender: AsyncComponentSender) { tracing::debug!("Called preferences window event: {:?}", msg); match msg {