Skip to content

Fix scheduling across timezones and multiple displays - #723

Open
t1m0thyj wants to merge 14 commits into
mainfrom
codex-fixes
Open

t1m0thyj wants to merge 14 commits into
mainfrom
codex-fixes

Conversation

@t1m0thyj

@t1m0thyj t1m0thyj commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Fix scheduling failures that could select the wrong solar day, repeatedly trigger timers, or leave wallpapers inconsistent after concurrent updates and display changes.

Changes:

  • Preserve the selected location’s UTC offset when calculating solar times, including adjacent-day calculations across DST gaps.
  • Schedule 12-hour shuffles from the last shuffle and monthly shuffles at the next month boundary.
  • Serialize scheduler runs and display-list updates to keep wallpaper writes and cached paths consistent.
  • Handle early display notifications and missing lock-screen sync entries safely.
  • Expand and validate per-display CLI selections while preserving other displays’ themes.
  • Keep sunrise scheduled during dawn and refresh surviving displays after monitor-count changes.

Validation:

  • 14 unit tests passed, including seven new SunriseSunset regression cases.
  • Release build passed with zero warnings or errors.
  • Temporary harness checks passed for concurrency, shuffle deadlines, lock-screen sync, startup notifications, CLI selection, and display removal/reconnection.
  • A simulated-clock sweep passed 140 geographic, polar, and DST boundary cases.

How to test:

dotnet test test/WinDynamicDesktop.Tests.csproj --filter "type!=system"
dotnet build src/WinDynamicDesktop.csproj -c Release

Manual checks:

  1. Select Tokyo or Auckland while Windows uses a different timezone; confirm sunrise/sunset dates and preview timing.
  2. Enable manual scheduling with 12-hour shuffling. Confirm one overdue shuffle completes without repeated timer activity or elevated CPU usage.
  3. With the app running, use /theme:2=<theme-id> from an “All Displays” configuration. Confirm display 1 retains its theme and invalid display numbers are rejected.
  4. Sync the lock screen with display 2, select None for all displays, then reapply a display theme. Confirm scheduling continues and sync resumes.
  5. Disconnect and reconnect a monitor with distinct per-display themes. Confirm surviving displays refresh correctly.
  6. Change themes around a scheduled transition; confirm the latest selection remains displayed.
  7. With a sunrise-triggered script enabled, confirm its transition occurs at sunrise while the wallpaper is already in its dawn segment.

Physical hotplug, live Windows timezone changes, and interactive UI checks remain to be exercised.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Active moderate issues remain in both production timer synchronization and test independence, so the change is not yet ready for approval.

2 open issues
What changed in this PR

This pull request improves wallpaper scheduling across time zones, daylight-saving transitions, shuffle intervals, concurrent scheduler activity, and multi-display configurations.

Changes:

  • Preserve location timezone offsets and handle DST boundary calculations for solar scheduling.
  • Correct 12-hour and monthly shuffle deadlines, including sunrise behavior during dawn.
  • Serialize scheduler and display updates while improving display hotplug recovery and cached wallpaper consistency.
  • Validate per-display CLI selections and improve lock-screen synchronization, restart handling, and power/session notifications.
  • Add regression coverage for timezone, dawn, and DST-gap scenarios.
File Summary Review Notes
test/​SunCalcTests.cs Adds timezone, dawn, and DST regression tests. The DST-gap expected value is derived from the implementation under test and should be computed independently.
src/​UpdateChecker.cs Documents Windows application-restart registration behavior. No findings reported.
src/​ThemeShuffler.cs Corrects 12-hour and monthly shuffle deadlines. No findings reported.
src/​SunriseSunset.cs Preserves the selected location’s UTC offset during solar calculations. No findings reported.
src/​SolarScheduler.cs Keeps sunrise scheduled as the next update during dawn. No findings reported.
src/​IpcManager.cs Validates per-display theme selections while preserving other displays. No findings reported.
src/​HiddenForm.cs Improves restart registration and session-end handling. No findings reported.
src/​EventScheduler.cs Serializes scheduler operations and refreshes display state after changes. Timer callbacks are not coalesced while waiting for the scheduler lock, and the deadline check/rearm sequence is not atomic under the lock.
src/​COM/​PowerSetting.cs Safely handles session display-status notifications and payload validation. No findings reported.

Review effort: Lite

Comment thread src/EventScheduler.cs
Comment on lines +306 to 321
if (e.Mode != PowerModes.Resume)
{
return;
}

if (UpdateDisplayList() || (nextUpdateTime.HasValue && DateTime.Now >= nextUpdateTime.Value))
{
LoggingHandler.LogMessage("Scheduler event triggered by resume from sleep");
HandleTimerEvent(false);
}
else if (nextUpdateTime.HasValue)
{
// Relative timers exclude sleep time, so rearm even when the deadline is still in the future.
StartTimer(nextUpdateTime.Value);
}
}
Comment thread test/SunCalcTests.cs Outdated

SolarData data = SunriseSunsetService.GetSolarData(transitionDate);
SunriseSunsetService.GetDateTimeNow = () => transitionDate.AddHours(12);
SolarData expected = SunriseSunsetService.GetSolarData(transitionDate);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants