Respect military time config from time applet

Closes: #775
This commit is contained in:
Josh Megnauth 2025-02-24 00:47:32 -05:00
parent 38829f4c00
commit e34dcf1372
No known key found for this signature in database
GPG key ID: 70813183462EFAD3
4 changed files with 125 additions and 64 deletions

View file

@ -3,7 +3,7 @@
use std::{any::TypeId, num::NonZeroU16, path::PathBuf};
use cosmic::{
cosmic_config::{self, cosmic_config_derive::CosmicConfigEntry, CosmicConfigEntry},
cosmic_config::{self, cosmic_config_derive::CosmicConfigEntry, ConfigGet, CosmicConfigEntry},
iced::Subscription,
theme, Application,
};
@ -197,6 +197,10 @@ pub struct TabConfig {
pub show_hidden: bool,
/// Icon zoom
pub icon_sizes: IconSizes,
#[serde(skip, default = "military_time_enabled")]
/// 24 hour clock; this is neither serialized nor deserialized because we use the user's global
/// preference rather than save it
pub military_time: bool,
}
impl Default for TabConfig {
@ -206,6 +210,22 @@ impl Default for TabConfig {
folders_first: true,
show_hidden: false,
icon_sizes: IconSizes::default(),
military_time: military_time_enabled(),
}
}
}
/// Return whether the user enabled military time via the Time applet.
fn military_time_enabled() -> bool {
// Borrowed from COSMIC Greeter
match cosmic_config::Config::new("com.system76.CosmicAppletTime", 1) {
Ok(config_handler) => config_handler.get("military_time").unwrap_or_default(),
Err(err) => {
log::error!(
"failed to create CosmicAppletTime config handler: {:?}",
err
);
false
}
}
}