From 5ae39efbacf47fec53aa220f904ff2596b19214c Mon Sep 17 00:00:00 2001 From: Observer KRypt0n_ Date: Wed, 1 Mar 2023 18:59:00 +0200 Subject: [PATCH] fix(ui): fixed background picture updating --- Cargo.lock | 8 +------- Cargo.toml | 2 +- src/background.rs | 6 +++++- src/ui/main.rs | 8 ++++++-- src/ui/preferences/general.rs | 4 ++-- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c099155..75027f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -63,7 +63,7 @@ dependencies = [ "gtk4", "lazy_static", "libadwaita", - "md5", + "md-5", "relm4", "rfd", "serde_json", @@ -1486,12 +1486,6 @@ dependencies = [ "md5-asm", ] -[[package]] -name = "md5" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771" - [[package]] name = "md5-asm" version = "0.5.0" diff --git a/Cargo.toml b/Cargo.toml index b1b804e..c0f537c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,4 +33,4 @@ lazy_static = "1.4.0" anyhow = "1.0" cached = { version = "0.42", features = ["proc_macro"] } serde_json = "1" -md5 = "0.7" +md-5 = { version = "0.10", features = ["asm"] } diff --git a/src/background.rs b/src/background.rs index 6d5903f..6562c46 100644 --- a/src/background.rs +++ b/src/background.rs @@ -1,6 +1,8 @@ use anime_launcher_sdk::anime_game_core::installer::downloader::Downloader; use anime_launcher_sdk::anime_game_core::curl::fetch; +use md5::{Md5, Digest}; + #[derive(Debug, Clone)] pub struct Background { pub uri: String, @@ -45,7 +47,7 @@ pub fn download_background() -> anyhow::Result<()> { let info = get_background_info()?; if crate::BACKGROUND_FILE.exists() { - let hash = md5::compute(std::fs::read(crate::BACKGROUND_FILE.as_path())?); + let hash = Md5::digest(std::fs::read(crate::BACKGROUND_FILE.as_path())?); if format!("{:x}", hash).to_lowercase() == info.hash { tracing::debug!("Background picture is already downloaded. Skipping"); @@ -56,6 +58,8 @@ pub fn download_background() -> anyhow::Result<()> { let mut downloader = Downloader::new(info.uri)?; + downloader.continue_downloading = false; + if let Err(err) = downloader.download_to(crate::BACKGROUND_FILE.as_path(), |_, _| {}) { let err: std::io::Error = err.into(); diff --git a/src/ui/main.rs b/src/ui/main.rs index 421fef6..31d7c50 100644 --- a/src/ui/main.rs +++ b/src/ui/main.rs @@ -110,7 +110,11 @@ impl SimpleComponent for App { view! { main_window = adw::Window { - set_title: Some("An Anime Game Launcher"), + #[watch] + set_title: match model.style { + LauncherStyle::Modern => Some("An Anime Game Launcher"), + LauncherStyle::Classic => Some("") + }, #[watch] set_default_size: ( @@ -551,7 +555,7 @@ impl SimpleComponent for App { tracing::info!("Main window initialized"); - let download_picture = model.style == LauncherStyle::Classic && !KEEP_BACKGROUND_FILE.exists(); + let download_picture = model.style == LauncherStyle::Classic; // Initialize some heavy tasks std::thread::spawn(move || { diff --git a/src/ui/preferences/general.rs b/src/ui/preferences/general.rs index de754f5..9a676b7 100644 --- a/src/ui/preferences/general.rs +++ b/src/ui/preferences/general.rs @@ -630,13 +630,13 @@ impl SimpleAsyncComponent for GeneralApp { std::thread::spawn(move || { if let Err(err) = package.delete_in(&config.game.path) { tracing::error!("Failed to delete voice package: {:?}", package.locale()); - + sender.input(GeneralAppMsg::Toast { title: tr("voice-package-deletion-error"), description: Some(err.to_string()) }); } - + sender.input(GeneralAppMsg::SetVoicePackageSensitivity(index, true)); sender.output(PreferencesAppMsg::UpdateLauncherState); });