Skip to content

refactor: extract TrayIconCoordinator from App.xaml.cs - #818

Merged
shanselman merged 3 commits into
openclaw:mainfrom
AlexAlves87:refactor/extract-tray-icon-2
Jun 25, 2026
Merged

refactor: extract TrayIconCoordinator from App.xaml.cs#818
shanselman merged 3 commits into
openclaw:mainfrom
AlexAlves87:refactor/extract-tray-icon-2

Conversation

@AlexAlves87

@AlexAlves87 AlexAlves87 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

UpdateTrayIcon and ApplyTrayTooltip were living in App.xaml.cs. This moves them into a small dedicated TrayIconCoordinator. Pure refactor, no behavior change.

What changed

  • New Services/TrayIconCoordinator.cs: owns UpdateTrayIcon() and ApplyTrayTooltip(string).
  • App.xaml.cs: UpdateTrayIcon() now delegates to _trayIconCoordinator; ApplyTrayTooltip removed; coordinator initialized in InitializeTrayIcon.

Testing

  • ./build.ps1
  • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore
  • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore

All passing.

Proof

Hovered over the tray icon after connecting and disconnecting the gateway to exercise the extracted coordinator through UpdateTrayIcon. Tooltip rendered correctly in both states — connected and disconnected.

Grabacion.de.pantalla.2026-06-25.013309.mp4

Notes

Intentionally small. No threading changes, no logic added or removed.

Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com

@clawsweeper

clawsweeper Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed June 25, 2026, 4:24 AM ET / 08:24 UTC.

Summary
The PR moves tray icon update and tooltip logic from App.xaml.cs into a new TrayIconCoordinator and adds source-level contract tests for delegation and shutdown liveness.

Reproducibility: not applicable. this is a refactor PR rather than a bug report. The relevant behavioral check is source-verifiable: queued tray updates now check App-owned liveness before touching the TrayIcon.

Review metrics: 1 noteworthy metric.

  • Diff surface: 3 files changed, +110/-40. The branch is a small tray refactor with focused test coverage, so review can stay on the coordinator extraction and shutdown guard.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit ✨ media proof bonus
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • none.

Risk before merge

  • [P1] I did not run the repository-required build/tests or a live WinUI shutdown race because this cleanup review is read-only; GitHub Build and Test jobs were still in progress at inspection.

Maintainer options:

  1. Decide the mitigation before merge
    Land the narrow refactor after required validation finishes, keeping tray icon lifecycle ownership in App and the coordinator guarded by App's liveness state.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • No repair lane is needed; the latest head addresses the prior queued-shutdown concern, leaving normal maintainer review and validation completion.

Security
Cleared: The diff only moves tray icon code and adds source-reading tests; it does not change dependencies, workflows, secrets, permissions, install scripts, or release paths.

Review details

Best possible solution:

Land the narrow refactor after required validation finishes, keeping tray icon lifecycle ownership in App and the coordinator guarded by App's liveness state.

Do we have a high-confidence way to reproduce the issue?

Not applicable; this is a refactor PR rather than a bug report. The relevant behavioral check is source-verifiable: queued tray updates now check App-owned liveness before touching the TrayIcon.

Is this the best way to solve the issue?

Yes; the current approach is narrow and preserves the existing App lifecycle boundary while moving tray icon update and tooltip formatting into a small coordinator. The remaining requirement is validation completion, not a different code design.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 4e7982bafb86.

Label changes

Label changes:

  • add P3: This is a low-risk tray cleanup/refactor with no blocking correctness finding after the latest liveness guard.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (recording): The PR includes a GitHub-hosted MP4 recording for connected and disconnected tray tooltip hover behavior, and the attachment downloaded successfully as a valid 23-second MP4.
  • remove P2: Current review triage priority is P3, so this older priority label is no longer current.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.
  • remove merge-risk: 🚨 availability: Current PR review selected no merge-risk labels.

Label justifications:

  • P3: This is a low-risk tray cleanup/refactor with no blocking correctness finding after the latest liveness guard.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (recording): The PR includes a GitHub-hosted MP4 recording for connected and disconnected tray tooltip hover behavior, and the attachment downloaded successfully as a valid 23-second MP4.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR includes a GitHub-hosted MP4 recording for connected and disconnected tray tooltip hover behavior, and the attachment downloaded successfully as a valid 23-second MP4.
  • proof: 🎥 video: Contributor real behavior proof includes video or recording evidence. The PR includes a GitHub-hosted MP4 recording for connected and disconnected tray tooltip hover behavior, and the attachment downloaded successfully as a valid 23-second MP4.
Evidence reviewed

