diff --git a/daemon/src/lib.rs b/daemon/src/lib.rs index 489ffe0..1272358 100644 --- a/daemon/src/lib.rs +++ b/daemon/src/lib.rs @@ -11,6 +11,8 @@ pub struct UserData { pub theme_opt: Option, pub wallpapers_opt: Option>, pub xkb_config_opt: Option, + pub clock_military_time: bool, + // pub clock_show_seconds: bool, } #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] diff --git a/daemon/src/main.rs b/daemon/src/main.rs index a0ab282..b15e6f0 100644 --- a/daemon/src/main.rs +++ b/daemon/src/main.rs @@ -1,6 +1,6 @@ use cosmic_bg_config::Source; use cosmic_comp_config::CosmicCompConfig; -use cosmic_config::CosmicConfigEntry; +use cosmic_config::{ConfigGet, CosmicConfigEntry}; use cosmic_greeter_daemon::{UserData, WallpaperData}; use std::{env, error::Error, fs, future::pending, io, path::Path}; use zbus::{ConnectionBuilder, DBusError}; @@ -115,6 +115,8 @@ impl GreeterProxy { //TODO: should wallpapers come from a per-user call? wallpapers_opt: None, xkb_config_opt: None, + clock_military_time: false, + // clock_show_seconds: false, }; //IMPORTANT: Assume the identity of the user to ensure we don't read wallpaper file data as root @@ -208,6 +210,21 @@ impl GreeterProxy { log::error!("failed to create cosmic-comp config handler: {}", err); } }; + + match cosmic_config::Config::new("com.system76.CosmicAppletTime", 1) { + Ok(config_handler) => { + user_data.clock_military_time = + config_handler.get("military_time").unwrap_or_default(); + // user_data.clock_show_seconds = + // config_handler.get("show_seconds").unwrap_or_default(); + } + Err(err) => { + log::error!( + "failed to create CosmicAppletTime config handler: {:?}", + err + ); + } + }; }) .map_err(|err| GreeterError::RunAsUser(err.to_string()))?; diff --git a/src/greeter.rs b/src/greeter.rs index 48f1922..f828ecd 100644 --- a/src/greeter.rs +++ b/src/greeter.rs @@ -110,6 +110,8 @@ fn user_data_fallback() -> Vec { theme_opt: None, wallpapers_opt: None, xkb_config_opt: None, + clock_military_time: false, + // clock_show_seconds: false, } }) .collect() @@ -1025,7 +1027,20 @@ impl cosmic::Application for App { column = column .push(widget::text::title2(format!("{}", date)).style(style::Text::Accent)); - let time = dt.format_localized("%R", locale); + // xxx It may be prudent to store the index of the selected user to avoid + // searches. This would also simplify logic elsewhere. + let time = if self + .flags + .user_datas + .binary_search_by(|probe| probe.name.cmp(&self.selected_username)) + .ok() + .map(|i| self.flags.user_datas[i].clock_military_time) + .unwrap_or_default() + { + dt.format_localized("%R", locale) + } else { + dt.format_localized("%I:%M %P", locale) + }; column = column.push( widget::text(format!("{}", time)) .size(112.0)