Documentation ¶
Overview ¶
Package systray is a cross-platform Go library to place an icon and menu in the notification area. Based on https://github.com/getlantern/systray and provides few improvements:
- Windows system calls instead of custom DLL
- Caching icon files
- Allows to set direct path to icon file
- Error handling
Supports Windows, Mac OSX and Linux currently. Methods can be called from any goroutine except Run(), which should be called at the very beginning of main() to lock at main thread.
Index ¶
- Constants
- func Quit()
- func Run(onReady func(), onExit func()) error
- func SetIcon(iconBytes []byte) error
- func SetIconPath(path string) error
- func SetTitle(title string) error
- func SetTooltip(tooltip string) error
- type MenuItem
- func (item *MenuItem) Check() error
- func (item *MenuItem) Checked() bool
- func (item *MenuItem) Disable() error
- func (item *MenuItem) Disabled() bool
- func (item *MenuItem) Enable() error
- func (item *MenuItem) Hide() error
- func (item *MenuItem) OnClickCh() <-chan struct{}
- func (item *MenuItem) SetTitle(title string) error
- func (item *MenuItem) SetTooltip(tooltip string) error
- func (item *MenuItem) Show() error
- func (item *MenuItem) Uncheck() error
Examples ¶
Constants ¶
const ( ItemDefault = 0 ItemSeparator byte = 1 << iota ItemChecked ItemCheckable ItemDisabled )
Variables ¶
This section is empty.
Functions ¶
func Run ¶
func Run(onReady func(), onExit func()) error
Run initializes GUI and starts the event loop, then invokes the onReady callback. It blocks until systray.Quit() is called. Should be called at the very beginning of main() to lock at main thread.
Example ¶
if err := SetIconPath("example/icon/iconwin.ico"); err != nil { log.Fatalf("Can't set icon: %s", err) } if err := SetTitle("Test title с кириллицей"); err != nil { log.Fatalf("Can't set title: %s", err) } bBtn := AddMenuItem("Йа Кнопко", "", ItemCheckable) AddSeparator() bQuit := AddMenuItem("Quit", "Quit the whole app", ItemDefault) go func() { for { select { case <-bBtn.OnClickCh(): log.Println("Btn clicked") case <-bQuit.OnClickCh(): log.Println("Quit reqested") Quit() } } }() onReady := func() { log.Println("Systray started") } Run(onReady, nil)
Output:
func SetIcon ¶
SetIcon sets the systray icon. iconBytes should be the content of *.ico for windows and *.ico/*.jpg/*.png for other platforms. On windows and linux it creates reusable temporary file with icon content. This file
func SetIconPath ¶
SetIconPath sets icon by direct path. It should be *.ico for windows and *.ico/*.jpg/*.png for other platforms.
func SetTooltip ¶
SetTooltip sets the systray tooltip to display on mouse hover of the tray icon, only available on Mac and Windows.
Types ¶
type MenuItem ¶
type MenuItem struct {
// contains filtered or unexported fields
}
MenuItem is used to keep track each menu item of systray Don't create it directly, use the one systray.AddMenuItem() returned
func AddMenuItem ¶
AddMenuItem adds menu item with designated title and tooltip, returning a channel that notifies whenever that menu item is clicked.
It can be safely invoked from different goroutines.
func (*MenuItem) SetTooltip ¶
SetTooltip set the tooltip to show when mouse hover.