Skip to content

refactor: extract CopyDiagnostic helper for diagnostic copy methods#336

Merged
shanselman merged 1 commit into
openclaw:masterfrom
AlexAlves87:refactor/extract-copy-diagnostic-helper
May 13, 2026
Merged

refactor: extract CopyDiagnostic helper for diagnostic copy methods#336
shanselman merged 1 commit into
openclaw:masterfrom
AlexAlves87:refactor/extract-copy-diagnostic-helper

Conversation

@AlexAlves87
Copy link
Copy Markdown
Contributor

Summary

App.xaml.cs had nine diagnostic copy methods that each repeated the
same 13-line body: build a DataPackage, call the appropriate
CommandCenterTextHelper formatter, write to clipboard, and log success
or failure. This extracts that repeated structure into a single private
CopyDiagnostic helper and reduces each method to a one-liner.

What changed

  • Added CopyDiagnostic(string label, Func<GatewayCommandCenterState, string> format) as a private instance method in App.xaml.cs
  • The helper reuses the existing CopyTextToClipboard static already present in the file
  • All nine methods are now expression-bodied one-liners; signatures are unchanged (they are exposed as Action delegates in DeepLinkActions)
  • Log messages preserved exactly

Testing

  • dotnet build src/OpenClaw.Tray.WinUI/OpenClaw.Tray.WinUI.csproj -r win-x64 --nologo
  • Manual: tray menu → Support & Debug → Copy Support Context, Copy Port Diagnostics, Copy Node Inventory — pasted output matches previous

Notes

No behaviour change. The one subtle difference worth noting: exceptions thrown inside BuildCommandCenterState() are now caught by the helper's try/catch, which was already the case in each of the original per-method try/catch blocks.

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

Nine structurally identical Copy* methods (CopySupportContext,
CopyDebugBundle, CopyBrowserSetupGuidance, CopyPortDiagnostics,
CopyCapabilityDiagnostics, CopyNodeInventory, CopyChannelSummary,
CopyActivitySummary, CopyExtensibilitySummary) each repeated the same
DataPackage + Clipboard.SetContent boilerplate alongside identical
try/catch logging. This replaces all nine bodies with a single private
CopyDiagnostic(string label, Func<GatewayCommandCenterState, string>)
helper and reduces each method to an expression-bodied one-liner.

No observable behavior change: log messages, clipboard content, error
handling, and method signatures (exposed as Action delegates in
DeepLinkActions) are all preserved exactly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@shanselman
Copy link
Copy Markdown
Contributor

Fantastic! Thanks for preventing slop @AlexAlves87

@shanselman shanselman merged commit 776d723 into openclaw:master May 13, 2026
16 checks passed
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