feat(core): initial core/sdk migration patch set

This commit is contained in:
Observer KRypt0n_ 2023-04-15 12:36:03 +02:00
parent 4ab8a6cc8d
commit 4eed994648
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
20 changed files with 185 additions and 171 deletions

2
Cargo.lock generated
View file

@ -41,7 +41,6 @@ dependencies = [
[[package]]
name = "anime-game-core"
version = "1.6.2"
source = "git+https://github.com/an-anime-team/anime-game-core?tag=1.6.2#f41c0edbf6d830662b20a220987531bb517cf8cb"
dependencies = [
"anyhow",
"bzip2",
@ -87,7 +86,6 @@ dependencies = [
[[package]]
name = "anime-launcher-sdk"
version = "0.5.17"
source = "git+https://github.com/an-anime-team/anime-launcher-sdk?tag=0.5.17#5b4403956feaca7204f057a26f06e69b7fc1b285"
dependencies = [
"anime-game-core",
"anyhow",

View file

@ -16,10 +16,11 @@ opt-level = "s"
glib-build-tools = "0.17"
[dependencies.anime-launcher-sdk]
git = "https://github.com/an-anime-team/anime-launcher-sdk"
tag = "0.5.17"
# git = "https://github.com/an-anime-team/anime-launcher-sdk"
# tag = "0.5.17"
features = ["all", "genshin"]
# path = "../anime-launcher-sdk" # ! for dev purposes only
path = "../anime-launcher-sdk" # ! for dev purposes only
[dependencies]
relm4 = { version = "0.6.0-alpha.2", features = ["macros", "libadwaita"] }

View file

@ -1,8 +1,10 @@
use relm4::prelude::*;
use anime_launcher_sdk::config;
use anime_launcher_sdk::states::LauncherState;
use anime_launcher_sdk::consts::launcher_dir;
use anime_launcher_sdk::config::ConfigExt;
use anime_launcher_sdk::genshin::config::{Config, Schema};
use anime_launcher_sdk::genshin::states::LauncherState;
use anime_launcher_sdk::genshin::consts::launcher_dir;
use anime_launcher_sdk::anime_game_core::prelude::*;
use anime_launcher_sdk::anime_game_core::genshin::prelude::*;
@ -34,9 +36,9 @@ pub fn is_ready() -> bool {
}
lazy_static::lazy_static! {
/// Config loaded on the app's start. Use `config::get()` to get up to date config instead.
/// Config loaded on the app's start. Use `Config::get()` to get up to date config instead.
/// This one is used to prepare some launcher UI components on start
pub static ref CONFIG: config::Config = config::get().expect("Failed to load config");
pub static ref CONFIG: Schema = Config::get().expect("Failed to load config");
pub static ref GAME: Game = Game::new(CONFIG.game.path.for_edition(CONFIG.launcher.edition));
@ -69,11 +71,11 @@ fn main() {
std::fs::write(FIRST_RUN_FILE.as_path(), "").expect("Failed to create .first-run file");
// Set initial launcher language based on system language
let mut config = config::get().expect("Failed to get config");
let mut config = Config::get().expect("Failed to get config");
config.launcher.language = i18n::format_lang(&i18n::get_default_lang());
config::update_raw(config).expect("Failed to update config");
Config::update_raw(config).expect("Failed to update config");
}
// Force debug output
@ -161,7 +163,7 @@ fn main() {
", BACKGROUND_FILE.to_string_lossy()));
// Set game edition
GameEdition::from(CONFIG.launcher.edition).select();
CONFIG.launcher.edition.select();
// Set UI language
let lang = CONFIG.launcher.language.parse().expect("Wrong language format used in config");
@ -187,7 +189,7 @@ fn main() {
match state {
LauncherState::Launch => {
anime_launcher_sdk::game::run().expect("Failed to run the game");
anime_launcher_sdk::genshin::game::run().expect("Failed to run the game");
return;
}
@ -196,7 +198,7 @@ fn main() {
LauncherState::UnityPlayerPatchAvailable(UnityPlayerPatch { status: PatchStatus::NotAvailable, .. }) |
LauncherState::XluaPatchAvailable(XluaPatch { status: PatchStatus::NotAvailable, .. }) => {
if just_run_game {
anime_launcher_sdk::game::run().expect("Failed to run the game");
anime_launcher_sdk::genshin::game::run().expect("Failed to run the game");
return;
}

View file

@ -6,13 +6,15 @@ use adw::prelude::*;
use gtk::glib::clone;
use super::progress_bar::ProgressBarMsg;
use anime_launcher_sdk::config;
use anime_launcher_sdk::anime_game_core::prelude::*;
use anime_launcher_sdk::config::ConfigExt;
use anime_launcher_sdk::genshin::config::Config;
use std::path::PathBuf;
use super::progress_bar::ProgressBarMsg;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum VersionState {
Downloaded,
@ -142,7 +144,7 @@ impl SimpleAsyncComponent for ComponentVersion {
}
VersionState::NotDownloaded => {
if let Ok(config) = config::get() {
if let Ok(config) = Config::get() {
// todo
let mut installer = Installer::new(&self.download_uri)
.expect("Failed to create installer instance for this version");

View file

@ -3,8 +3,6 @@ use relm4::component::*;
use adw::prelude::*;
use anime_launcher_sdk::config;
use std::path::PathBuf;
use crate::*;
@ -360,7 +358,7 @@ impl SimpleAsyncComponent for DefaultPathsApp {
#[allow(unused_must_use)]
DefaultPathsAppMsg::Continue => {
let old_config = config::get().unwrap_or_else(|_| CONFIG.clone());
let old_config = Config::get().unwrap_or_else(|_| CONFIG.clone());
match self.update_config() {
Ok(_) => {
@ -431,7 +429,7 @@ impl SimpleAsyncComponent for DefaultPathsApp {
impl DefaultPathsApp {
pub fn update_config(&self) -> anyhow::Result<()> {
let mut config = config::get()?;
let mut config = Config::get()?;
config.game.wine.builds = self.runners.clone();
config.game.dxvk.builds = self.dxvks.clone();
@ -444,6 +442,6 @@ impl DefaultPathsApp {
config.game.enhancements.fps_unlocker.path = self.fps_unlocker.clone();
config::update_raw(config)
Config::update_raw(config)
}
}

View file

@ -4,10 +4,13 @@ use relm4::component::*;
use adw::prelude::*;
use anime_launcher_sdk::anime_game_core::prelude::*;
use anime_launcher_sdk::wincompatlib::prelude::*;
use anime_launcher_sdk::components::*;
use anime_launcher_sdk::components::wine::WincompatlibWine;
use anime_launcher_sdk::config;
use anime_launcher_sdk::wincompatlib::prelude::*;
use anime_launcher_sdk::config::ConfigExt;
use anime_launcher_sdk::genshin::config::Config;
use std::path::PathBuf;
@ -312,7 +315,7 @@ impl SimpleAsyncComponent for DownloadComponentsApp {
async fn update(&mut self, msg: Self::Input, sender: AsyncComponentSender<Self>) {
match msg {
DownloadComponentsAppMsg::UpdateVersionsLists => {
let config = config::get().unwrap_or_else(|_| CONFIG.clone());
let config = Config::get().unwrap_or_else(|_| CONFIG.clone());
// 4 latest versions of 4 first available wine group
self.wine_versions = wine::get_groups(&config.components.path).unwrap()
@ -331,7 +334,7 @@ impl SimpleAsyncComponent for DownloadComponentsApp {
#[allow(unused_must_use)]
DownloadComponentsAppMsg::DownloadWine => {
let config = config::get().unwrap_or_else(|_| CONFIG.clone());
let config = Config::get().unwrap_or_else(|_| CONFIG.clone());
self.selected_wine = Some(self.wine_versions[self.wine_combo.selected() as usize].clone());
self.selected_dxvk = Some(self.dxvk_versions[self.dxvk_combo.selected() as usize].clone());
@ -350,11 +353,11 @@ impl SimpleAsyncComponent for DownloadComponentsApp {
if wine.is_downloaded_in(&config.game.wine.builds) {
tracing::info!("Wine already installed: {}", wine.name);
let mut config = config::get().unwrap_or_else(|_| CONFIG.clone());
let mut config = Config::get().unwrap_or_else(|_| CONFIG.clone());
config.game.wine.selected = Some(wine.name);
if let Err(err) = config::update_raw(config) {
if let Err(err) = Config::update_raw(config) {
tracing::error!("Failed to update config: {err}");
sender.output(Self::Output::Toast {
@ -402,11 +405,11 @@ impl SimpleAsyncComponent for DownloadComponentsApp {
// Create prefix
InstallerUpdate::UnpackingFinished => {
let mut config = config::get().unwrap_or_else(|_| CONFIG.clone());
let mut config = Config::get().unwrap_or_else(|_| CONFIG.clone());
config.game.wine.selected = Some(wine.name.clone());
if let Err(err) = config::update_raw(config) {
if let Err(err) = Config::update_raw(config) {
tracing::error!("Failed to update config: {err}");
sender.output(Self::Output::Toast {
@ -443,7 +446,7 @@ impl SimpleAsyncComponent for DownloadComponentsApp {
self.downloading_wine = Some(true);
self.creating_prefix = Some(false);
let config = config::get().unwrap_or_else(|_| CONFIG.clone());
let config = Config::get().unwrap_or_else(|_| CONFIG.clone());
tracing::info!("Creating wine prefix");
@ -477,7 +480,7 @@ impl SimpleAsyncComponent for DownloadComponentsApp {
self.creating_prefix = Some(true);
self.downloading_dxvk = Some(false);
let config = config::get().unwrap_or_else(|_| CONFIG.clone());
let config = Config::get().unwrap_or_else(|_| CONFIG.clone());
let dxvk = self.selected_dxvk.clone().unwrap();
let progress_bar_input = self.progress_bar.sender().clone();
@ -554,7 +557,7 @@ impl SimpleAsyncComponent for DownloadComponentsApp {
self.downloading_dxvk = Some(true);
self.applying_dxvk = Some(false);
let config = config::get().unwrap_or_else(|_| CONFIG.clone());
let config = Config::get().unwrap_or_else(|_| CONFIG.clone());
tracing::info!("Applying DXVK");

View file

@ -219,7 +219,7 @@ impl SimpleComponent for FirstRunApp {
// Update components index
sender.input(FirstRunAppMsg::SetLoadingStatus(Some(Some(tr("updating-components-index")))));
let config = config::get().unwrap_or_else(|_| CONFIG.clone());
let config = Config::get().unwrap_or_else(|_| CONFIG.clone());
let components_sender = self.download_components.sender().clone();
let components = ComponentsLoader::new(config.components.path);

View file

@ -3,7 +3,8 @@ use relm4::component::*;
use adw::prelude::*;
use anime_launcher_sdk::config;
use anime_launcher_sdk::config::ConfigExt;
use anime_launcher_sdk::genshin::config::Config;
use crate::i18n::*;
use super::main::*;
@ -153,7 +154,7 @@ impl SimpleAsyncComponent for SelectVoiceoversApp {
impl SelectVoiceoversApp {
pub fn update_config(&self) -> anyhow::Result<()> {
let mut config = config::get()?;
let mut config = Config::get()?;
config.game.voices = Vec::new();
@ -173,6 +174,6 @@ impl SelectVoiceoversApp {
config.game.voices.push(String::from("zh-cn"));
}
config::update_raw(config)
Config::update_raw(config)
}
}

View file

@ -1,7 +1,5 @@
use relm4::prelude::*;
use anime_launcher_sdk::config;
use crate::*;
use crate::i18n::*;
use super::{App, AppMsg};
@ -16,7 +14,7 @@ pub fn apply_patch<T: PatchExt + Send + Sync + 'static>(sender: ComponentSender<
PatchStatus::Available { .. } => {
sender.input(AppMsg::DisableButtons(true));
let config = config::get().unwrap();
let config = Config::get().unwrap();
std::thread::spawn(move || {
let mut apply_patch_if_needed = true;

View file

@ -1,13 +1,15 @@
use relm4::prelude::*;
use anime_launcher_sdk::config;
use anime_launcher_sdk::wincompatlib::prelude::*;
use anime_launcher_sdk::config::ConfigExt;
use anime_launcher_sdk::genshin::config::Config;
use crate::i18n::*;
use super::{App, AppMsg};
pub fn create_prefix(sender: ComponentSender<App>) {
let config = config::get().unwrap();
let config = Config::get().unwrap();
match config.get_selected_wine() {
Ok(Some(wine)) => {

View file

@ -5,7 +5,6 @@ use relm4::{
use gtk::glib::clone;
use anime_launcher_sdk::config;
use anime_launcher_sdk::anime_game_core::installer::diff::VersionDiff;
use crate::*;
@ -17,7 +16,7 @@ pub fn download_diff(sender: ComponentSender<App>, progress_bar_input: Sender<Pr
sender.input(AppMsg::SetDownloading(true));
std::thread::spawn(move || {
let config = config::get().unwrap();
let config = Config::get().unwrap();
let game_path = config.game.path.for_edition(config.launcher.edition).to_path_buf();
let result = diff.install_to_by(game_path, config.launcher.temp, clone!(@strong sender => move |state| {

View file

@ -5,7 +5,6 @@ use relm4::{
use gtk::glib::clone;
use anime_launcher_sdk::config;
use anime_launcher_sdk::components::wine;
use crate::*;
@ -14,7 +13,7 @@ use crate::ui::components::*;
use super::{App, AppMsg};
pub fn download_wine(sender: ComponentSender<App>, progress_bar_input: Sender<ProgressBarMsg>) {
let mut config = config::get().unwrap();
let mut config = Config::get().unwrap();
match wine::get_downloaded(&CONFIG.components.path, &config.game.wine.builds) {
Ok(downloaded) => {
@ -22,7 +21,7 @@ pub fn download_wine(sender: ComponentSender<App>, progress_bar_input: Sender<Pr
if !downloaded.is_empty() {
config.game.wine.selected = Some(downloaded[0].versions[0].name.clone());
config::update(config);
Config::update(config);
sender.input(AppMsg::UpdateLauncherState {
perform_on_download_needed: false,
@ -85,7 +84,7 @@ pub fn download_wine(sender: ComponentSender<App>, progress_bar_input: Sender<Pr
config.game.wine.selected = Some(wine.name.clone());
config::update(config);
Config::update(config);
sender.input(AppMsg::SetDownloading(false));
sender.input(AppMsg::UpdateLauncherState {

View file

@ -7,7 +7,7 @@ pub fn launch(sender: ComponentSender<App>) {
sender.input(AppMsg::HideWindow);
std::thread::spawn(move || {
if let Err(err) = anime_launcher_sdk::game::run() {
if let Err(err) = anime_launcher_sdk::genshin::game::run() {
tracing::error!("Failed to launch game: {err}");
sender.input(AppMsg::Toast {

View file

@ -18,10 +18,15 @@ mod download_diff;
mod migrate_folder;
mod launch;
use anime_launcher_sdk::config::launcher::LauncherStyle;
use anime_launcher_sdk::states::LauncherState;
use anime_launcher_sdk::components::loader::ComponentsLoader;
use anime_launcher_sdk::anime_game_core::genshin::consts::GameEdition;
use anime_launcher_sdk::config::ConfigExt;
use anime_launcher_sdk::genshin::config::Config;
use anime_launcher_sdk::genshin::config::schema::launcher::LauncherStyle;
use anime_launcher_sdk::genshin::states::*;
use anime_launcher_sdk::genshin::consts::*;
use crate::*;
use crate::i18n::*;
@ -328,7 +333,7 @@ impl SimpleComponent for App {
#[watch]
set_sensitive: match model.state.as_ref() {
Some(LauncherState::PredownloadAvailable { game, voices }) => {
let config = config::get().unwrap();
let config = Config::get().unwrap();
let temp = config.launcher.temp.unwrap_or_else(std::env::temp_dir);
let downloaded = temp.join(game.file_name().unwrap()).exists() &&
@ -343,7 +348,7 @@ impl SimpleComponent for App {
#[watch]
set_css_classes: match model.state.as_ref() {
Some(LauncherState::PredownloadAvailable { game, voices }) => {
let config = config::get().unwrap();
let config = Config::get().unwrap();
let temp = config.launcher.temp.unwrap_or_else(std::env::temp_dir);
let downloaded = temp.join(game.file_name().unwrap()).exists() &&
@ -481,7 +486,7 @@ impl SimpleComponent for App {
},
connect_close_request[sender] => move |_| {
if let Err(err) = config::flush() {
if let Err(err) = Config::flush() {
sender.input(AppMsg::Toast {
title: tr("config-update-error"),
description: Some(err.to_string())
@ -558,7 +563,7 @@ impl SimpleComponent for App {
})));
group.add_action::<GameFolder>(&RelmAction::new_stateless(clone!(@strong sender => move |_| {
let path = match config::get() {
let path = match Config::get() {
Ok(config) => config.game.path.for_edition(config.launcher.edition).to_path_buf(),
Err(_) => CONFIG.game.path.for_edition(CONFIG.launcher.edition).to_path_buf(),
};
@ -574,7 +579,7 @@ impl SimpleComponent for App {
})));
group.add_action::<ConfigFile>(&RelmAction::new_stateless(clone!(@strong sender => move |_| {
if let Ok(file) = anime_launcher_sdk::consts::config_file() {
if let Ok(file) = config_file() {
if let Err(err) = open::that(file) {
sender.input(AppMsg::Toast {
title: tr("config-file-opening-error"),
@ -599,10 +604,10 @@ impl SimpleComponent for App {
group.add_action::<WishUrl>(&RelmAction::new_stateless(clone!(@strong sender => move |_| {
std::thread::spawn(clone!(@strong sender => move || {
let config = config::get().unwrap_or_else(|_| CONFIG.clone());
let config = Config::get().unwrap_or_else(|_| CONFIG.clone());
let web_cache = config.game.path.for_edition(config.launcher.edition)
.join(GameEdition::from(config.launcher.edition).data_folder())
.join(config.launcher.edition.data_folder())
.join("webCaches/Cache/Cache_Data/data_2");
if !web_cache.exists() {
@ -860,8 +865,6 @@ impl SimpleComponent for App {
}
let updater = clone!(@strong sender => move |state| {
use anime_launcher_sdk::states::StateUpdating;
if show_status_page {
match state {
StateUpdating::Game => {
@ -963,7 +966,7 @@ impl SimpleComponent for App {
#[allow(unused_must_use)]
AppMsg::PredownloadUpdate => {
if let Some(LauncherState::PredownloadAvailable { game, mut voices }) = self.state.clone() {
let tmp = config::get().unwrap().launcher.temp.unwrap_or_else(std::env::temp_dir);
let tmp = Config::get().unwrap().launcher.temp.unwrap_or_else(std::env::temp_dir);
self.downloading = true;

View file

@ -7,8 +7,6 @@ use gtk::glib::clone;
use std::path::Path;
use anime_launcher_sdk::config;
use crate::*;
use crate::i18n::*;
use crate::ui::components::*;
@ -16,7 +14,7 @@ use super::{App, AppMsg};
#[allow(unused_must_use)]
pub fn repair_game(sender: ComponentSender<App>, progress_bar_input: Sender<ProgressBarMsg>) {
let config = config::get().unwrap();
let config = Config::get().unwrap();
progress_bar_input.send(ProgressBarMsg::UpdateCaption(Some(tr("verifying-files"))));
sender.input(AppMsg::SetDownloading(true));

View file

@ -3,8 +3,11 @@ use relm4::component::*;
use adw::prelude::*;
use anime_launcher_sdk::config;
use anime_launcher_sdk::config::prelude::*;
use anime_launcher_sdk::config::ConfigExt;
use anime_launcher_sdk::genshin::config::Config;
use anime_launcher_sdk::config::schema_blanks::prelude::*;
use anime_launcher_sdk::is_available;
use crate::i18n::tr;
@ -52,10 +55,10 @@ impl SimpleAsyncComponent for EnhancementsApp {
connect_selected_notify => |row| unsafe {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.wine.sync = WineSync::from_ordinal_unsafe(row.selected() as i8);
config::update(config);
Config::update(config);
}
}
}
@ -84,10 +87,10 @@ impl SimpleAsyncComponent for EnhancementsApp {
connect_selected_notify => |row| unsafe {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.wine.language = WineLang::from_ordinal_unsafe(row.selected() as i8);
config::update(config);
Config::update(config);
}
}
}
@ -103,10 +106,10 @@ impl SimpleAsyncComponent for EnhancementsApp {
connect_state_notify => |switch| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.wine.borderless = switch.state();
config::update(config);
Config::update(config);
}
}
}
@ -130,13 +133,13 @@ impl SimpleAsyncComponent for EnhancementsApp {
connect_selected_notify => |row| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
let (width, height) = Resolution::try_from(row.selected()).unwrap().get_pair();
config.game.wine.virtual_desktop.width = width;
config.game.wine.virtual_desktop.height = height;
config::update(config);
Config::update(config);
}
}
},
@ -148,10 +151,10 @@ impl SimpleAsyncComponent for EnhancementsApp {
connect_state_notify => |switch| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.wine.virtual_desktop.enabled = switch.state();
config::update(config);
Config::update(config);
}
}
}
@ -176,10 +179,10 @@ impl SimpleAsyncComponent for EnhancementsApp {
connect_selected_notify => |row| unsafe {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.enhancements.hud = HUD::from_ordinal_unsafe(row.selected() as i8);
config::update(config);
Config::update(config);
}
}
}
@ -209,10 +212,10 @@ impl SimpleAsyncComponent for EnhancementsApp {
connect_selected_notify => |row| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.enhancements.fsr.strength = 5 - row.selected() as u64;
config::update(config);
Config::update(config);
}
}
},
@ -224,10 +227,10 @@ impl SimpleAsyncComponent for EnhancementsApp {
connect_state_notify => |switch| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.enhancements.fsr.enabled = switch.state();
config::update(config);
Config::update(config);
}
}
}
@ -247,10 +250,10 @@ impl SimpleAsyncComponent for EnhancementsApp {
connect_state_notify => |switch| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.enhancements.gamemode = switch.state();
config::update(config);
Config::update(config);
}
}
}
@ -279,10 +282,10 @@ impl SimpleAsyncComponent for EnhancementsApp {
connect_state_notify => |switch| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.enhancements.gamescope.enabled = switch.state();
config::update(config);
Config::update(config);
}
}
}
@ -303,10 +306,10 @@ impl SimpleAsyncComponent for EnhancementsApp {
connect_state_notify => |switch| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.launcher.discord_rpc.enabled = switch.state();
config::update(config);
Config::update(config);
}
}
}
@ -319,10 +322,10 @@ impl SimpleAsyncComponent for EnhancementsApp {
connect_changed: |row| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.launcher.discord_rpc.title = row.text().to_string();
config::update(config);
Config::update(config);
}
}
}
@ -334,10 +337,10 @@ impl SimpleAsyncComponent for EnhancementsApp {
connect_changed: |row| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.launcher.discord_rpc.subtitle = row.text().to_string();
config::update(config);
Config::update(config);
}
}
}
@ -363,7 +366,7 @@ impl SimpleAsyncComponent for EnhancementsApp {
&tr("custom")
]),
set_selected: match Fps::from_num(CONFIG.game.enhancements.fps_unlocker.config.fps) {
set_selected: match Fps::from_num(CONFIG.game.enhancements.fps_unlocker.config.fps.to_num()) {
Fps::Ninety => 0,
Fps::HundredTwenty => 1,
Fps::HundredFourtyFour => 2,
@ -377,10 +380,10 @@ impl SimpleAsyncComponent for EnhancementsApp {
connect_selected_notify => |row| {
if is_ready() && row.selected() < Fps::list().len() as u32 - 1 {
if let Ok(mut config) = config::get() {
config.game.enhancements.fps_unlocker.config.fps = Fps::list()[row.selected() as usize].to_num();
if let Ok(mut config) = Config::get() {
config.game.enhancements.fps_unlocker.config.fps = Fps::list()[row.selected() as usize];
config::update(config);
Config::update(config);
}
}
},
@ -392,10 +395,10 @@ impl SimpleAsyncComponent for EnhancementsApp {
connect_state_notify => |switch| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.enhancements.fps_unlocker.enabled = switch.state();
config::update(config);
Config::update(config);
}
}
}
@ -413,10 +416,10 @@ impl SimpleAsyncComponent for EnhancementsApp {
connect_state_notify => |switch| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.enhancements.fps_unlocker.config.power_saving = switch.state();
config::update(config);
Config::update(config);
}
}
}
@ -435,10 +438,10 @@ impl SimpleAsyncComponent for EnhancementsApp {
connect_changed => |row| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.enhancements.fps_unlocker.config.monitor = row.value() as u64;
config::update(config);
Config::update(config);
}
}
}
@ -459,10 +462,10 @@ impl SimpleAsyncComponent for EnhancementsApp {
connect_selected_notify => |row| unsafe {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.enhancements.fps_unlocker.config.window_mode = WindowMode::from_ordinal_unsafe(row.selected() as i8);
config::update(config);
Config::update(config);
}
}
}
@ -486,10 +489,10 @@ impl SimpleAsyncComponent for EnhancementsApp {
connect_selected_notify => |row| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.enhancements.fps_unlocker.config.priority = row.selected() as u64;
config::update(config);
Config::update(config);
}
}
}

View file

@ -4,8 +4,6 @@ use relm4::factory::*;
use adw::prelude::*;
use anime_launcher_sdk::config;
use crate::i18n::tr;
use crate::*;
@ -94,7 +92,7 @@ impl SimpleAsyncComponent for EnvironmentApp {
set_text: CONFIG.game.command.as_ref().unwrap_or(&String::new()).trim(),
connect_changed => |entry| {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
let command = entry.text().trim().to_string();
config.game.command = if command.is_empty() {
@ -103,7 +101,7 @@ impl SimpleAsyncComponent for EnvironmentApp {
Some(command)
};
config::update(config);
Config::update(config);
}
}
}
@ -174,24 +172,24 @@ impl SimpleAsyncComponent for EnvironmentApp {
async fn update(&mut self, msg: Self::Input, _sender: AsyncComponentSender<Self>) {
match msg {
EnvironmentMsg::Add => {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
let name = self.name.text().trim().to_string();
let value = self.value.text().trim().to_string();
config.game.environment.insert(name.clone(), value.clone());
config::update(config);
Config::update(config);
self.variables.guard().push_back((name, value));
}
}
EnvironmentMsg::Remove(index) => {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
if let Some(var) = self.variables.guard().get(index.current_index()) {
config.game.environment.remove(&var.key);
config::update(config);
Config::update(config);
}
self.variables.guard().remove(index.current_index());

View file

@ -3,8 +3,10 @@ use relm4::component::*;
use adw::prelude::*;
use anime_launcher_sdk::config;
use anime_launcher_sdk::config::prelude::*;
use anime_launcher_sdk::config::ConfigExt;
use anime_launcher_sdk::genshin::config::Config;
use anime_launcher_sdk::config::schema_blanks::prelude::*;
use crate::i18n::tr;
use crate::*;
@ -43,10 +45,10 @@ impl SimpleAsyncComponent for GamescopeApp {
connect_changed => |row| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.enhancements.gamescope.game.width = row.text().parse().unwrap_or_default();
config::update(config);
Config::update(config);
}
}
}
@ -64,10 +66,10 @@ impl SimpleAsyncComponent for GamescopeApp {
connect_changed => |row| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.enhancements.gamescope.game.height = row.text().parse().unwrap_or_default();
config::update(config);
Config::update(config);
}
}
}
@ -89,10 +91,10 @@ impl SimpleAsyncComponent for GamescopeApp {
connect_changed => |row| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.enhancements.gamescope.gamescope.width = row.text().parse().unwrap_or_default();
config::update(config);
Config::update(config);
}
}
}
@ -110,10 +112,10 @@ impl SimpleAsyncComponent for GamescopeApp {
connect_changed => |row| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.enhancements.gamescope.gamescope.height = row.text().parse().unwrap_or_default();
config::update(config);
Config::update(config);
}
}
}
@ -133,10 +135,10 @@ impl SimpleAsyncComponent for GamescopeApp {
connect_state_notify => |switch| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.enhancements.gamescope.integer_scaling = switch.state();
config::update(config);
Config::update(config);
}
}
}
@ -153,10 +155,10 @@ impl SimpleAsyncComponent for GamescopeApp {
connect_state_notify => |switch| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.enhancements.gamescope.fsr = switch.state();
config::update(config);
Config::update(config);
}
}
}
@ -173,10 +175,10 @@ impl SimpleAsyncComponent for GamescopeApp {
connect_state_notify => |switch| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.enhancements.gamescope.nis = switch.state();
config::update(config);
Config::update(config);
}
}
}
@ -201,10 +203,10 @@ impl SimpleAsyncComponent for GamescopeApp {
connect_changed => |row| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.enhancements.gamescope.framerate.focused = row.text().parse().unwrap_or_default();
config::update(config);
Config::update(config);
}
}
}
@ -222,10 +224,10 @@ impl SimpleAsyncComponent for GamescopeApp {
connect_changed => |row| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.enhancements.gamescope.framerate.unfocused = row.text().parse().unwrap_or_default();
config::update(config);
Config::update(config);
}
}
}
@ -244,10 +246,10 @@ impl SimpleAsyncComponent for GamescopeApp {
connect_selected_notify => |row| unsafe {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.game.enhancements.gamescope.window_type = WindowType::from_ordinal_unsafe(row.selected() as i8);
config::update(config);
Config::update(config);
}
}
}

View file

@ -10,14 +10,18 @@ use gtk::prelude::*;
use adw::prelude::*;
use anime_launcher_sdk::anime_game_core::prelude::*;
use anime_launcher_sdk::anime_game_core::genshin::consts::GameEdition;
use anime_launcher_sdk::wincompatlib::prelude::*;
use anime_launcher_sdk::config;
use anime_launcher_sdk::config::launcher::LauncherStyle;
use anime_launcher_sdk::components::*;
use anime_launcher_sdk::components::wine::WincompatlibWine;
use anime_launcher_sdk::env_emulation::Environment;
use anime_launcher_sdk::config::launcher::GameEdition;
use anime_launcher_sdk::anime_game_core::genshin::consts::GameEdition as CoreGameEdition;
use anime_launcher_sdk::config::ConfigExt;
use anime_launcher_sdk::genshin::config::Config;
use anime_launcher_sdk::genshin::config::schema::launcher::LauncherStyle;
use anime_launcher_sdk::genshin::env_emulation::Environment;
use super::main::PreferencesAppMsg;
use crate::ui::migrate_installation::MigrateInstallationApp;
@ -291,12 +295,12 @@ impl SimpleAsyncComponent for GeneralApp {
connect_selected_notify => |row| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.launcher.language = crate::i18n::format_lang(SUPPORTED_LANGUAGES
.get(row.selected() as usize)
.unwrap_or(&SUPPORTED_LANGUAGES[0]));
config::update(config);
Config::update(config);
}
}
}
@ -318,7 +322,7 @@ impl SimpleAsyncComponent for GeneralApp {
connect_selected_notify[sender] => move |row| {
if is_ready() {
#[allow(unused_must_use)]
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.launcher.edition = match row.selected() {
0 => GameEdition::Global,
1 => GameEdition::China,
@ -327,9 +331,9 @@ impl SimpleAsyncComponent for GeneralApp {
};
// Select new game edition
CoreGameEdition::from(config.launcher.edition).select();
config.launcher.edition.select();
config::update(config);
Config::update(config);
sender.output(PreferencesAppMsg::UpdateLauncherState);
}
@ -355,7 +359,7 @@ impl SimpleAsyncComponent for GeneralApp {
connect_selected_notify => |row| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.launcher.environment = match row.selected() {
0 => Environment::PC,
1 => Environment::Android,
@ -363,7 +367,7 @@ impl SimpleAsyncComponent for GeneralApp {
_ => unreachable!()
};
config::update(config);
Config::update(config);
}
}
}
@ -478,7 +482,7 @@ impl SimpleAsyncComponent for GeneralApp {
PatchStatus::Preparation { .. } |
PatchStatus::Testing { .. } => &["warning"],
PatchStatus::Available { .. } => unsafe {
let path = match config::get() {
let path = match Config::get() {
Ok(config) => config.game.path.for_edition(config.launcher.edition).to_path_buf(),
Err(_) => CONFIG.game.path.for_edition(CONFIG.launcher.edition).to_path_buf(),
};
@ -505,7 +509,7 @@ impl SimpleAsyncComponent for GeneralApp {
PatchStatus::Preparation { .. } => tr("patch-preparation-tooltip"),
PatchStatus::Testing { .. } => tr("patch-testing-tooltip"),
PatchStatus::Available { .. } => unsafe {
let path = match config::get() {
let path = match Config::get() {
Ok(config) => config.game.path.for_edition(config.launcher.edition).to_path_buf(),
Err(_) => CONFIG.game.path.for_edition(CONFIG.launcher.edition).to_path_buf(),
};
@ -549,7 +553,7 @@ impl SimpleAsyncComponent for GeneralApp {
PatchStatus::Preparation { .. } |
PatchStatus::Testing { .. } => &["warning"],
PatchStatus::Available { .. } => unsafe {
let path = match config::get() {
let path = match Config::get() {
Ok(config) => config.game.path.for_edition(config.launcher.edition).to_path_buf(),
Err(_) => CONFIG.game.path.for_edition(CONFIG.launcher.edition).to_path_buf(),
};
@ -576,7 +580,7 @@ impl SimpleAsyncComponent for GeneralApp {
PatchStatus::Preparation { .. } => tr("patch-preparation-tooltip"),
PatchStatus::Testing { .. } => tr("patch-testing-tooltip"),
PatchStatus::Available { .. } => unsafe {
let path = match config::get() {
let path = match Config::get() {
Ok(config) => config.game.path.for_edition(config.launcher.edition).to_path_buf(),
Err(_) => CONFIG.game.path.for_edition(CONFIG.launcher.edition).to_path_buf(),
};
@ -607,10 +611,10 @@ impl SimpleAsyncComponent for GeneralApp {
connect_state_notify[sender] => move |switch| {
if is_ready() {
#[allow(unused_must_use)]
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.patch.apply_xlua = switch.state();
config::update(config);
Config::update(config);
sender.output(PreferencesAppMsg::UpdateLauncherState);
}
@ -630,10 +634,10 @@ impl SimpleAsyncComponent for GeneralApp {
connect_state_notify => |switch| {
if is_ready() {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.patch.root = switch.state();
config::update(config);
Config::update(config);
}
}
}
@ -951,11 +955,11 @@ impl SimpleAsyncComponent for GeneralApp {
#[allow(unused_must_use)]
GeneralAppMsg::AddVoicePackage(index) => {
if let Some(package) = self.voice_packages.get(index.current_index()) {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
if !config.game.voices.iter().any(|voice| VoiceLocale::from_str(voice) == Some(package.locale)) {
config.game.voices.push(package.locale.to_code().to_string());
config::update(config);
Config::update(config);
sender.output(PreferencesAppMsg::UpdateLauncherState);
}
@ -966,12 +970,12 @@ impl SimpleAsyncComponent for GeneralApp {
#[allow(unused_must_use)]
GeneralAppMsg::RemoveVoicePackage(index) => {
if let Some(package) = self.voice_packages.guard().get_mut(index.current_index()) {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
package.sensitive = false;
config.game.voices.retain(|voice| VoiceLocale::from_str(voice) != Some(package.locale));
config::update(config.clone());
Config::update(config.clone());
let package = VoicePackage::with_locale(package.locale).unwrap();
let game_path = config.game.path.for_edition(config.launcher.edition).to_path_buf();
@ -1019,7 +1023,7 @@ impl SimpleAsyncComponent for GeneralApp {
}
GeneralAppMsg::WineOpen(executable) => {
let config = config::get().unwrap_or_else(|_| CONFIG.clone());
let config = Config::get().unwrap_or_else(|_| CONFIG.clone());
if let Ok(Some(wine)) = config.get_selected_wine() {
let result = wine.to_wine(config.components.path, Some(config.game.wine.builds.join(&wine.name)))
@ -1056,10 +1060,10 @@ impl SimpleAsyncComponent for GeneralApp {
}
}
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
config.launcher.style = style;
config::update(config);
Config::update(config);
}
self.style = style;
@ -1135,7 +1139,7 @@ impl SimpleAsyncComponent for GeneralApp {
}
GeneralAppMsg::SelectWine(index) => {
if let Ok(mut config) = config::get() {
if let Ok(mut config) = Config::get() {
if let Some((version, features)) = self.downloaded_wine_versions.get(index) {
if config.game.wine.selected.as_ref() != Some(&version.title) {
self.selecting_wine_version = true;
@ -1154,7 +1158,7 @@ impl SimpleAsyncComponent for GeneralApp {
Ok(_) => {
config.game.wine.selected = Some(wine_name);
config::update(config);
Config::update(config);
}
Err(err) => {
@ -1178,7 +1182,7 @@ impl SimpleAsyncComponent for GeneralApp {
}
GeneralAppMsg::SelectDxvk(index) => {
if let Ok(config) = config::get() {
if let Ok(config) = Config::get() {
if let Some(version) = self.downloaded_dxvk_versions.get(index) {
if let Ok(selected) = config.get_selected_dxvk() {
if selected.is_none() || selected.unwrap().name != version.name {

View file

@ -6,7 +6,10 @@ use adw::prelude::*;
use anime_launcher_sdk::anime_game_core::prelude::*;
use anime_launcher_sdk::anime_game_core::genshin::prelude::*;
use anime_launcher_sdk::config::launcher::LauncherStyle;
use anime_launcher_sdk::config::ConfigExt;
use anime_launcher_sdk::genshin::config::Config;
use anime_launcher_sdk::genshin::config::schema::launcher::LauncherStyle;
use crate::i18n::tr;
@ -67,7 +70,7 @@ impl SimpleAsyncComponent for PreferencesApp {
add = model.environment.widget(),
connect_close_request[sender] => move |_| {
if let Err(err) = anime_launcher_sdk::config::flush() {
if let Err(err) = Config::flush() {
sender.input(PreferencesAppMsg::Toast {
title: tr("config-update-error"),
description: Some(err.to_string())