feat(core): added dynamic components loading

Now launcher will update its local wine/dxvk versions index from remotes in config file
This commit is contained in:
Observer KRypt0n_ 2023-03-06 12:39:22 +02:00
parent 5f0d6f5c14
commit d69107dfba
6 changed files with 73 additions and 23 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.7" version = "1.3.8"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bzip2", "bzip2",
@ -76,7 +76,7 @@ dependencies = [
[[package]] [[package]]
name = "anime-launcher-sdk" name = "anime-launcher-sdk"
version = "0.2.5" version = "0.3.0"
dependencies = [ dependencies = [
"anime-game-core", "anime-game-core",
"anyhow", "anyhow",

@ -1 +1 @@
Subproject commit 9d6aeff5265999f724ff6caf288007a0756f1415 Subproject commit 42b738dc1ec5be8e6ced48501604622b8d0ab91e

View file

@ -27,7 +27,7 @@ pub struct ComponentsListGroup {
impl From<wine::Group> for ComponentsListGroup { impl From<wine::Group> for ComponentsListGroup {
fn from(group: wine::Group) -> Self { fn from(group: wine::Group) -> Self {
Self { Self {
title: group.name, title: group.title,
versions: group.versions.into_iter().map(|version| version.into()).collect() versions: group.versions.into_iter().map(|version| version.into()).collect()
} }
} }
@ -56,7 +56,7 @@ impl From<wine::Version> for ComponentsListVersion {
name: version.name, name: version.name,
title: version.title, title: version.title,
uri: version.uri, uri: version.uri,
recommended: version.recommended recommended: true // FIXME
} }
} }
} }
@ -67,7 +67,7 @@ impl From<dxvk::Version> for ComponentsListVersion {
name: version.name.clone(), name: version.name.clone(),
title: version.name, title: version.name,
uri: version.uri, uri: version.uri,
recommended: version.recommended recommended: true // FIXME
} }
} }
} }

View file

