fix: re-apply the theme after missed boundaries - #24
Merged
Merged
Conversation
The theme could stay wrong after the machine slept across two boundaries, and a long checkIntervalMs delayed or skipped switches. A new exact helper, nextPeriodChange, finds the next day/night change; tui uses it to detect crossings since the last check and to arm a one-shot timer at the next boundary.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Fixes cases where the theme didn't switch, or switched late (audit item H3):
/themefrom before sleep was kept, e.g. sleeping from evening until the next evening.checkIntervalMs: switches waited for the next tick. At 24h the theme never switched, and at 13h some periods were skipped entirely.Changes:
nextPeriodChange(from, cfg, horizonMs). It returns the exact next day/night change by checking only the instants where one can happen: 15-minute UTC marks in fixed mode, and each solar day's start, sunrise and sunset in solar mode. So even very short periods near the polar circle are found (for example a 2-minute night at 66.34°N).tuiremembers when it last checked the period. It re-applies the theme if any boundary was crossed since then, even when the period now looks unchanged (looking back up to 400 days).checkIntervalMsis. The interval stays as a fallback. The timer is cleared on abort/dispose.checkIntervalMsrow are updated (this also fixes the README part of audit item L5).Behavior impact
periodFor, boundaries, gentle override)dayTheme,nightTheme,dayStartHour,nightStartHour,checkIntervalMs,toast) — README options table updatedpackage.jsonexports,files, published contents)After waking up past a boundary, a manual
/themeis now replaced by the configured theme for the current period. Within a period it is still kept.Testing
npm run typecheckpassesnpm testpasses: 56 tests (11 newnextPeriodChangeunit tests, 7 newtuitests). Also passes underTZset to UTC, Europe/London, America/St_Johns, Australia/Lord_Howe, Asia/Kathmandu, Pacific/Chatham and America/New_York.Extra checks:
nextPeriodChangeagainst a 30-second scan for 246 configs over all of 2026: 0 mismatches.Checklist
(enforced by the PR Title check; drives the release-please version bump)