Skip to main content

decide_bedtime

Function decide_bedtime 

Source
pub fn decide_bedtime(
    window: BedtimeWindow,
    now_min: u32,
    last_sleep_fire: Option<Instant>,
    now: Instant,
    resumed_from_suspend: bool,
) -> BedtimeAction
Expand description

Pure bedtime decision: combine the time-of-day window, the per-window interval, and the last_sleep anchor into one of three actions.

last_sleep == None always fires on the first tick of the window — the cap only kicks in for re-prompts.

resumed_from_suspend is true on the single tick that follows a wake from sleep (detected via a wall-clock jump in the run loop). The monotonic last_sleep anchor can show an arbitrarily large elapsed interval across a suspend, which would otherwise fire a stale catch-up prompt the instant the lid opens. When we’ve already prompted this window (last_sleep is Some), we demote that catch-up to ResetTimersOnly so opening the laptop mid-window stays quiet. A first entry into the window (last_sleep is None, e.g. the laptop was closed before bedtime and opened inside it) still fires normally.