gogpu/systray 是一个托管在 GitHub 上的开源项目,主要使用 Go 编写,采用 MIT License 许可证,目前获得 87 个 Star、17 次 Fork。
仓库全名
gogpu/systray
README 摘要
systray Pure Go system tray library for Windows, macOS, and Linux Zero CGO. Cross-platform. Multiple trays. Context menus. Notifications. Features Pure Go — zero CGO on all platforms. Single binary, easy cross-compilation Multiple trays — create as many tray icons as you need Context menus — nested menus with checkboxes, separators, icons, and submenus Notifications — balloon tips (Windows), notification center…
Add, AddCheckbox, AddSubmenu, AddWithIcon return *MenuItem for dynamic updates. AddSeparator returns *Menu for chaining.
Dynamic Menu Updates
Update menu items at runtime from any goroutine — thread-safe, changes are applied in-place via native platform APIs (no menu rebuild). On macOS, updates are automatically dispatched to the main thread:
item.SetLabel("New Label") // Change display text
check.SetChecked(false) // Change checked state
sub.SetDisabled(true) // Disable/enable
icon.SetIcon(newIconPNG) // Change icon
// Thread-safe getters
if check.IsChecked() { ... } // Read current state
if sub.IsDisabled() { ... }
Multiple Trays
// Each tray is independent with its own icon, menu, and handlers
mainTray := systray.New().SetIcon(appIcon).SetMenu(mainMenu).Show()
statusTray := systray.New().SetIcon(statusIcon).SetTooltip("Status: OK").Show()
Dark Mode
systray supports automatic icon switching based on the system theme.
Windows — Use SetDarkModeIcon() to provide an alternative icon for dark mode. The library detects theme changes via WM_SETTINGCHANGE with "ImmersiveColorSet" and switches icons automatically:
tray.SetIcon(lightIcon).SetDarkModeIcon(darkIcon)
macOS — Use SetTemplateIcon() with a monochrome PNG. macOS renders template images with the correct color for the current menu bar appearance (light or dark). Only the alpha channel matters:
tray.SetTemplateIcon(monochromeIcon)
Linux — The SNI protocol delivers the icon pixmap to the desktop environment, which handles theme adaptation. No special API is needed.
Notifications
ShowNotification sends an OS-level notification from the tray icon:
tray.ShowNotification("Update Available", "Version 2.0 is ready to install.")
Platform
Mechanism
Notes
Windows
Balloon tip (Shell_NotifyIconW + NIF_INFO)
Appears near the tray icon
macOS
NSUserNotification / Notification Center
Requires notification permission on macOS 13+
Linux
org.freedesktop.Notifications D-Bus
Works on GNOME, KDE, XFCE, and other FreeDesktop-compliant DEs
Icon Guidelines
Platform
Recommended Size
Format
Notes
Windows
16x16, 32x32
PNG
Provide both sizes for standard and HiDPI
macOS
22x22, 44x44 (@2x)
PNG
Must be monochrome (template) for proper theme adaptation
Linux
22x22, 24x24
PNG
SNI spec recommends 22x22
Input format: PNG bytes ([]byte). The library handles conversion to native format (HICON, NSImage, ARGB pixmap) internally.
For macOS, use SetTemplateIcon() with a monochrome PNG (only alpha channel matters). The system automatically adjusts the icon color for light/dark menu bar.
Follows the Qt6 QPlatformSystemTrayIcon three-layer pattern. Each platform implementation is isolated in its own file with build constraints.
Usage with gogpu
While systray is fully standalone, it integrates with the gogpu application framework. systray runs its own message loop via Run(), or you can manage the lifecycle manually alongside gogpu’s event loop:
We welcome contributions! See CONTRIBUTING.md for guidelines.
Part of the GoGPU Ecosystem
systray is part of the GoGPU ecosystem — 1.2M+ lines of Pure Go, zero CGO. A GPU computing platform with a WebGPU implementation, shader compiler, 2D graphics library, and GUI toolkit.
评论