Skip to content

Hide tray icon natively (drop P/Invoke into Avalonia internals) - #500

Merged
mgth merged 1 commit into
masterfrom
fix/hide-tray-icon-native
Jul 9, 2026
Merged

Hide tray icon natively (drop P/Invoke into Avalonia internals)#500
mgth merged 1 commit into
masterfrom
fix/hide-tray-icon-native

Conversation

@mgth

@mgth mgth commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Follow-up to #472. The "hide tray icon" option works, but its implementation used Shell_NotifyIcon P/Invoke + reflection into Avalonia's internal TrayIconImpl (_impl / _uniqueId / Win32Platform) — Windows-only code in the cross-platform UI, and fragile across Avalonia versions.

What changes

  • HLab.Core: IUserNotificationService gains a Visible property.
  • HLab.Avalonia: implemented with Avalonia's public TrayIcon.IsVisible (mapped to NIM_ADD/NIM_DELETE per 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.
  • MainService: just sets _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

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>
@mgth
mgth merged commit 3b8a6fa into master Jul 9, 2026
1 check 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.

1 participant