chore: do not log error for unset configs

This commit is contained in:
Michael Aaron Murphy 2024-08-13 19:34:35 +02:00 committed by Michael Murphy
parent f758451ab9
commit 43b23c11c9
3 changed files with 28 additions and 7 deletions

View file

@ -36,16 +36,25 @@ impl Default for Page {
fn default() -> Self {
let comp_config = cosmic_config::Config::new("com.system76.CosmicComp", 1).unwrap();
let comp_workspace_config = comp_config.get("workspaces").unwrap_or_else(|err| {
error!(?err, "Failed to read config 'workspaces'");
if !matches!(cosmic_config::Error::NoConfigDirectory, err) {
error!(?err, "Failed to read config 'workspaces'");
}
WorkspaceConfig::default()
});
let config = cosmic_config::Config::new("com.system76.CosmicWorkspaces", 1).unwrap();
let show_workspace_name = config.get("show_workspace_name").unwrap_or_else(|err| {
error!(?err, "Failed to read config 'show_workspace_name'");
if !matches!(cosmic_config::Error::NoConfigDirectory, err) {
error!(?err, "Failed to read config 'show_workspace_name'");
}
false
});
let show_workspace_number = config.get("show_workspace_number").unwrap_or_else(|err| {
error!(?err, "Failed to read config 'show_workspace_number'");
if !matches!(cosmic_config::Error::NoConfigDirectory, err) {
error!(?err, "Failed to read config 'show_workspace_number'");
}
false
});
Self {

View file

@ -46,7 +46,10 @@ fn get_config<T: Default + serde::de::DeserializeOwned>(
key: &str,
) -> T {
config.get(key).unwrap_or_else(|why| {
error!(?why, "Failed to read config '{}'", key);
if !matches!(cosmic_config::Error::NoConfigDirectory, why) {
error!(?why, "Failed to read config '{}'", key);
}
T::default()
})
}

View file

@ -56,21 +56,30 @@ impl Default for Page {
let military_time = cosmic_applet_config
.get("military_time")
.unwrap_or_else(|err| {
error!(?err, "Failed to read config 'military_time'");
if !matches!(cosmic_config::Error::NoConfigDirectory, err) {
error!(?err, "Failed to read config 'military_time'");
}
false
});
let first_day_of_week = cosmic_applet_config
.get("first_day_of_week")
.unwrap_or_else(|err| {
error!(?err, "Failed to read config 'first_day_of_week'");
if !matches!(cosmic_config::Error::NoConfigDirectory, err) {
error!(?err, "Failed to read config 'first_day_of_week'");
}
6
});
let show_date_in_top_panel = cosmic_applet_config
.get("show_date_in_top_panel")
.unwrap_or_else(|err| {
error!(?err, "Failed to read config 'show_date_in_top_panel'");
if !matches!(cosmic_config::Error::NoConfigDirectory, err) {
error!(?err, "Failed to read config 'show_date_in_top_panel'");
}
true
});