1use serde::Deserialize;
4use std::path::PathBuf;
5
6#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize)]
8#[serde(rename_all = "lowercase")]
9pub enum AlbumArtMode {
10 #[default]
11 Auto,
12 Off,
13 #[serde(other)]
15 Other,
16}
17
18impl AlbumArtMode {
19 pub fn is_off(&self) -> bool {
21 *self == Self::Off
22 }
23}
24
25#[derive(Debug, Clone, Deserialize)]
27#[serde(default)]
28pub struct Config {
29 pub default_group: Option<String>,
31 pub theme: String,
33 pub album_art_mode: AlbumArtMode,
35}
36
37impl Default for Config {
38 fn default() -> Self {
39 Self {
40 default_group: None,
41 theme: "dark".to_string(),
42 album_art_mode: AlbumArtMode::default(),
43 }
44 }
45}
46
47impl Config {
48 pub fn load() -> Self {
50 let config_dir = std::env::var("SONOS_CONFIG_DIR")
51 .ok()
52 .filter(|s| !s.is_empty())
53 .map(PathBuf::from)
54 .filter(|p| p.is_absolute())
55 .or_else(|| dirs::config_dir().map(|p| p.join("sonos")));
56
57 let mut config: Config = config_dir
58 .map(|d| d.join("config.toml"))
59 .and_then(|p| std::fs::read_to_string(p).ok())
60 .and_then(|s| toml::from_str(&s).ok())
61 .unwrap_or_default();
62
63 if let Ok(group) = std::env::var("SONOS_DEFAULT_GROUP") {
65 config.default_group = Some(group);
66 }
67
68 config
69 }
70}