use std::collections::BTreeMap; use std::path::PathBuf; use serde::{Deserialize, Serialize}; use oneclient_cluster::GameSettingsProfile; #[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default)] #[serde(rename_all = "snake_case")] pub enum ViewLayout { #[default] Grid, List, } pub const DEFAULT_GRID_COLUMNS: u8 = 3; #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] #[serde(default)] pub struct ViewState { pub layout: ViewLayout, #[serde(skip_serializing_if = "Option::is_none")] pub sort: Option, pub columns: u8, } impl Default for ViewState { fn default() -> Self { Self { layout: ViewLayout::default(), sort: None, columns: DEFAULT_GRID_COLUMNS, } } } #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(default)] pub struct LauncherSettings { pub settings_version: u32, pub log_debug: bool, pub auto_update: bool, pub crash_reporting: bool, pub enable_gamemode: bool, pub use_discrete_gpu: bool, pub discord_enabled: bool, pub max_concurrent_requests: usize, pub global_game_settings: GameSettingsProfile, pub allow_parallel_running_clusters: bool, pub dynamic_background_enabled: bool, pub start_maximized: bool, pub animations_enabled: bool, pub view_states: BTreeMap, pub seen_onboarding: bool, pub accepted_tos_version: u32, pub accepted_privacy_version: u32, pub declined_tos: bool, pub seen_versions: Vec, pub seen_changelog_version: Option, pub modrinth_api_key: Option, pub curseforge_api_key: Option, pub custom_api_endpoint: Option, pub custom_meta_url_base: Option, pub data_dir: Option, pub previous_data_dir: Option, } impl LauncherSettings { pub fn view_state(&self, key: &str) -> ViewState { self.view_states.get(key).cloned().unwrap_or_default() } pub fn set_view_state(&mut self, key: impl Into, state: ViewState) { self.view_states.insert(key.into(), state); } } impl Default for LauncherSettings { fn default() -> Self { Self { settings_version: 1, log_debug: false, auto_update: true, crash_reporting: true, discord_enabled: true, enable_gamemode: false, use_discrete_gpu: false, max_concurrent_requests: 25, global_game_settings: GameSettingsProfile::default_global_profile(), allow_parallel_running_clusters: false, dynamic_background_enabled: true, start_maximized: false, animations_enabled: true, view_states: BTreeMap::new(), seen_onboarding: false, accepted_tos_version: 0, accepted_privacy_version: 0, declined_tos: false, seen_versions: Vec::new(), seen_changelog_version: None, modrinth_api_key: None, curseforge_api_key: None, custom_api_endpoint: None, custom_meta_url_base: None, data_dir: None, previous_data_dir: None, } } }