A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.
Rust archive-managerdesktop-appdual-paneexplorer-alternativefile-browserfile-explorerfile-managerfluent-designgpu-acceleratedgpuimacosmicaproductivityquick-lookrustrust-guitabswindowswindows-11windows-explorer
Dock calendar shows Windows' additional clocks (767)
gelenmedya2b2c8dcdf88a
diff --git a/crates/rf-app/src/dock/cal_view.rs b/crates/rf-app/src/dock/cal_view.rsindex f763a0b0..3c29abdd 100644--- a/crates/rf-app/src/dock/cal_view.rs+++ b/crates/rf-app/src/dock/cal_view.rs@@ -43,10 +43,14 @@ const HEAD_H: f32 = 24.0;const TIME_H: f32 = 52.0;const LINK_H: f32 = 40.0;const GAP: f32 = 8.0;+/// A line of one of Windows' additional clocks, under the time.+const OTHER_H: f32 = 22.0;-/// The panel's height, logical px: the same whatever the month, as the grid always has six rows.+/// The panel's height, logical px: the same whatever the month, as the grid always has six rows; a line more for each of Windows'+/// additional clocks that is on (issue 767).pub fn height() -> f32 {- 2.0 * PAD + DATE_H + NAV_H + HEAD_H + 6.0 * CELL_H + TIME_H + LINK_H + 4.0 * GAP+ let others = clock::other_clocks().len() as f32;+ 2.0 * PAD + DATE_H + NAV_H + HEAD_H + 6.0 * CELL_H + TIME_H + LINK_H + 4.0 * GAP + others * OTHER_H}pub fn size() -> (f32, f32) {@@ -253,6 +257,34 @@ impl CalView {clock::format_pattern(&self.pattern, &clock::local_time(), &self.am, &self.pm)}+ /// Windows' additional clocks, a line each: the clock's name, and its time without the seconds (and the day, when it is another+ /// day there).+ fn render_others(&self, look: &Look) -> Vec<AnyElement> {+ let today = clock::local_time();+ let short = self.pattern.replace(":ss", "").replace(".ss", "");+ clock::other_clocks()+ .into_iter()+ .filter_map(|c| {+ let t = c.now()?;+ let mut when = clock::format_pattern(&short, &t, &self.am, &self.pm);+ if (t.year, t.month, t.day) != (today.year, today.month, today.day) {+ when = format!("{when} {:02}.{:02}", t.day, t.month);+ }+ Some(+ h_flex()+ .h(px(OTHER_H))+ .flex_shrink_0()+ .justify_between()+ .items_center()+ .px_2()+ .child(div().text_color(look.pal.text_secondary().hsla()).truncate().child(c.name))+ .child(div().child(when))+ .into_any_element(),+ )+ })+ .collect()+ }+// ------------------------------------------------------------------ drawing the partsfn render_nav(&self, look: &Look, lang: Lang, cx: &mut Context<Self>) -> AnyElement {@@ -429,6 +461,7 @@ impl Render for CalView {.text_color(look.pal.text().hsla()).child(self.time_text()),)+ .children(self.render_others(&look)).child(self.render_link(&look, cx));div().id("calendar-panel")diff --git a/crates/rf-win/src/dock/clock.rs b/crates/rf-win/src/dock/clock.rsindex e110e8bb..75ffa92e 100644--- a/crates/rf-win/src/dock/clock.rs+++ b/crates/rf-win/src/dock/clock.rs@@ -116,6 +116,67 @@ pub fn ms_until_next_minute(t: &ClockTime) -> u32 {(60_000 - into.min(59_999)).max(1)}+/// One of the clocks Windows shows beside its own (Settings › Time & language › Date & time › Additional clocks, at most two): its+/// name and its time zone. Issue 767: Windows' calendar showed both, the dock's calendar neither.+#[derive(Clone)]+pub struct OtherClock {+ pub name: String,+ zone: windows::Win32::System::Time::DYNAMIC_TIME_ZONE_INFORMATION,+}++/// The additional clocks that are switched on (`HKCU\Control Panel\TimeDate\AdditionalClocks\1` and `\2`), in their order. A clock+/// whose time zone Windows no longer knows is left out. A few registry reads: cheap, but not for every frame.+pub fn other_clocks() -> Vec<OtherClock> {+ let Ok(root) = windows_registry::CURRENT_USER.open(r"Control Panel\TimeDate\AdditionalClocks") else { return Vec::new() };+ ["1", "2"]+ .iter()+ .filter_map(|k| {+ let key = root.open(k).ok()?;+ if key.get_u32("Enable").ok()? == 0 {+ return None;+ }+ let name = key.get_string("DisplayName").unwrap_or_default();+ let zone = zone_named(&key.get_string("TzRegKeyName").ok()?)?;+ Some(OtherClock { name, zone })+ })+ .collect()+}++/// The time zone Windows knows by the key name `key` (`Pacific Standard Time`).+fn zone_named(key: &str) -> Option<windows::Win32::System::Time::DYNAMIC_TIME_ZONE_INFORMATION> {+ use windows::Win32::System::Time::{DYNAMIC_TIME_ZONE_INFORMATION, EnumDynamicTimeZoneInformation};+ for i in 0..1000u32 {+ let mut z = DYNAMIC_TIME_ZONE_INFORMATION::default();+ if unsafe { EnumDynamicTimeZoneInformation(i, &mut z) } != 0 {+ return None;+ }+ if crate::wide::from_wide(&z.TimeZoneKeyName).eq_ignore_ascii_case(key) {+ return Some(z);+ }+ }+ None+}++impl OtherClock {+ /// The time on this clock now.+ pub fn now(&self) -> Option<ClockTime> {+ use windows::Win32::System::SystemInformation::GetSystemTime;+ use windows::Win32::System::Time::SystemTimeToTzSpecificLocalTimeEx;+ let utc = unsafe { GetSystemTime() };+ let mut s = Default::default();+ unsafe { SystemTimeToTzSpecificLocalTimeEx(Some(&self.zone), &utc, &mut s) }.ok()?;+ Some(ClockTime {+ year: s.wYear,+ month: s.wMonth as u8,+ day: s.wDay as u8,+ hour: s.wHour as u8,+ minute: s.wMinute as u8,+ second: s.wSecond as u8,+ millisecond: s.wMilliseconds,+ })+ }+}+/// The user's local time now.pub fn local_time() -> ClockTime {use windows::Win32::System::SystemInformation::GetLocalTime;@@ -246,3 +307,24 @@ mod tests {}}}++#[cfg(test)]+mod other_clock_tests {+ /// A zone every Windows knows is found by its key name, in any case, and gives a time; a made-up one is not found.+ #[test]+ fn a_known_zone_is_found_and_tells_the_time() {+ let z = super::zone_named("utc").expect("UTC is known");+ let c = super::OtherClock { name: "UTC".into(), zone: z };+ let t = c.now().expect("a time");+ assert!(t.year >= 2024 && t.hour < 24 && t.minute < 60);+ assert!(super::zone_named("No Such Standard Time").is_none());+ }++ /// Reading the user's list never panics (here: whatever this machine has set).+ #[test]+ fn the_users_list_is_read() {+ for c in super::other_clocks() {+ assert!(c.now().is_some(), "{}", c.name);+ }+ }+}