components: made all preferences components async

- apparently they tend to freeze without it
- also added use of `AdwStatusPage` during heavy tasks execution
This commit is contained in:
Observer KRypt0n_ 2023-02-22 20:58:01 +02:00
parent 6525fbb0d9
commit 8199e0eac9
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
6 changed files with 56 additions and 30 deletions

View file

@ -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

View file

@ -6,6 +6,10 @@ close = Закрыть
save = Сохранить
loading-game-version = Загрузка версии игры
loading-patch-status = Загрузка статуса патча
checking-free-space = Проверка свободного места
downloading = Загрузка
unpacking = Распаковка

View file

@ -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<Controller<PreferencesApp>> = None;
static mut PREFERENCES_WINDOW: Option<AsyncController<PreferencesApp>> = None;
static mut ABOUT_DIALOG: Option<Controller<AboutDialog>> = None;
pub struct App {
@ -41,6 +42,7 @@ pub enum AppMsg {
/// was retrieved from remote repos
UpdatePatch(Option<Patch>),
UpdateLoadingStatus(Option<Option<String>>),
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");
}

View file

@ -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<Self>,
) -> ComponentParts<Self> {
root: Self::Root,
_sender: AsyncComponentSender<Self>,
) -> AsyncComponentParts<Self> {
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<Self>) {
async fn update(&mut self, msg: Self::Input, _sender: AsyncComponentSender<Self>) {
tracing::debug!("Called enhancements settings event: {:?}", msg);
}
}

View file

@ -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<Self>,
) -> ComponentParts<Self> {
root: Self::Root,
sender: AsyncComponentSender<Self>,
) -> AsyncComponentParts<Self> {
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<Self>) {
async fn update(&mut self, msg: Self::Input, sender: AsyncComponentSender<Self>) {
tracing::debug!("Called general settings event: {:?}", msg);
match msg {

View file

@ -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<adw::PreferencesWindow> = None;
pub struct PreferencesApp {
general: Controller<GeneralApp>,
enhancements: Controller<EnhancementsApp>
general: AsyncController<GeneralApp>,
enhancements: AsyncController<EnhancementsApp>
}
#[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<Self>,
) -> ComponentParts<Self> {
root: Self::Root,
sender: AsyncComponentSender<Self>,
) -> AsyncComponentParts<Self> {
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<Self>) {
async fn update(&mut self, msg: Self::Input, sender: AsyncComponentSender<Self>) {
tracing::debug!("Called preferences window event: {:?}", msg);
match msg {