Move language config field into general config
This commit is contained in:
@@ -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<Theme> for adw::ColorScheme {
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
|
||||
pub struct GeneralConfig {
|
||||
pub language: Option<LanguageIdentifier>,
|
||||
#[serde(default)]
|
||||
pub theme: Theme,
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -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<LanguageIdentifier>,
|
||||
#[serde(default)]
|
||||
pub window: Window,
|
||||
|
||||
pub servers: Vec<Server>,
|
||||
|
||||
#[serde(default)]
|
||||
pub general: GeneralConfig,
|
||||
|
||||
#[serde(default)]
|
||||
pub video_player: VideoPlayerConfig,
|
||||
pub servers: Vec<Server>,
|
||||
}
|
||||
|
||||
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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -182,7 +182,6 @@ impl Migrate<Config> for ConfigV1 {
|
||||
|
||||
Config {
|
||||
version: 2,
|
||||
language: self.language,
|
||||
window: Window {
|
||||
width: self.window.width,
|
||||
height: self.window.height,
|
||||
@@ -190,6 +189,7 @@ impl Migrate<Config> 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,
|
||||
|
@@ -25,6 +25,7 @@ lazy_static! {
|
||||
pub fn current_language() -> LanguageIdentifier {
|
||||
CONFIG
|
||||
.read()
|
||||
.general
|
||||
.language
|
||||
.clone()
|
||||
.unwrap_or(DEFAULT_LANGUAGE.clone())
|
||||
|
@@ -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) => {
|
||||
|
Reference in New Issue
Block a user