fix(ui): fixed background picture updating

This commit is contained in:
Observer KRypt0n_ 2023-03-01 18:59:00 +02:00
parent 7d080fcdf4
commit 5ae39efbac
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
5 changed files with 15 additions and 13 deletions

8
Cargo.lock generated
View file

@ -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"

View file

@ -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"] }

View file

@ -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();

View file

@ -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 || {

View file

@ -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);
});