Respect user config for military time

Closes: #96
This commit is contained in:
Josh Megnauth 2024-08-29 03:23:40 -04:00
parent ff03667847
commit 912017615c
No known key found for this signature in database
GPG key ID: 70813183462EFAD3
3 changed files with 36 additions and 2 deletions

View file

@ -11,6 +11,8 @@ pub struct UserData {
pub theme_opt: Option<Theme>,
pub wallpapers_opt: Option<Vec<(String, WallpaperData)>>,
pub xkb_config_opt: Option<XkbConfig>,
pub clock_military_time: bool,
// pub clock_show_seconds: bool,
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]

View file

@ -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()))?;

View file

@ -110,6 +110,8 @@ fn user_data_fallback() -> Vec<UserData> {
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)