Skip to content

gui.tray: tray icon for native apps - #3728

Merged
BaseMax merged 7 commits into
mainfrom
feat/gui-tray
Nov 21, 2026
Merged

BaseMax merged 7 commits into
mainfrom
feat/gui-tray

Conversation

@BaseMax

@BaseMax BaseMax commented Nov 21, 2026

Copy link
Copy Markdown
Member

New std/gui/tray package: tray or menu bar icon with a menu, click events and a thread-safe event queue, for apps on gui.window/gui.ui (until now only the webview package had a tray).

  • Linux: StatusNotifierItem + dbusmenu over D-Bus (KDE, GNOME with AppIndicator, XFCE, waybar...)
  • Windows: Shell_NotifyIconW on its own thread
  • macOS: NSStatusItem, main thread only (compile-checked only)

Also adds Window.Hide/Show/IsVisible and ui.OnCloseRequest/HideWindow/ShowWindow so closing the window can hide the app to the tray.

Linux checked end to end against a fake watcher on a private bus, Windows under wine. Docs page 189.

@BaseMax
BaseMax requested a review from a team as a code owner November 21, 2026 04:41
@BaseMax
BaseMax merged commit 73e1f10 into main Nov 21, 2026
2 checks passed
@BaseMax
BaseMax deleted the feat/gui-tray branch November 21, 2026 04:42
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

Copy link
Copy Markdown
Contributor
sha=d370874b4879ee91fcbbb172d15360abb6a4e97c

🤖 Salam AI review

Verdict: 🛠️ Changes needed before merging

commit d370874 · 37 files · +2640 −2 · model salam

Summary

This PR adds a new std/gui/tray package providing a system tray/menu bar icon with a menu, click events and a thread-safe event queue, with Linux (StatusNotifierItem/D-Bus), Windows (Shell_NotifyIconW) and macOS (NSStatusItem) backends, plus Window.Hide/Show/IsVisible and ui close-to-tray hooks. The implementation is large and broadly follows the project's conventions, but the icon loading path mutates stored state before validating the file, so a failed read can discard a previously working icon.

What changed

A new std/gui/tray package (English and Persian) with Item, Event, EventKind, Show, SetMenu, SetTooltip, SetIcon, Hide, IsShown, SetWake, Post, Take, Pending, plus helpers. Platform backends live in linux.salam, windows.salam, macos.salam and none.salam. gui.window gains Hide/Show/IsVisible (and a hidden field plus visible option), and gui.ui gains OnCloseRequest/HideWindow/ShowWindow/WindowVisible with close handling in run.salam. Tests, docs (page 189) and examples are added.

Review

  1. std/gui/tray/tray.salam, _load_icon: it frees _icon and reassigns _icon_path to the new (possibly unreadable) path before attempting image.OpenPNG, returning false on failure. That discards the previously loaded icon and leaves _icon_path pointing at a bad file, contradicting the "keep state when the icon is unreadable" commit. Validate first (decode into a temporary, only commit _icon/_icon_path on success), and on failure leave prior state untouched.
  2. std/gui/tray/tray.salam, Show: on a failed _load_icon it returns false after _icon/_icon_path have already been mutated, and _tooltip/_items are only updated afterwards, so a failed show can leave a half-updated tray. Apply the same validate-then-commit ordering here.
  3. std/gui/window/window.salam, IsVisible: ret _alive(this.id) and not _wins[this.id].hidden. This relies on short-circuit evaluation of and; if Salam does not short-circuit, indexing _wins for a closed window is out of range. Please confirm the language guarantees short-circuit and/or (or guard with an explicit if).
  4. std/gui/ui/run.salam: the new close branch calls _close_hook() only when _close_set is true, which is correct, but _close_hook defaults to returning true; verify that a hook registered via OnCloseRequest that returns false keeps the page running as documented (the test only checks the no-window path).
  5. std/gui/tray/macos.salam: _os_apply runs on the caller's thread and touches AppKit directly; the docs say calls must be made from the main thread. There is no guard or assertion, so a call from a worker thread will crash with no diagnostic. Consider documenting or asserting the main-thread requirement.
  6. std/gui/tray/windows.salam, _wt_thunk: the x86 thunk is hand-assembled; on 64-bit targets _wt_thunk is identity, but salam_tray_w32_proc is exported with stdcall-style calling. Confirm the calling convention matches on both architectures (the diff cannot show the compiler's handling).

Tests

The added tests/en/stdlib/gui_tray.salam and its Persian counterpart exercise the event queue, wake callback, window hide/show and the ui close hook, with matching .out files. Coverage of the unreadable-icon keep-state behaviour and of SetIcon failure recovery is not visible in the test; adding a case would lock in the fix for finding 1.

Risks

The icon-state mutation (findings 1-2) is the main functional risk: a transient unreadable icon path can permanently blank the tray icon until the process restarts. The platform backends are large FFI surfaces that cannot be compile-checked here for the non-Linux targets beyond what CI provides; macOS in particular is "compile-checked only" per the PR. If the diff was truncated for any of windows.salam/macos.salam, those parts were not fully reviewed.


⚠️ This review was written automatically by an AI and may contain mistakes. It is a helper for maintainers, not a replacement for a human review: check the code yourself before merging.

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