diff --git a/delfin/src/config/general.rs b/delfin/src/config/general.rs index c0ed328..e6b3317 100644 --- a/delfin/src/config/general.rs +++ b/delfin/src/config/general.rs @@ -1,5 +1,6 @@ use relm4::adw; use serde::{Deserialize, Serialize}; +use unic_langid::LanguageIdentifier; #[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq)] pub enum Theme { @@ -21,6 +22,7 @@ impl From for adw::ColorScheme { #[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)] pub struct GeneralConfig { + pub language: Option, #[serde(default)] pub theme: Theme, } diff --git a/delfin/src/config/migrate.rs b/delfin/src/config/migrate.rs index ba7d5d7..dfa8070 100644 --- a/delfin/src/config/migrate.rs +++ b/delfin/src/config/migrate.rs @@ -113,6 +113,7 @@ italic = false let config: Config = config_version.into(); let expected = Config { + version: 2, window: Window { width: 967, height: 670, @@ -142,7 +143,10 @@ italic = false }], }, ], - general: GeneralConfig { theme: Theme::Dark }, + general: GeneralConfig { + language: None, + theme: Theme::Dark, + }, video_player: VideoPlayerConfig { volume: 0.0, muted: true, @@ -150,7 +154,6 @@ italic = false on_left_click: VideoPlayerOnLeftClick::ToggleControls, ..Default::default() }, - ..Default::default() }; assert_eq!(config, expected); diff --git a/delfin/src/config/mod.rs b/delfin/src/config/mod.rs index d8187c3..30c4ba5 100644 --- a/delfin/src/config/mod.rs +++ b/delfin/src/config/mod.rs @@ -7,7 +7,6 @@ use std::{fs, path::PathBuf}; use anyhow::{anyhow, Result}; use serde::{Deserialize, Serialize}; -use unic_langid::LanguageIdentifier; use uuid::Uuid; use self::{ @@ -17,29 +16,23 @@ use self::{ #[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] pub struct Config { version: usize, - - pub language: Option, #[serde(default)] pub window: Window, - - pub servers: Vec, - #[serde(default)] pub general: GeneralConfig, - #[serde(default)] pub video_player: VideoPlayerConfig, + pub servers: Vec, } impl Default for Config { fn default() -> Self { Self { version: 2, - language: None, window: Window::default(), - servers: Vec::default(), general: GeneralConfig::default(), video_player: VideoPlayerConfig::default(), + servers: Vec::default(), } } } diff --git a/delfin/src/config/versions/config_v1.rs b/delfin/src/config/versions/config_v1.rs index cd9bc05..8185837 100644 --- a/delfin/src/config/versions/config_v1.rs +++ b/delfin/src/config/versions/config_v1.rs @@ -182,7 +182,6 @@ impl Migrate for ConfigV1 { Config { version: 2, - language: self.language, window: Window { width: self.window.width, height: self.window.height, @@ -190,6 +189,7 @@ impl Migrate for ConfigV1 { }, servers, general: GeneralConfig { + language: self.language, theme: match self.general.theme { Theme::Light => config::general::Theme::Light, Theme::Dark => config::general::Theme::Dark, diff --git a/delfin/src/locales.rs b/delfin/src/locales.rs index c0a4768..20f0d46 100644 --- a/delfin/src/locales.rs +++ b/delfin/src/locales.rs @@ -25,6 +25,7 @@ lazy_static! { pub fn current_language() -> LanguageIdentifier { CONFIG .read() + .general .language .clone() .unwrap_or(DEFAULT_LANGUAGE.clone()) diff --git a/delfin/src/preferences/general_preferences.rs b/delfin/src/preferences/general_preferences.rs index d5a7aea..674f40c 100644 --- a/delfin/src/preferences/general_preferences.rs +++ b/delfin/src/preferences/general_preferences.rs @@ -103,7 +103,7 @@ impl SimpleComponent for GeneralPreferences { match message { GeneralPreferencesInput::Language(language) => { - config.language = language + config.general.language = language .map(|l| LanguageIdentifier::from_str(&l).expect("Error setting language")); } GeneralPreferencesInput::ThemeChanged(theme) => { @@ -116,7 +116,7 @@ impl SimpleComponent for GeneralPreferences { } fn get_selected_language(language: &adw::ComboRow, config: Config) -> u32 { - match config.language { + match config.general.language { // First item is system default None => 0, Some(selected_language) => {