diff --git a/Cargo.lock b/Cargo.lock index 6aef93d..f94fb07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,7 +31,7 @@ dependencies = [ [[package]] name = "anime-game-core" -version = "0.2.2" +version = "0.3.0" dependencies = [ "bzip2", "curl", @@ -51,7 +51,7 @@ dependencies = [ [[package]] name = "anime-game-launcher" -version = "0.6.2" +version = "0.6.3" dependencies = [ "anime-game-core", "dirs", diff --git a/Cargo.toml b/Cargo.toml index 91a54e9..ceb2a27 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "anime-game-launcher" -version = "0.6.2" +version = "0.6.3" description = "Anime Game launcher" authors = ["Nikita Podvirnyy "] license = "GPL-3.0" diff --git a/anime-game-core b/anime-game-core index 9820453..8c7a8f9 160000 --- a/anime-game-core +++ b/anime-game-core @@ -1 +1 @@ -Subproject commit 9820453d6fdc5ccdc832fd0a8bbe80e210df2b2e +Subproject commit 8c7a8f9bcbe008f164e810aeddbe33366fa541ec diff --git a/src/lib/consts.rs b/src/lib/consts.rs index e54d1c2..bf1d7d1 100644 --- a/src/lib/consts.rs +++ b/src/lib/consts.rs @@ -1,6 +1,14 @@ +use std::time::Duration; + static mut LAUNCHER_DIR: Option> = None; static mut CONFIG_FILE: Option> = None; +/// Timeout used by `anime_game_core::telemetry::is_disabled` to check acessibility of telemetry servers +pub const TELEMETRY_CHECK_TIMEOUT: Option = Some(Duration::from_secs(3)); + +/// Timeout used by `anime_game_core::linux_patch::Patch::try_fetch` to fetch patch info +pub const PATCH_FETCHING_TIMEOUT: Option = Some(Duration::from_secs(5)); + pub fn launcher_dir() -> Option { unsafe { match &LAUNCHER_DIR { diff --git a/src/lib/game.rs b/src/lib/game.rs index c707cfa..7365535 100644 --- a/src/lib/game.rs +++ b/src/lib/game.rs @@ -2,6 +2,9 @@ use std::io::{Error, ErrorKind}; use std::path::Path; use std::process::Command; +use anime_game_core::telemetry; + +use super::consts; use super::config; #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -73,6 +76,12 @@ pub fn run(debug: bool) -> std::io::Result<()> { None => return Err(Error::new(ErrorKind::Other, "Couldn't find wine executable")) }; + // Check telemetry servers + + if let Some(server) = telemetry::is_disabled(consts::TELEMETRY_CHECK_TIMEOUT) { + return Err(Error::new(ErrorKind::Other, format!("Telemetry server is not disabled: {server}"))); + } + // Prepare bash -c '' let mut bash_chain = String::new(); diff --git a/src/lib/launcher/states.rs b/src/lib/launcher/states.rs index efb2bff..57e449f 100644 --- a/src/lib/launcher/states.rs +++ b/src/lib/launcher/states.rs @@ -2,6 +2,7 @@ use std::io::{Error, ErrorKind}; use anime_game_core::prelude::*; +use crate::lib::consts; use crate::lib::config; use crate::lib::wine_prefix::WinePrefix; @@ -93,7 +94,7 @@ impl LauncherState { status("Updating patch info..."); - let patch = Patch::try_fetch(config.patch.servers.clone())?; + let patch = Patch::try_fetch(config.patch.servers.clone(), consts::PATCH_FETCHING_TIMEOUT)?; if patch.is_applied(&config.game.path)? { Self::Launch diff --git a/src/ui/main.rs b/src/ui/main.rs index 9d1c43a..c72c73e 100644 --- a/src/ui/main.rs +++ b/src/ui/main.rs @@ -18,6 +18,7 @@ use super::preferences::PreferencesStack; use super::traits::toast::Toast; use super::components::progress_bar::*; +use crate::lib::consts; use crate::lib::config; use crate::lib::game; use crate::lib::launcher::states::LauncherState; @@ -275,7 +276,9 @@ impl App { if let Err(err) = game::run(false) { this.widgets.window.show(); - this.toast("Failed to run game", err); + this.update(Actions::Toast(Rc::new(( + String::from("Failed to run game"), err + )))).unwrap(); } else { @@ -635,7 +638,7 @@ impl App { let total = broken.len() as f64; - let is_patch_applied = match Patch::try_fetch(config.patch.servers) { + let is_patch_applied = match Patch::try_fetch(config.patch.servers, consts::PATCH_FETCHING_TIMEOUT) { Ok(patch) => patch.is_applied(&config.game.path).unwrap_or(true), Err(_) => true }; diff --git a/src/ui/preferences/general.rs b/src/ui/preferences/general.rs index 7e6ffdd..10c6ae6 100644 --- a/src/ui/preferences/general.rs +++ b/src/ui/preferences/general.rs @@ -649,7 +649,7 @@ impl App { self.widgets.game_version.set_label(¤t.to_string()); self.widgets.game_version.set_css_classes(&["error"]); - self.widgets.game_version.set_tooltip_text(Some(&format!("Game is too outdated and can't be updated. Latest version: {}", latest))); + self.widgets.game_version.set_tooltip_text(Some(&format!("Game is too outdated and can't be updated. Latest version: {latest}"))); }, VersionDiff::NotInstalled { .. } => { self.widgets.game_version.set_label("not installed"); @@ -660,7 +660,7 @@ impl App { // Update patch version status_page.set_description(Some("Updating patch info...")); - let patch = Patch::try_fetch(config.patch.servers)?; + let patch = Patch::try_fetch(config.patch.servers, consts::PATCH_FETCHING_TIMEOUT)?; match patch { Patch::NotAvailable => { @@ -673,7 +673,7 @@ impl App { self.widgets.patch_version.set_label("outdated"); self.widgets.patch_version.set_css_classes(&["warning"]); - self.widgets.patch_version.set_tooltip_text(Some(&format!("Patch is outdated ({} -> {})", current, latest))); + self.widgets.patch_version.set_tooltip_text(Some(&format!("Patch is outdated ({current} -> {latest})"))); }, Patch::Preparation { .. } => { self.widgets.patch_version.set_label("preparation");