From 032ca88a6e3b05a423b4043266fd3928c1b7419b Mon Sep 17 00:00:00 2001 From: Observer KRypt0n_ Date: Tue, 7 Mar 2023 13:07:22 +0200 Subject: [PATCH] fix: fixed initial setup window panic Before it couldn't get list of available wine/dxvk versions because on first run launcher obviously doesn't have `components` folder and it needs to be synced with one of remotes I've added here status page and heavy tasks system to the first run window as it works now on the main window, and now components are synced there behind status page As well was updated SDK with fixed `Installer::get_filename` method which will fix issue with stuff downloading closes https://github.com/an-anime-team/an-anime-game-launcher/issues/91 --- Cargo.lock | 4 +- anime-launcher-sdk | 2 +- src/ui/first_run/download_components.rs | 10 ++- src/ui/first_run/main.rs | 85 +++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6681758..405b7dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,7 +31,7 @@ dependencies = [ [[package]] name = "anime-game-core" -version = "1.3.9" +version = "1.3.10" dependencies = [ "anyhow", "bzip2", @@ -76,7 +76,7 @@ dependencies = [ [[package]] name = "anime-launcher-sdk" -version = "0.3.3" +version = "0.3.4" dependencies = [ "anime-game-core", "anyhow", diff --git a/anime-launcher-sdk b/anime-launcher-sdk index 219d0f7..7bcfdbe 160000 --- a/anime-launcher-sdk +++ b/anime-launcher-sdk @@ -1 +1 @@ -Subproject commit 219d0f7704e18d74a9205163ffbb7d1718291ea4 +Subproject commit 7bcfdbee8583f046c9df045577bd679ee4eb45c2 diff --git a/src/ui/first_run/download_components.rs b/src/ui/first_run/download_components.rs index ca1cec7..b6c1464 100644 --- a/src/ui/first_run/download_components.rs +++ b/src/ui/first_run/download_components.rs @@ -61,6 +61,7 @@ pub struct DownloadComponentsApp { #[derive(Debug, Clone)] pub enum DownloadComponentsAppMsg { + UpdateVersionsLists, DownloadWine, CreatePrefix, DownloadDXVK, @@ -265,8 +266,8 @@ impl SimpleAsyncComponent for DownloadComponentsApp { dxvk_combo: adw::ComboRow::new(), // FIXME: .filter(|version| version.recommended) - wine_versions: wine::get_groups(&CONFIG.components.path).unwrap_or_default()[0].versions.clone().into_iter().collect(), - dxvk_versions: dxvk::get_groups(&CONFIG.components.path).unwrap_or_default()[0].versions.clone().into_iter().collect(), + wine_versions: vec![], + dxvk_versions: vec![], downloading_wine: None, creating_prefix: None, @@ -288,6 +289,11 @@ impl SimpleAsyncComponent for DownloadComponentsApp { async fn update(&mut self, msg: Self::Input, sender: AsyncComponentSender) { match msg { + DownloadComponentsAppMsg::UpdateVersionsLists => { + self.wine_versions = wine::get_groups(&CONFIG.components.path).unwrap()[0].versions.clone().into_iter().collect(); + self.dxvk_versions = dxvk::get_groups(&CONFIG.components.path).unwrap()[0].versions.clone().into_iter().collect(); + } + #[allow(unused_must_use)] DownloadComponentsAppMsg::DownloadWine => { self.downloading = true; diff --git a/src/ui/first_run/main.rs b/src/ui/first_run/main.rs index dd5e083..71a6285 100644 --- a/src/ui/first_run/main.rs +++ b/src/ui/first_run/main.rs @@ -4,7 +4,10 @@ use relm4::component::*; use gtk::prelude::*; use adw::prelude::*; +use anime_launcher_sdk::components::loader::ComponentsLoader; + use crate::i18n::tr; +use crate::*; use super::welcome::*; use super::tos_warning::*; @@ -30,11 +33,14 @@ pub struct FirstRunApp { toast_overlay: adw::ToastOverlay, carousel: adw::Carousel, + loading: Option>, title: String } #[derive(Debug, Clone)] pub enum FirstRunAppMsg { + SetLoadingStatus(Option>), + ScrollToTosWarning, ScrollToDependencies, ScrollToDefaultPaths, @@ -70,8 +76,26 @@ impl SimpleComponent for FirstRunApp { add_css_class: "flat" }, + adw::StatusPage { + set_title: &tr("loading-data"), + set_icon_name: Some(APP_ID), + set_vexpand: true, + + #[watch] + set_description: match &model.loading { + Some(Some(desc)) => Some(desc), + Some(None) | None => None + }, + + #[watch] + set_visible: model.loading.is_some() + }, + #[local_ref] carousel -> adw::Carousel { + #[watch] + set_visible: model.loading.is_none(), + set_allow_mouse_drag: false, append = model.welcome.widget(), @@ -134,6 +158,7 @@ impl SimpleComponent for FirstRunApp { toast_overlay, carousel, + loading: Some(None), title: tr("welcome") }; @@ -148,6 +173,62 @@ impl SimpleComponent for FirstRunApp { tracing::info!("First run window initialized"); + let components_sender = model.download_components.sender().clone(); + + // Initialize some heavy tasks + #[allow(unused_must_use)] + std::thread::spawn(move || { + tracing::info!("Initializing heavy tasks"); + + // Update components index + + sender.input(FirstRunAppMsg::SetLoadingStatus(Some(Some(tr("updating-components-index"))))); + + let components = ComponentsLoader::new(&CONFIG.components.path); + + match components.is_sync(&CONFIG.components.servers) { + Ok(true) => (), + + Ok(false) => { + for host in &CONFIG.components.servers { + match components.sync(host) { + Ok(true) => break, + Ok(false) => continue, + + Err(err) => { + tracing::error!("Failed to sync components index"); + + sender.input(FirstRunAppMsg::Toast { + title: tr("components-index-sync-failed"), + description: Some(err.to_string()) + }); + } + } + } + } + + Err(err) => { + tracing::error!("Failed to verify that components index synced"); + + sender.input(FirstRunAppMsg::Toast { + title: tr("components-index-verify-failed"), + description: Some(err.to_string()) + }); + } + } + + // Update versions lists in download components page and hide status page + components_sender.send(DownloadComponentsAppMsg::UpdateVersionsLists); + sender.input(FirstRunAppMsg::SetLoadingStatus(None)); + + // Mark app as loaded + unsafe { + crate::READY = true; + } + + tracing::info!("App is ready"); + }); + ComponentParts { model, widgets } // will return soon } @@ -155,6 +236,10 @@ impl SimpleComponent for FirstRunApp { tracing::debug!("Called first run window event: {:?}", msg); match msg { + FirstRunAppMsg::SetLoadingStatus(status) => { + self.loading = status; + } + FirstRunAppMsg::ScrollToTosWarning => { self.title = tr("tos-violation-warning");