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
This commit is contained in:
Observer KRypt0n_ 2023-03-07 13:07:22 +02:00
parent 7f38c15c76
commit 032ca88a6e
4 changed files with 96 additions and 5 deletions

4
Cargo.lock generated
View file

@ -31,7 +31,7 @@ dependencies = [
[[package]] [[package]]
name = "anime-game-core" name = "anime-game-core"
version = "1.3.9" version = "1.3.10"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bzip2", "bzip2",
@ -76,7 +76,7 @@ dependencies = [
[[package]] [[package]]
name = "anime-launcher-sdk" name = "anime-launcher-sdk"
version = "0.3.3" version = "0.3.4"
dependencies = [ dependencies = [
"anime-game-core", "anime-game-core",
"anyhow", "anyhow",

@ -1 +1 @@
Subproject commit 219d0f7704e18d74a9205163ffbb7d1718291ea4 Subproject commit 7bcfdbee8583f046c9df045577bd679ee4eb45c2

View file

@ -61,6 +61,7 @@ pub struct DownloadComponentsApp {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum DownloadComponentsAppMsg { pub enum DownloadComponentsAppMsg {
UpdateVersionsLists,
DownloadWine, DownloadWine,
CreatePrefix, CreatePrefix,
DownloadDXVK, DownloadDXVK,
@ -265,8 +266,8 @@ impl SimpleAsyncComponent for DownloadComponentsApp {
dxvk_combo: adw::ComboRow::new(), dxvk_combo: adw::ComboRow::new(),
// FIXME: .filter(|version| version.recommended) // FIXME: .filter(|version| version.recommended)
wine_versions: wine::get_groups(&CONFIG.components.path).unwrap_or_default()[0].versions.clone().into_iter().collect(), wine_versions: vec![],
dxvk_versions: dxvk::get_groups(&CONFIG.components.path).unwrap_or_default()[0].versions.clone().into_iter().collect(), dxvk_versions: vec![],
downloading_wine: None, downloading_wine: None,
creating_prefix: None, creating_prefix: None,
@ -288,6 +289,11 @@ impl SimpleAsyncComponent for DownloadComponentsApp {
async fn update(&mut self, msg: Self::Input, sender: AsyncComponentSender<Self>) { async fn update(&mut self, msg: Self::Input, sender: AsyncComponentSender<Self>) {
match msg { 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)] #[allow(unused_must_use)]
DownloadComponentsAppMsg::DownloadWine => { DownloadComponentsAppMsg::DownloadWine => {
self.downloading = true; self.downloading = true;

View file

@ -4,7 +4,10 @@ use relm4::component::*;
use gtk::prelude::*; use gtk::prelude::*;
use adw::prelude::*; use adw::prelude::*;
use anime_launcher_sdk::components::loader::ComponentsLoader;
use crate::i18n::tr; use crate::i18n::tr;
use crate::*;
use super::welcome::*; use super::welcome::*;
use super::tos_warning::*; use super::tos_warning::*;
@ -30,11 +33,14 @@ pub struct FirstRunApp {
toast_overlay: adw::ToastOverlay, toast_overlay: adw::ToastOverlay,
carousel: adw::Carousel, carousel: adw::Carousel,
loading: Option<Option<String>>,
title: String title: String
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum FirstRunAppMsg { pub enum FirstRunAppMsg {
SetLoadingStatus(Option<Option<String>>),
ScrollToTosWarning, ScrollToTosWarning,
ScrollToDependencies, ScrollToDependencies,
ScrollToDefaultPaths, ScrollToDefaultPaths,
@ -70,8 +76,26 @@ impl SimpleComponent for FirstRunApp {
add_css_class: "flat" 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] #[local_ref]
carousel -> adw::Carousel { carousel -> adw::Carousel {
#[watch]
set_visible: model.loading.is_none(),
set_allow_mouse_drag: false, set_allow_mouse_drag: false,
append = model.welcome.widget(), append = model.welcome.widget(),
@ -134,6 +158,7 @@ impl SimpleComponent for FirstRunApp {
toast_overlay, toast_overlay,
carousel, carousel,
loading: Some(None),
title: tr("welcome") title: tr("welcome")
}; };
@ -148,6 +173,62 @@ impl SimpleComponent for FirstRunApp {
tracing::info!("First run window initialized"); 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 ComponentParts { model, widgets } // will return soon
} }
@ -155,6 +236,10 @@ impl SimpleComponent for FirstRunApp {
tracing::debug!("Called first run window event: {:?}", msg); tracing::debug!("Called first run window event: {:?}", msg);
match msg { match msg {
FirstRunAppMsg::SetLoadingStatus(status) => {
self.loading = status;
}
FirstRunAppMsg::ScrollToTosWarning => { FirstRunAppMsg::ScrollToTosWarning => {
self.title = tr("tos-violation-warning"); self.title = tr("tos-violation-warning");