Skip to content

Commit 1c362eb

Browse files
committed
fix: use checked_sub for update check timer to avoid panic on low uptime
1 parent 1bf4e66 commit 1c362eb

1 file changed

Lines changed: 7 additions & 33 deletions

File tree

src/main.rs

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,12 @@ fn run() -> Result<()> {
9898
}
9999
}
100100

101-
// Schedule first update check
102-
let mut last_update_check =
103-
Instant::now() - Duration::from_secs(config.updater.check_interval_h as u64 * 3600);
101+
// Schedule first update check.
102+
// Use checked_sub so we don't panic on systems with uptime shorter than the interval.
103+
// If the subtraction underflows we fall back to now(), meaning the first check happens
104+
// after one full interval rather than immediately — that's fine.
105+
let interval = Duration::from_secs(config.updater.check_interval_h as u64 * 3600);
106+
let mut last_update_check = Instant::now().checked_sub(interval).unwrap_or_else(Instant::now);
104107

105108
main_loop(
106109
cmd_rx,
@@ -347,33 +350,4 @@ fn main_loop(
347350
Cmd::Exit => {
348351
// Restore everything cleanly before exiting
349352
let mut state = state_shared.lock().unwrap();
350-
profiles::restore_all(&mut state);
351-
return Ok(());
352-
}
353-
354-
Cmd::UpdateAvailable(version) => {
355-
let cfg = config_shared.lock().unwrap().clone();
356-
notifications::notify_update_available(&version, &cfg.notifications);
357-
eprintln!("Update available: {version}");
358-
}
359-
360-
Cmd::HotkeyFailed(hotkey) => {
361-
let cfg = config_shared.lock().unwrap().clone();
362-
notifications::notify_hotkey_failed(&hotkey, &cfg.notifications);
363-
}
364-
}
365-
}
366-
}
367-
}
368-
369-
/// Update Discord Rich Presence if enabled.
370-
fn update_discord(state: &AppState, config: &AppConfig) {
371-
if config.discord.enabled {
372-
discord::set_rich_presence(
373-
state.icons_hidden,
374-
state.taskbar_hidden,
375-
state.windows_hidden,
376-
state.active_profile.clone(),
377-
);
378-
}
379-
}
353+
profiles::restor

0 commit comments

Comments
 (0)