summaryrefslogtreecommitdiff
path: root/src/configmanager.rs
blob: c005d2c82451835d3854405e89965063c1c0a1db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use std::fs;
use serde::Deserialize;
use dirs::home_dir;

#[derive(Debug, Deserialize, Clone)]
pub struct Config {
    pub lat:     f64,
    pub lon:     f64,
    pub exclude: String,
    pub appid:   String,
    pub lang:    String,
    pub units:   String,
    pub cache:   bool,
    pub rain:    String,
    pub sunny:   String,
    pub snowy:   String,
}

type BoxedError = Box<dyn std::error::Error + Send + Sync>;



pub fn handle_config(_config: &Config) -> Result<(), Box<dyn std::error::Error>> {
    Ok(())
}

pub fn gen_standard_conf() {
    // TODO: Implement
}
 
impl Config {
    pub fn load() -> Result<Self, Box<dyn std::error::Error>> {
        let mut path = home_dir().ok_or("Home directory not found")?;
        path.push(".config/WeatherFetch/Config.toml");
        
        let config_str = fs::read_to_string(&path)
            .map_err(|e| format!("Failed to read config: {}", e))?;
        
        let config: Config = toml::from_str(&config_str)
            .map_err(|e| format!("Invalid TOML: {}", e))?;
        
        Ok(config)
    }
}