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() error
- func Run(onReady func(), onExit func()) error
- func SetCustomLeftClickAction(ff ClickActionType)
- func SetCustomLeftDoubleClickAction(ff ClickActionType)
- func SetCustomRightClickAction(ff ClickActionType)
- func SetCustomRightDoubleClickAction(ff ClickActionType)
- func SetDefaultLeftClickAction()
- func SetDefaultLeftDoubleClickAction()
- func SetDefaultRightClickAction()
- func SetDefaultRightDoubleClickAction()
- func SetIcon(iconBytes []byte) error
- func SetIconPath(path string) error
- func SetTitle(title string) error
- func SetTooltip(tooltip string) error
- type ClickActionType
- type MenuItem
- func (item *MenuItem) AddBitmap(bitmapByte []byte) error
- func (item *MenuItem) AddBitmapPath(filepath string) error
- func (sitem *MenuItem) AddSubMenuItem(title, tooltip string, flags byte) *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 SetCustomLeftClickAction ¶ added in v0.0.2
func SetCustomLeftClickAction(ff ClickActionType)
SetCustomLeftClickAction set custom function to process left click on icon only windows at this moment
func SetCustomLeftDoubleClickAction ¶ added in v0.0.2
func SetCustomLeftDoubleClickAction(ff ClickActionType)
SetCustomLeftDoubleClickAction set custom function to process left click on icon only windows at this moment
func SetCustomRightClickAction ¶ added in v0.0.2
func SetCustomRightClickAction(ff ClickActionType)
SetCustomRightClickAction set custom function to process right click on icon only windows at this moment
func SetCustomRightDoubleClickAction ¶ added in v0.0.2
func SetCustomRightDoubleClickAction(ff ClickActionType)
SetCustomRightDoubleClickAction set custom function to process right click on icon only windows at this moment
func SetDefaultLeftClickAction ¶ added in v0.0.2
func SetDefaultLeftClickAction()
SetDefaultLeftClickAction set defualt function to process left click on icon (show menu) only windows at this moment
func SetDefaultLeftDoubleClickAction ¶ added in v0.0.2
func SetDefaultLeftDoubleClickAction()
SetDefaultLeftDoubleClickAction set defualt function to process left click on icon (show menu) only windows at this moment
func SetDefaultRightClickAction ¶ added in v0.0.2
func SetDefaultRightClickAction()
SetDefaultRightClickAction set defualt function to process right click on icon (show menu) only windows at this moment
func SetDefaultRightDoubleClickAction ¶ added in v0.0.2
func SetDefaultRightDoubleClickAction()
SetDefaultRightDoubleClickAction set defualt function to process right click on icon (show menu) only windows at this moment
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 ¶ added in v1.0.0
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 ClickActionType ¶ added in v0.0.2
type ClickActionType func() error
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 AddSubMenu ¶ added in v1.0.0
AddSubMenu adds a sub menu to the systray and and returns an id to access to accesss the menu
func (*MenuItem) AddBitmapPath ¶ added in v1.0.0
func (*MenuItem) AddSubMenuItem ¶ added in v1.0.0
func (*MenuItem) SetTooltip ¶
SetTooltip set the tooltip to show when mouse hover.