refactor(tray): extract CommandCenterStateBuilder from App.xaml.cs#297
Merged
shanselman merged 1 commit intoMay 12, 2026
Merged
Conversation
18 tasks
Moves the BuildCommandCenterState cluster (11 methods, ~400 lines) into two new classes in Services/: - AppStateSnapshot: sealed record capturing the 15 App fields the cluster reads at call time (init-only, no mutation). - CommandCenterStateBuilder: receives the snapshot, exposes Build() returning GatewayCommandCenterState. App.BuildCommandCenterState() becomes a 2-line delegation call. All 11 existing callers are unchanged. The cluster is near-pure: reads App state, no shared mutations, no UI calls, no DispatcherQueue marshal. Equivalence is verifiable by comparing the DTO output field by field. Execution order including the ApplyDetectedSshForwardTopology mutation of topology in its fixed position is preserved exactly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
cafd118 to
4224c5e
Compare
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.
Context
App.xaml.cscurrently handles a range of distinct responsibilities: gateway eventrouting, tray menu construction, window lifecycle, diagnostics state assembly, update
management, and SSH tunnel orchestration, alongside its role as the WinUI 3
Applicationentry point.
This PR is the first in a series of small, incremental extractions that move cohesive
groups of logic into dedicated classes, one at a time. Each extraction leaves a thin
delegation call in
Appand does not alter observable behavior: same events, same order,same threading, same side effects.
If this direction fits the repository criteria, it would allow
App.xaml.cstoprogressively move toward its natural role in WinUI: serving primarily as an entry point
and composition root, rather than directly embedding additional responsibilities. The
extraction is designed incrementally with a criterion of observable behavioral equivalence.
Appwill continue to exist as a WinUI 3Applicationsubclass throughout this series.Each PR can be evaluated independently as a structural equivalence proof: the question to
ask is not whether this changes what the app does, but whether this code does the same
thing it did before, from a different location.
Changes
Extracts the
BuildCommandCenterStatecluster (11 methods, ~400 lines) fromApp.xaml.csinto two new classes in
Services/:AppStateSnapshot: sealed record capturing the 15Appfields the cluster reads, asinit-only properties. Captured at call time via
CaptureSnapshot()before being passedto the builder.
CommandCenterStateBuilder: receives the snapshot in the constructor, exposes a singleBuild()method returningGatewayCommandCenterState.App.BuildCommandCenterState()becomes a 2-line delegation call. All 11 existing callersare unchanged.
Equivalence
The 11 methods in the cluster are near-pure: they read
Appstate, do not mutate sharedfields, do not call UI, and do not marshal threads. Equivalence is verifiable by comparing
the DTO output field by field.
The one non-trivial ordering constraint (
ApplyDetectedSshForwardTopologymutatestopologyat a fixed position in the sequence) is preserved exactly.Validation
./build.ps1greendotnet test OpenClaw.Shared.Tests— 1442 passed, 22 skipped, 1464 totaldotnet test OpenClaw.Tray.Tests— 702 passed, 0 skipped, 702 totalCo-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com