diff --git a/src/widgets.rs b/src/widgets.rs index 155bd85..1d2a4cc 100644 --- a/src/widgets.rs +++ b/src/widgets.rs @@ -8,8 +8,8 @@ fn run_cmd(cmd: &str) -> Option { Command::new(cmd).spawn().ok() } -fn format_time() -> String { - Local::now().format("%I:%M %p").to_string() +fn format_time() -> SharedString { + SharedString::from(Local::now().format("%I:%M %p").to_string()) } fn time_until_next_minute() -> Duration { @@ -31,21 +31,21 @@ fn start_clock_updater(ui: &TopBar) { // 1. Initial immediate update if let Some(ui) = weak.upgrade() { - ui.set_time_text(SharedString::from(format_time())); + ui.set_time_text(format_time()); } // 2. Schedule first update exactly at next minute boundary initial_timer.start(TimerMode::SingleShot, time_until_next_minute(), move || { // Update at the boundary if let Some(ui) = weak.upgrade() { - ui.set_time_text(SharedString::from(format_time())); + ui.set_time_text(format_time()); } // 3. Start repeating 60-sec timer let weak_clone = weak.clone(); repeating_timer.start(TimerMode::Repeated, Duration::from_secs(60), move || { if let Some(ui) = weak_clone.upgrade() { - ui.set_time_text(SharedString::from(format_time())); + ui.set_time_text(format_time()); } }); }); @@ -54,7 +54,7 @@ fn start_clock_updater(ui: &TopBar) { pub fn install_callbacks(ui: &TopBar) { let weak = ui.as_weak(); - // Click handler + // Click handler ui.on_show_clock(move || { if weak.upgrade().is_some() { run_cmd("xclock");