Refactor update workflow into UpdateController - #49
Closed
Balragon wants to merge 1 commit into
Closed
Conversation
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>
This was referenced Jul 3, 2026
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>
Owner
Author
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 was extracted
MainWindow.cs(3,856 lines) owned the entire update workflow. This PR moves the orchestration into a newMacMirrorReceiver/UpdateController.cs: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.MainWindow: all WPF control access. It implements a newIUpdateNoticeViewinterface (notice text/visibility, button enable/content,SetStatus) and builds the download-progress text for the notice button.ShutdownApplicationAsyncis injected as aFunc<Task>.UpdateService,UpdateLauncher,SettingsWindowUI andISettingsHost(its update members now just delegate to the controller). Video/audio/firewall/fullscreen code untouched.No behavior change
UpdateLauncher.Launch(still/SILENT ... /IMIRROR_LAUNCH=1), the controller awaits the injected graceful shutdown so the installer can replace files and relaunch iMirror.UpdateService.DownloadSetupAsyncis reused as-is.[Unreleased]only.Testing
The controller takes injected delegates (check/download/launch/shutdown/notice policy/clock), so it runs without WPF. Added 18
UpdateControllerunit 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