Hide tray icon natively (drop P/Invoke into Avalonia internals) - #500
Merged
Conversation
Follow-up to #472. The hide-tray-icon option worked, but its implementation used Shell_NotifyIcon P/Invoke plus reflection into Avalonia's internal TrayIconImpl (_impl / _uniqueId / Win32Platform) — Windows-only code sitting in the cross-platform UI, and fragile across Avalonia versions. Move it behind the notification abstraction instead: IUserNotificationService gains a Visible property (HLab.Core), implemented with Avalonia's public TrayIcon.IsVisible (HLab.Avalonia), which maps to NIM_ADD/NIM_DELETE per OS. The one real subtlety — a daemon state-change icon refresh re-adding a hidden icon — is handled cleanly by holding icon updates while hidden and reapplying on show. MainService now just sets _notify.Visible; no reflection, no P/Invoke, nothing Windows-specific in the UI (keeps the Linux port on track). Bumps HLab.Core and HLab.Avalonia submodules. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Follow-up to #472. The "hide tray icon" option works, but its implementation used
Shell_NotifyIconP/Invoke + reflection into Avalonia's internalTrayIconImpl(_impl/_uniqueId/Win32Platform) — Windows-only code in the cross-platform UI, and fragile across Avalonia versions.What changes
IUserNotificationServicegains aVisibleproperty.TrayIcon.IsVisible(mapped toNIM_ADD/NIM_DELETEper OS). Icon updates are held while hidden and reapplied on show, so a daemon state-change refresh can't re-add a hidden icon — the one real subtlety, handled without touching Avalonia internals._notify.Visible; no reflection, no P/Invoke, nothing Windows-specific left in the UI (keeps the Linux port on track).Net: +7 / −79 in the main repo (the 72-line P/Invoke block is gone). Bumps the HLab.Core / HLab.Avalonia submodules.
Runtime check
Toggle "Hide tray icon" → icon hides/shows; while hidden, daemon state changes (Running/Stopped) must not re-show it.
🤖 Generated with Claude Code