feat(ui): made "update background" switcher

Now this switch will create `.keep-background` file in the launcher folder if launcher is supposed to keep current `background` file
This commit is contained in:
Observer KRypt0n_ 2023-02-23 19:33:59 +02:00
parent 6340ccbd6e
commit fcb24f803b
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
3 changed files with 20 additions and 4 deletions

View file

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

View file

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

View file

@ -48,6 +48,7 @@ pub enum GeneralAppMsg {
title: String,
description: Option<String>
},
UpdateLauncherStyle(LauncherStyle),
WineRecommendedOnly(bool),
DxvkRecommendedOnly(bool),
@ -142,7 +143,17 @@ impl SimpleAsyncComponent for GeneralApp {
set_subtitle: &tr("update-background-description"),
add_suffix = &gtk::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) => {