What I checked:

  • Latest PR head adds coordinator liveness guard: TrayIconCoordinator now checks _isAlive() before SetIcon or tooltip mutation, which preserves the current main no-op behavior after App clears the tray icon during shutdown. (src/OpenClaw.Tray.WinUI/Services/TrayIconCoordinator.cs:37, 9c8e24dda85b)
  • App wires lifecycle state into the coordinator: InitializeTrayIcon passes isAlive: () => _trayIcon != null, and shutdown clears both _trayIcon and _trayIconCoordinator next to tray disposal. (src/OpenClaw.Tray.WinUI/App.xaml.cs:736, 9c8e24dda85b)
  • Regression contract test covers the prior review concern: The added test verifies the liveness check appears before SetIcon in TrayIconCoordinator.UpdateTrayIcon. (tests/OpenClaw.Tray.Tests/AppRefactorContractTests.cs:297, 9c8e24dda85b)
  • Current main baseline checked: Current main's inlined UpdateTrayIcon queues back to App.UpdateTrayIcon and then returns early when _trayIcon is null; the PR's liveness callback preserves that shutdown boundary after extraction. (src/OpenClaw.Tray.WinUI/App.xaml.cs:2821, 4e7982bafb86)
  • Maintainer discussion followed: The maintainer review asked for retargeting to main, clearing the coordinator during tray disposal, and rerunning validation; the PR is now based on main and includes both coordinator clearing and the stronger queued-delegate liveness guard. (9c8e24dda85b)
  • Proof artifact checked: The linked GitHub attachment downloaded as a 6.81 MiB, 23-second MP4 recording; it supports the visible connected/disconnected tray-tooltip behavior described in the PR body.

Likely related people:

  • Régis Brid: git blame attributes the current InitializeTrayIcon, UpdateTrayIcon, ApplyTrayTooltip, and nearby App.xaml.cs tray baseline to 6623cb8, with recent App.xaml.cs work also at 4e7982b. (role: introduced current tray-code baseline and recent area contributor; confidence: high; commits: 6623cb8410a4, 4e7982bafb86; files: src/OpenClaw.Tray.WinUI/App.xaml.cs, tests/OpenClaw.Tray.Tests/AppRefactorContractTests.cs)
  • AlexAlves87: Prior merged history shows this contributor extracted TrayTooltipBuilder and TrayMenuStateBuilder from App.xaml.cs, which is the same refactor area this PR continues. (role: adjacent tray refactor contributor; confidence: high; commits: 24c2853d396f, 565fba8feffa; files: src/OpenClaw.Tray.WinUI/App.xaml.cs, src/OpenClaw.Tray.WinUI/Services/TrayTooltipBuilder.cs, src/OpenClaw.Tray.WinUI/Services/TrayMenuStateBuilder.cs)
  • Scott Hanselman: History shows merges of the earlier tray tooltip/menu refactors, and the PR discussion contains targeted review guidance for this shutdown path. (role: adjacent refactor merger and reviewer; confidence: medium; commits: 9f76881a9ff4, 33b537e7b591; files: src/OpenClaw.Tray.WinUI/App.xaml.cs, src/OpenClaw.Tray.WinUI/Services/TrayTooltipBuilder.cs, src/OpenClaw.Tray.WinUI/Services/TrayMenuStateBuilder.cs)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. proof: 🎥 video Contributor real behavior proof includes video or recording evidence. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. labels Jun 25, 2026
@shanselman

Copy link
Copy Markdown
Collaborator

@AlexAlves87 heads up, you're still targeting master and we moved to main because clawsweeper uses main.

@shanselman

Copy link
Copy Markdown
Collaborator

Thanks for keeping this small. One repo/process issue first: this PR is still targeting master, but main is the active branch and master was the mistaken target from the earlier Barbara PRs. Please retarget/rebase this onto main so the diff is only the TrayIconCoordinator extraction.

I did a quick local rebase check. After skipping the already-ported master-only commits, the intended diff is still just the three tray-icon files, but there is one shutdown-race fix needed before we should merge it: when the tray icon is disposed during shutdown, also clear _trayIconCoordinator next to _trayIcon = null. Otherwise a queued UpdateTrayIcon() can call through a coordinator that still holds the disposed TrayIcon instance.

Suggested fix in the tray icon shutdown step:

csharp _trayIcon?.Dispose(); _trayIcon = null; _trayIconCoordinator = null;

After that, rerun the required validation on main: ./build.ps1, Shared tests, and Tray tests.

@AlexAlves87
AlexAlves87 changed the base branch from master to main June 25, 2026 04:13
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jun 25, 2026
AlexAlves87 and others added 2 commits June 25, 2026 06:32
Moves tray icon update logic — icon path, tooltip build, tooltip apply,
and UI-thread marshalling — into a dedicated TrayIconCoordinator.
App.xaml.cs retains a one-line delegation. No behaviour change.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
A queued UpdateTrayIcon() dispatch could reach the coordinator after
TrayIcon is disposed. Nulling the coordinator in the same shutdown step
that disposes and nulls TrayIcon closes that window.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@AlexAlves87
AlexAlves87 force-pushed the refactor/extract-tray-icon-2 branch from 1b1370a to 2caddc1 Compare June 25, 2026 04:37
@AlexAlves87

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 25, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@AlexAlves87

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. and removed P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. labels Jun 25, 2026
A tray update marshalled off the UI thread can run after shutdown has
disposed the tray icon. Clearing the coordinator reference alone does not
stop an already-queued delegate, so the coordinator now checks a liveness
callback before touching the icon, restoring the no-op behaviour the
inlined code had via its null check.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. labels Jun 25, 2026
@shanselman
shanselman merged commit 1cc37fe into openclaw:main Jun 25, 2026
12 checks passed
@clawsweeper clawsweeper Bot mentioned this pull request Jun 26, 2026
17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. proof: sufficient Contributor real behavior proof is sufficient. proof: 🎥 video Contributor real behavior proof includes video or recording evidence. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants