diff --git a/src/main.rs b/src/main.rs index 08ec7bb..0920008 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,6 +42,11 @@ lazy_static::lazy_static! { /// Path to `background` file. Standard is `$HOME/.local/share/anime-game-launcher/background` pub static ref BACKGROUND_FILE: PathBuf = anime_launcher_sdk::consts::launcher_dir().unwrap_or_default().join("background"); + + /// Path to `.keep-background` file. Used to mark launcher that it shouldn't update background picture + /// + /// Standard is `$HOME/.local/share/anime-game-launcher/.keep-background` + pub static ref KEEP_BACKGROUND_FILE: PathBuf = anime_launcher_sdk::consts::launcher_dir().unwrap_or_default().join(".keep-background"); } fn main() { diff --git a/src/ui/main.rs b/src/ui/main.rs index 273e420..40b951f 100644 --- a/src/ui/main.rs +++ b/src/ui/main.rs @@ -401,7 +401,7 @@ impl SimpleComponent for App { tracing::info!("Main window initialized"); - let download_picture = model.style == LauncherStyle::Classic; + let download_picture = model.style == LauncherStyle::Classic && !KEEP_BACKGROUND_FILE.exists(); // Initialize some heavy tasks std::thread::spawn(move || { diff --git a/src/ui/preferences/general.rs b/src/ui/preferences/general.rs index 498d8cf..f5e788d 100644 --- a/src/ui/preferences/general.rs +++ b/src/ui/preferences/general.rs @@ -48,6 +48,7 @@ pub enum GeneralAppMsg { title: String, description: Option }, + UpdateLauncherStyle(LauncherStyle), WineRecommendedOnly(bool), DxvkRecommendedOnly(bool), @@ -142,7 +143,17 @@ impl SimpleAsyncComponent for GeneralApp { set_subtitle: &tr("update-background-description"), add_suffix = >k::Switch { - set_valign: gtk::Align::Center + set_valign: gtk::Align::Center, + set_active: !KEEP_BACKGROUND_FILE.exists(), + + connect_state_notify => |switch| { + #[allow(unused_must_use)] + if switch.state() { + std::fs::remove_file(KEEP_BACKGROUND_FILE.as_path()); + } else { + std::fs::write(KEEP_BACKGROUND_FILE.as_path(), ""); + } + } } } }, @@ -513,11 +524,11 @@ impl SimpleAsyncComponent for GeneralApp { match msg { GeneralAppMsg::UpdateGameDiff(diff) => { self.game_diff = diff; - }, + } GeneralAppMsg::UpdatePatch(patch) => { self.patch = patch; - }, + } #[allow(unused_must_use)] GeneralAppMsg::UpdateLauncherStyle(style) => {