Minor refactoring
- Return `SharedString` from `format_time()` - Avoid repetition
This commit is contained in:
parent
c878c7f678
commit
5b79941341
@ -8,8 +8,8 @@ fn run_cmd(cmd: &str) -> Option<Child> {
|
||||
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());
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user