diff --git a/src/config.rs b/src/config.rs index 3c18090..30d7385 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,11 +8,10 @@ pub struct Config { } impl Config { - pub fn load() -> Config { - fs::read_to_string("../jmb-bar.conf") + pub fn load(file_path: &str) -> Option { + fs::read_to_string(file_path) .ok() .and_then(|s| toml::from_str::(&s).ok()) - .unwrap_or_default() } } diff --git a/src/main.rs b/src/main.rs index a44ae52..dd92db5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,11 @@ pub const APP_NAME: &str = "net.jmb19905.jmb-bar"; fn main() { info!(&LOGGER, "Starting jmb-bar"); - let config = Config::load(); + let config = Config::load("jmb-bar.conf"); + let config = config.unwrap_or_else(|| { + warn!(&LOGGER, "Couldn't load config file, using default"); + Config::default() + }); let backend = Backend::start(&config); gio::resources_register_include!("templates.gresource").expect("Failed to register resources");