Documentation
¶
Overview ¶
Package systray provides a cross-platform system tray (notification area) library for Go applications. It supports Windows, macOS, and Linux with zero CGO dependencies.
Key features:
- Multiple independent tray icons per application
- Context menus with nested submenus, checkboxes, and separators
- OS-level notifications (balloon tips, notification center, D-Bus)
- Dark mode icon switching and macOS template images
- Builder pattern for fluent API
Platform implementations:
- Windows: Shell_NotifyIconW via golang.org/x/sys/windows
- macOS: NSStatusBar/NSStatusItem via go-webgpu/goffi ObjC runtime
- Linux: StatusNotifierItem (SNI) via godbus/dbus D-Bus protocol
Quick start:
tray := systray.New()
tray.SetIcon(iconPNG).SetTooltip("My App").SetMenu(menu).Show()
Part of the GoGPU ecosystem: https://github.com/gogpu
Index ¶
- Constants
- type Menu
- func (m *Menu) Add(label string, onClick func()) *MenuItem
- func (m *Menu) AddCheckbox(label string, checked bool, onClick func()) *MenuItem
- func (m *Menu) AddSeparator() *Menu
- func (m *Menu) AddSubmenu(label string, submenu *Menu) *MenuItem
- func (m *Menu) AddWithIcon(label string, icon []byte, onClick func()) *MenuItem
- type MenuItem
- type MenuItemType
- type SystemTray
- func (t *SystemTray) Bounds() (x, y, w, h int)
- func (t *SystemTray) Hide() *SystemTray
- func (t *SystemTray) ID() TrayID
- func (t *SystemTray) OnClick(fn func()) *SystemTray
- func (t *SystemTray) OnDoubleClick(fn func()) *SystemTray
- func (t *SystemTray) OnRightClick(fn func()) *SystemTray
- func (t *SystemTray) Remove()
- func (t *SystemTray) Run() error
- func (t *SystemTray) SetDarkModeIcon(png []byte) *SystemTray
- func (t *SystemTray) SetIcon(png []byte) *SystemTray
- func (t *SystemTray) SetMenu(menu *Menu) *SystemTray
- func (t *SystemTray) SetTemplateIcon(png []byte) *SystemTray
- func (t *SystemTray) SetTooltip(text string) *SystemTray
- func (t *SystemTray) Show() *SystemTray
- func (t *SystemTray) ShowNotification(title, message string) *SystemTray
- type TrayID
Constants ¶
const ( MenuItemNormal = internal.MenuItemNormal MenuItemCheckbox = internal.MenuItemCheckbox MenuItemSeparator = internal.MenuItemSeparator )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Menu ¶
type Menu struct {
// contains filtered or unexported fields
}
Menu represents a context menu for a system tray icon.
func (*Menu) AddCheckbox ¶
AddCheckbox appends a checkbox menu item and returns it for dynamic updates.
func (*Menu) AddSeparator ¶
AddSeparator appends a visual separator.
func (*Menu) AddSubmenu ¶
AddSubmenu appends a nested submenu and returns the item for dynamic updates.
type MenuItem ¶
type MenuItem struct {
// contains filtered or unexported fields
}
MenuItem represents a single item in a context menu. Use SetLabel, SetChecked, SetDisabled, SetIcon for dynamic updates.
func (*MenuItem) SetChecked ¶
SetChecked changes the checked state.
func (*MenuItem) SetDisabled ¶
SetDisabled changes the enabled/disabled state.
type MenuItemType ¶
type MenuItemType = internal.MenuItemType
MenuItemType identifies the kind of menu item.
type SystemTray ¶
type SystemTray struct {
// contains filtered or unexported fields
}
SystemTray represents a system tray icon with context menu. Create with New(). All setter methods return *SystemTray for chaining.
func (*SystemTray) Bounds ¶
func (t *SystemTray) Bounds() (x, y, w, h int)
Bounds returns the tray icon's screen position (x, y, width, height).
func (*SystemTray) Hide ¶
func (t *SystemTray) Hide() *SystemTray
Hide makes the tray icon invisible without removing it.
func (*SystemTray) ID ¶
func (t *SystemTray) ID() TrayID
ID returns the unique identifier for this tray icon.
func (*SystemTray) OnClick ¶
func (t *SystemTray) OnClick(fn func()) *SystemTray
OnClick registers a left-click handler.
func (*SystemTray) OnDoubleClick ¶
func (t *SystemTray) OnDoubleClick(fn func()) *SystemTray
OnDoubleClick registers a double-click handler.
func (*SystemTray) OnRightClick ¶
func (t *SystemTray) OnRightClick(fn func()) *SystemTray
OnRightClick registers a right-click handler.
func (*SystemTray) Remove ¶
func (t *SystemTray) Remove()
Remove destroys the tray icon and releases all resources.
func (*SystemTray) Run ¶
func (t *SystemTray) Run() error
Run blocks the calling goroutine, pumping the platform message loop. Call from main() after Show(). Returns when Quit() is called.
func (*SystemTray) SetDarkModeIcon ¶
func (t *SystemTray) SetDarkModeIcon(png []byte) *SystemTray
SetDarkModeIcon sets an alternative icon for dark mode (Windows). When set, the tray automatically switches between the light and dark icons based on the system theme. On Windows, theme changes are detected via WM_SETTINGCHANGE with "ImmersiveColorSet".
func (*SystemTray) SetIcon ¶
func (t *SystemTray) SetIcon(png []byte) *SystemTray
SetIcon sets the tray icon from PNG bytes.
func (*SystemTray) SetMenu ¶
func (t *SystemTray) SetMenu(menu *Menu) *SystemTray
SetMenu attaches a context menu to the tray icon.
func (*SystemTray) SetTemplateIcon ¶
func (t *SystemTray) SetTemplateIcon(png []byte) *SystemTray
SetTemplateIcon sets a macOS template image (monochrome, adapts to theme).
func (*SystemTray) SetTooltip ¶
func (t *SystemTray) SetTooltip(text string) *SystemTray
SetTooltip sets the hover tooltip text.
func (*SystemTray) ShowNotification ¶
func (t *SystemTray) ShowNotification(title, message string) *SystemTray
ShowNotification displays an OS-level notification.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
|
|
|
multi-tray
command
Example multi-tray demonstrates running two independent system tray icons simultaneously within the same application.
|
Example multi-tray demonstrates running two independent system tray icons simultaneously within the same application. |
|
notification
command
Example notification demonstrates OS-level notifications from a system tray icon.
|
Example notification demonstrates OS-level notifications from a system tray icon. |
|
darwin
Package darwin provides a minimal Objective-C runtime wrapper for the systray package.
|
Package darwin provides a minimal Objective-C runtime wrapper for the systray package. |