feat: changed background images processing logic

This commit is contained in:
Nikita Podvirnyi 2024-07-19 12:39:27 +02:00
parent 39527c18d7
commit b7ca18495e
No known key found for this signature in database
GPG key ID: 859D416E5142AFF3
2 changed files with 7 additions and 13 deletions

View file

@ -73,12 +73,6 @@ pub fn download_background() -> anyhow::Result<()> {
tracing::debug!("Background picture is already downloaded. Skipping");
download_image = false;
if crate::BACKGROUND_PRIMARY_FILE.exists() {
tracing::debug!("Background picture is already patched. Skipping");
return Ok(());
}
}
}
@ -97,20 +91,20 @@ pub fn download_background() -> anyhow::Result<()> {
Command::new("dwebp")
.arg(crate::BACKGROUND_FILE.as_path())
.arg("-o")
.arg(crate::BACKGROUND_PRIMARY_FILE.as_path())
.arg(crate::PROCESSED_BACKGROUND_FILE.as_path())
.spawn()?
.wait()?;
// If it failed to re-code the file - just copy it
// Will happen with HSR because devs apparently named
// their background image ".webp" while it's JPEG
if !crate::BACKGROUND_PRIMARY_FILE.exists() {
std::fs::copy(crate::BACKGROUND_FILE.as_path(), crate::BACKGROUND_PRIMARY_FILE.as_path())?;
if !crate::PROCESSED_BACKGROUND_FILE.exists() {
std::fs::copy(crate::BACKGROUND_FILE.as_path(), crate::PROCESSED_BACKGROUND_FILE.as_path())?;
}
}
else {
std::fs::copy(crate::BACKGROUND_FILE.as_path(), crate::BACKGROUND_PRIMARY_FILE.as_path())?;
std::fs::copy(crate::BACKGROUND_FILE.as_path(), crate::PROCESSED_BACKGROUND_FILE.as_path())?;
}
Ok(())

View file

@ -61,8 +61,8 @@ lazy_static::lazy_static! {
/// Path to `background` file. Standard is `$HOME/.local/share/anime-game-launcher/background`
pub static ref BACKGROUND_FILE: PathBuf = LAUNCHER_FOLDER.join("background");
/// Path to `background-primary` file. Standard is `$HOME/.local/share/anime-game-launcher/background-primary`
pub static ref BACKGROUND_PRIMARY_FILE: PathBuf = LAUNCHER_FOLDER.join("background-primary");
/// Path to the processed `background` file. Standard is `$HOME/.cache/anime-game-launcher/background`
pub static ref PROCESSED_BACKGROUND_FILE: PathBuf = CACHE_FOLDER.join("background");
/// Path to `.keep-background` file. Used to mark launcher that it shouldn't update background picture
///
@ -102,7 +102,7 @@ lazy_static::lazy_static! {
.round-bin {{
border-radius: 24px;
}}
", BACKGROUND_PRIMARY_FILE.to_string_lossy());
", PROCESSED_BACKGROUND_FILE.to_string_lossy());
}
fn main() -> anyhow::Result<()> {