ensure persistent_state is easier and more infallible to add fields to

This commit is contained in:
2025-11-06 23:55:04 +00:00
parent f07421e75a
commit c34cf187d5
3 changed files with 18 additions and 5 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
mod app;
pub mod app;
mod colours;
mod debug;
pub mod run;
+1 -3
View File
@@ -14,9 +14,7 @@ fn app_creator(
let mut app = Box::new(App::default());
// load previously selected launch platform & settings from persistent state
if let Some(persistent_state) = PersistentState::get() {
app.launch.selected = persistent_state.launcher;
app.anti_afk.enabled = persistent_state.anti_afk_enabled;
app.settings = persistent_state.settings;
persistent_state.apply_to(&mut app);
}
// check if we're elevated. if not, and the user wants an elevated launch - relaunch elevated
if !app.flags.elevated && app.settings.start_elevated {
+16 -1
View File
@@ -1,4 +1,8 @@
use crate::{features::launch::Platform, gui::settings::Settings, util::consts::path};
use crate::{
features::launch::Platform,
gui::{app, settings::Settings},
util::consts::path,
};
use serde::{Deserialize, Serialize};
use std::{
fs::{self, File},
@@ -24,4 +28,15 @@ impl PersistentState {
let json = serde_json::to_string_pretty(&self).unwrap();
config_file.write_all(json.as_bytes()).unwrap();
}
pub fn apply_to(self, app: &mut app::App) {
let Self {
launcher,
anti_afk_enabled,
settings,
} = self;
app.launch.selected = launcher;
app.anti_afk.enabled = anti_afk_enabled;
app.settings = settings;
}
}