Skip to content

Refactor update workflow into UpdateController - #49

Closed
Balragon wants to merge 1 commit into
mainfrom
codex/refactor-update-controller
Closed

Refactor update workflow into UpdateController#49
Balragon wants to merge 1 commit into
mainfrom
codex/refactor-update-controller

Conversation

@Balragon

@Balragon Balragon commented Jul 3, 2026

Copy link
Copy Markdown
Owner

What was extracted

MainWindow.cs (3,856 lines) owned the entire update workflow. This PR moves the orchestration into a new MacMirrorReceiver/UpdateController.cs:

  • Moved to UpdateController: startup update check (including the 1.5s delay, single-run guard, and shutdown guard), manual check (CheckForUpdatesAsync), the automatic-notice policy calls (ReceiverSettings.ShouldShowAutomaticUpdateNotice / MarkUpdateNoticeShown / DismissUpdateNotice), pending-update state, and the download → installer launch → graceful shutdown sequence.
  • Kept in MainWindow: all WPF control access. It implements a new IUpdateNoticeView interface (notice text/visibility, button enable/content, SetStatus) and builds the download-progress text for the notice button. ShutdownApplicationAsync is injected as a Func<Task>.
  • Unchanged: UpdateService, UpdateLauncher, SettingsWindow UI and ISettingsHost (its update members now just delegate to the controller). Video/audio/firewall/fullscreen code untouched.

No behavior change

  • Same call order, same UI strings, same status messages, same log lines, same error handling (retry state on failure, no shutdown unless the installer actually launched).
  • Close iMirror during silent update handoff #48 handoff preserved: after UpdateLauncher.Launch (still /SILENT ... /IMIRROR_LAUNCH=1), the controller awaits the injected graceful shutdown so the installer can replace files and relaunch iMirror.
  • SHA-256 fail-closed verification untouched: UpdateService.DownloadSetupAsync is reused as-is.
  • No version bump, no tag, no release; CHANGELOG entry added under [Unreleased] only.

Testing

The controller takes injected delegates (check/download/launch/shutdown/notice policy/clock), so it runs without WPF. Added 18 UpdateController unit tests covering the startup-notice policy, manual vs automatic checks, install success (launch-then-shutdown ordering), download/launch failure paths, and dismiss persistence. All existing tests (incl. UpdateLauncherTests) still pass.

Validation

  • dotnet build iMirror.sln -c Release — passed, 0 warnings, 0 errors.
  • dotnet test MacMirrorReceiver.Tests\MacMirrorReceiver.Tests.csproj -c Release — passed: 83 tests (65 existing + 18 new), 0 failed.

🤖 Generated with Claude Code

Move the update orchestration out of MainWindow into a new
UpdateController: startup/manual update checks, the automatic-notice
policy, download, installer handoff, and the graceful shutdown from #48.
MainWindow keeps only the WPF concerns (update-notice controls, status
text, download-progress text) behind a new IUpdateNoticeView seam, and
ISettingsHost/SettingsWindow are unchanged apart from delegating to the
controller.

UpdateService (SHA-256 fail-closed download) and UpdateLauncher
(/IMIRROR_LAUNCH=1 silent handoff) are reused as-is; no behavior change.
The controller takes injected delegates so it is unit-testable without
WPF; adds 18 UpdateController tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Balragon added a commit that referenced this pull request Jul 3, 2026
)

* Refactor update workflow into UpdateController

Move the update orchestration out of MainWindow into a new
UpdateController: startup/manual update checks, the automatic-notice
policy, download, installer handoff, and the graceful shutdown from #48.
MainWindow keeps only the WPF concerns (update-notice controls, status
text, download-progress text) behind a new IUpdateNoticeView seam, and
ISettingsHost/SettingsWindow are unchanged apart from delegating to the
controller.

UpdateService (SHA-256 fail-closed download) and UpdateLauncher
(/IMIRROR_LAUNCH=1 silent handoff) are reused as-is; no behavior change.
The controller takes injected delegates so it is unit-testable without
WPF; adds 18 UpdateController tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Harden update download lifecycle: cleanup and shutdown cancellation

Two fixes to the update workflow, built on the UpdateController
extraction (#49):

1. Downloaded installers were never deleted, so
   %LOCALAPPDATA%\iMirror\Updates grew by one setup.exe per update
   forever. UpdateService.TryCleanUpDownloadedInstallers now removes
   leftover .exe/.download files at startup (best-effort; files locked
   by a still-running installer are skipped until the next start).

2. Update checks and installer downloads used CancellationToken.None,
   so an in-flight download raced process teardown when the user closed
   the app. UpdateController now owns a shutdown CancellationTokenSource
   that MainWindow cancels at the start of ShutdownApplicationAsync; a
   canceled install returns quietly without flashing the retry UI.

The SHA-256 fail-closed verification and the #48 installer handoff
(launch installer, then graceful shutdown, relaunch via
/IMIRROR_LAUNCH=1) are unchanged. Adds 7 tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
@Balragon

Balragon commented Jul 3, 2026

Copy link
Copy Markdown
Owner Author

Superseded by #51, which was stacked on this branch and squash-merged with this refactoring included — main now contains the full UpdateController extraction (cb66524). Nothing left to merge here.

@Balragon Balragon closed this Jul 3, 2026
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.

1 participant