Fix config not loading

This commit is contained in:
jmb05
2026-11-02 22:02:37 +01:00
parent 541ce5ccb2
commit c758268beb
2 changed files with 7 additions and 4 deletions

View File

@@ -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<Config> {
fs::read_to_string(file_path)
.ok()
.and_then(|s| toml::from_str::<Config>(&s).ok())
.unwrap_or_default()
}
}

View File

@@ -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");