1use serde::Deserialize;
4use std::path::PathBuf;
5
6#[derive(Debug, Clone, Deserialize)]
8#[serde(default)]
9pub struct Config {
10 pub default_group: Option<String>,
12 pub theme: String,
14}
15
16impl Default for Config {
17 fn default() -> Self {
18 Self {
19 default_group: None,
20 theme: "dark".to_string(),
21 }
22 }
23}
24
25impl Config {
26 pub fn load() -> Self {
28 let config_dir = std::env::var("SONOS_CONFIG_DIR")
29 .ok()
30 .filter(|s| !s.is_empty())
31 .map(PathBuf::from)
32 .filter(|p| p.is_absolute())
33 .or_else(|| dirs::config_dir().map(|p| p.join("sonos")));
34
35 let mut config: Config = config_dir
36 .map(|d| d.join("config.toml"))
37 .and_then(|p| std::fs::read_to_string(p).ok())
38 .and_then(|s| toml::from_str(&s).ok())
39 .unwrap_or_default();
40
41 if let Ok(group) = std::env::var("SONOS_DEFAULT_GROUP") {
43 config.default_group = Some(group);
44 }
45
46 config
47 }
48}