Add tray and theme settings (#21)
This commit was merged in pull request #43.
This commit is contained in:
1 parent
28319fc133
commit
d7bd69c35d
7 files changed
+520
-37
No files matched your search
@@ -13,6 +13,35 @@ pub struct Config {
|
||||
pub riot_id: String,
|
||||
#[serde(default = "default_region")]
|
||||
pub region: String,
|
||||
#[serde(flatten)]
|
||||
pub preferences: Preferences,
|
||||
#[serde(flatten)]
|
||||
other: toml::Table,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(default)]
|
||||
pub struct Preferences {
|
||||
pub close_to_tray: bool,
|
||||
pub theme: ThemePreference,
|
||||
}
|
||||
|
||||
impl Default for Preferences {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
close_to_tray: true,
|
||||
theme: ThemePreference::System,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ThemePreference {
|
||||
#[default]
|
||||
System,
|
||||
Light,
|
||||
Dark,
|
||||
}
|
||||
|
||||
fn default_region() -> String {
|
||||
@@ -37,6 +66,8 @@ impl Config {
|
||||
riot_api_key: String::new(),
|
||||
riot_id: String::new(),
|
||||
region: default_region(),
|
||||
preferences: Preferences::default(),
|
||||
other: toml::Table::new(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -76,6 +107,8 @@ mod tests {
|
||||
let config = load("riot_api_key = \"k\"\nriot_id = \"Joueur#EUW\"\n").unwrap();
|
||||
assert_eq!(config.riot_id, "Joueur#EUW");
|
||||
assert_eq!(config.region, "europe");
|
||||
assert!(config.preferences.close_to_tray);
|
||||
assert_eq!(config.preferences.theme, ThemePreference::System);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -112,21 +145,29 @@ mod tests {
|
||||
("", "", "europe")
|
||||
);
|
||||
assert!(!dir.path().join("config.toml").exists());
|
||||
assert!(config.preferences.close_to_tray);
|
||||
assert_eq!(config.preferences.theme, ThemePreference::System);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn saved_settings_load_back() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let path = dir.path().join("nested").join("config.toml");
|
||||
let config = Config {
|
||||
riot_api_key: "RGAPI-secret".into(),
|
||||
riot_id: "Joueur#EUW".into(),
|
||||
region: "americas".into(),
|
||||
let path = dir.path().join("config.toml");
|
||||
std::fs::write(
|
||||
&path,
|
||||
"riot_api_key = \"RGAPI-secret\"\nriot_id = \"Joueur#EUW\"\nregion = \"americas\"\n\n[other]\nvalue = 42\n",
|
||||
)
|
||||
.unwrap();
|
||||
let mut config = Config::load(&path).unwrap();
|
||||
config.preferences = Preferences {
|
||||
close_to_tray: false,
|
||||
theme: ThemePreference::Dark,
|
||||
};
|
||||
|
||||
config.save(&path).unwrap();
|
||||
let loaded = Config::load_or_default(&path).unwrap();
|
||||
|
||||
assert_eq!(loaded.preferences, config.preferences);
|
||||
assert_eq!(loaded.other["other"]["value"].as_integer(), Some(42));
|
||||
assert_eq!(loaded.riot_api_key, "RGAPI-secret");
|
||||
assert_eq!(
|
||||
(loaded.riot_id.as_str(), loaded.region.as_str()),
|
||||
@@ -143,6 +184,8 @@ mod tests {
|
||||
riot_api_key: "RGAPI-secret".into(),
|
||||
riot_id: String::new(),
|
||||
region: "europe".into(),
|
||||
preferences: Preferences::default(),
|
||||
other: toml::Table::new(),
|
||||
};
|
||||
|
||||
let Err(err) = config.save(&blocker.join("config.toml")) else {
|
||||
|
||||
@@ -15,7 +15,7 @@ mod tracker;
|
||||
pub use champion_search::ChampionSearch;
|
||||
pub use champions::{Champion, ChampionCatalog, ChampionSource, DataDragon};
|
||||
pub use client::{ClientError, GameClientSource, GamePhase, Gameflow};
|
||||
pub use config::{Config, data_dir};
|
||||
pub use config::{Config, Preferences, ThemePreference, data_dir};
|
||||
pub use date::Date;
|
||||
pub use error::{Error, SourceError};
|
||||
pub use follow::{MATCH_RETRIES, ProgressCheck, RETRY_EVERY_MS, Status, UpdateProblem};
|
||||
|
||||
Reference in new issue
Block a user