@ -13,7 +13,7 @@ use std::path::PathBuf;
use super::main::FirstRunAppMsg; use super::main::FirstRunAppMsg;
use crate::ui::components::*; use crate::ui::components::*;
use crate::i18n::*; use crate::i18n::*;
use crate::FIRST_RUN_FILE; use crate::*;
fn get_installer(uri: &str, temp: Option<&PathBuf>, speed_limit: u64) -> anyhow::Result<Installer> { fn get_installer(uri: &str, temp: Option<&PathBuf>, speed_limit: u64) -> anyhow::Result<Installer> {
let mut installer = Installer::new(uri)?; let mut installer = Installer::new(uri)?;
@ -264,8 +264,9 @@ impl SimpleAsyncComponent for DownloadComponentsApp {
wine_combo: adw::ComboRow::new(), wine_combo: adw::ComboRow::new(),
dxvk_combo: adw::ComboRow::new(), dxvk_combo: adw::ComboRow::new(),
wine_versions: wine::get_groups()[0].versions.clone().into_iter().filter(|version| version.recommended).collect(), // FIXME: .filter(|version| version.recommended)
dxvk_versions: dxvk::get_groups()[0].versions.clone().into_iter().filter(|version| version.recommended).collect(), 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(),
downloading_wine: None, downloading_wine: None,
creating_prefix: None, creating_prefix: None,

View file

@ -13,6 +13,7 @@ use gtk::glib::clone;
use anime_launcher_sdk::config::launcher::LauncherStyle; use anime_launcher_sdk::config::launcher::LauncherStyle;
use anime_launcher_sdk::states::LauncherState; use anime_launcher_sdk::states::LauncherState;
use anime_launcher_sdk::wincompatlib::prelude::*; use anime_launcher_sdk::wincompatlib::prelude::*;
use anime_launcher_sdk::components::loader::ComponentsLoader;
use anime_launcher_sdk::components::wine; use anime_launcher_sdk::components::wine;
use std::path::Path; use std::path::Path;
@ -600,6 +601,43 @@ impl SimpleComponent for App {
} }
} }
// Update components index
sender.input(AppMsg::SetLoadingStatus(Some(Some(String::from("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(AppMsg::Toast {
title: String::from("Failed to sync components index"),
description: Some(err.to_string())
});
}
}
}
}
Err(err) => {
tracing::error!("Failed to verify that components index synced");
sender.input(AppMsg::Toast {
title: String::from("Failed to verify components index"),
description: Some(err.to_string())
});
}
}
// Update initial game version status // Update initial game version status
sender.input(AppMsg::SetLoadingStatus(Some(Some(tr("loading-game-version"))))); sender.input(AppMsg::SetLoadingStatus(Some(Some(tr("loading-game-version")))));
@ -1050,16 +1088,17 @@ impl SimpleComponent for App {
LauncherState::WineNotInstalled => { LauncherState::WineNotInstalled => {
let mut config = config::get().unwrap(); let mut config = config::get().unwrap();
match wine::get_downloaded(&config.game.wine.builds) { match wine::get_downloaded(&CONFIG.components.path, &config.game.wine.builds) {
Ok(list) => { Ok(list) => {
if let Some(version) = list.into_iter().find(|version| version.recommended) { // FIXME: .find(|version| version.recommended)
config.game.wine.selected = Some(version.name); if !list.is_empty() {
config.game.wine.selected = Some(list[0].name.clone());
config::update(config.clone()); config::update(config.clone());
} }
if config.game.wine.selected.is_none() { if config.game.wine.selected.is_none() {
let wine = wine::Version::latest(); let wine = wine::Version::latest(&CONFIG.components.path).expect("Failed to get latest wine version");
match Installer::new(wine.uri) { match Installer::new(wine.uri) {
Ok(mut installer) => { Ok(mut installer) => {
@ -1134,12 +1173,13 @@ impl SimpleComponent for App {
LauncherState::PrefixNotExists => { LauncherState::PrefixNotExists => {
let config = config::get().unwrap(); let config = config::get().unwrap();
match config.try_get_wine_executable() { match config.try_get_selected_wine_info() {
Some(wine) => { Ok(Some(wine)) => {
sender.input(AppMsg::DisableButtons(true)); sender.input(AppMsg::DisableButtons(true));
std::thread::spawn(move || { std::thread::spawn(move || {
let wine = Wine::from_binary(wine) let wine = wine
.to_wine(Some(config.game.wine.builds.join(&wine.name)))
.with_loader(WineLoader::Current) .with_loader(WineLoader::Current)
.with_arch(WineArch::Win64); .with_arch(WineArch::Win64);
@ -1160,7 +1200,7 @@ impl SimpleComponent for App {
}); });
} }
None => { Ok(None) => {
tracing::error!("Failed to get selected wine executable"); tracing::error!("Failed to get selected wine executable");
sender.input(AppMsg::Toast { sender.input(AppMsg::Toast {
@ -1168,6 +1208,15 @@ impl SimpleComponent for App {
description: None description: None
}); });
} }
Err(err) => {
tracing::error!("Failed to get selected wine executable: {err}");
sender.input(AppMsg::Toast {
title: tr("failed-get-selected-wine"),
description: Some(err.to_string())
});
}
} }
} }

View file

@ -542,7 +542,7 @@ impl SimpleAsyncComponent for GeneralApp {
.launch(ComponentsListInit { .launch(ComponentsListInit {
pattern: ComponentsListPattern { pattern: ComponentsListPattern {
download_folder: CONFIG.game.wine.builds.clone(), download_folder: CONFIG.game.wine.builds.clone(),
groups: wine::get_groups().into_iter().map(|group| group.into()).collect() groups: wine::get_groups(&CONFIG.components.path).unwrap_or_default().into_iter().map(|group| group.into()).collect()
}, },
on_downloaded: Some(GeneralAppMsg::UpdateDownloadedWine), on_downloaded: Some(GeneralAppMsg::UpdateDownloadedWine),
on_deleted: Some(GeneralAppMsg::UpdateDownloadedWine) on_deleted: Some(GeneralAppMsg::UpdateDownloadedWine)
@ -553,7 +553,7 @@ impl SimpleAsyncComponent for GeneralApp {
.launch(ComponentsListInit { .launch(ComponentsListInit {
pattern: ComponentsListPattern { pattern: ComponentsListPattern {
download_folder: CONFIG.game.dxvk.builds.clone(), download_folder: CONFIG.game.dxvk.builds.clone(),
groups: dxvk::get_groups().into_iter().map(|group| group.into()).collect() groups: dxvk::get_groups(&CONFIG.components.path).unwrap_or_default().into_iter().map(|group| group.into()).collect()
}, },
on_downloaded: Some(GeneralAppMsg::UpdateDownloadedDxvk), on_downloaded: Some(GeneralAppMsg::UpdateDownloadedDxvk),
on_deleted: Some(GeneralAppMsg::UpdateDownloadedDxvk) on_deleted: Some(GeneralAppMsg::UpdateDownloadedDxvk)
@ -701,7 +701,7 @@ impl SimpleAsyncComponent for GeneralApp {
} }
GeneralAppMsg::UpdateDownloadedWine => { GeneralAppMsg::UpdateDownloadedWine => {
self.downloaded_wine_versions = wine::get_downloaded(&CONFIG.game.wine.builds).unwrap_or_default(); self.downloaded_wine_versions = wine::get_downloaded(&CONFIG.components.path, &CONFIG.game.wine.builds).unwrap_or_default();
self.selected_wine_version = if let Some(selected) = &CONFIG.game.wine.selected { self.selected_wine_version = if let Some(selected) = &CONFIG.game.wine.selected {
let mut index = 0; let mut index = 0;
@ -723,7 +723,7 @@ impl SimpleAsyncComponent for GeneralApp {
} }
GeneralAppMsg::UpdateDownloadedDxvk => { GeneralAppMsg::UpdateDownloadedDxvk => {
self.downloaded_dxvk_versions = dxvk::get_downloaded(&CONFIG.game.dxvk.builds).unwrap_or_default(); self.downloaded_dxvk_versions = dxvk::get_downloaded(&CONFIG.components.path, &CONFIG.game.dxvk.builds).unwrap_or_default();
self.selected_dxvk_version = if let Ok(Some(selected)) = CONFIG.try_get_selected_dxvk_info() { self.selected_dxvk_version = if let Ok(Some(selected)) = CONFIG.try_get_selected_dxvk_info() {
let mut index = 0; let mut index = 0;
@ -789,8 +789,8 @@ impl SimpleAsyncComponent for GeneralApp {
self.selecting_dxvk_version = true; self.selecting_dxvk_version = true;
let mut wine = match config.try_get_selected_wine_info() { let mut wine = match config.try_get_selected_wine_info() {
Some(version) => version.to_wine(Some(config.game.wine.builds.join(&version.name))), Ok(Some(version)) => version.to_wine(Some(config.game.wine.builds.join(&version.name))),
None => Wine::default() _ => Wine::default()
}; };
wine = wine.with_prefix(config.game.wine.prefix); wine = wine.with_prefix(config.game.wine.prefix);