wintray

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

README

wintray

wintray is a Windows-specific Go library to place an icon and menu in the notification area.

Usage

This package comes with an example application that shows how to use the library. See example/main.go for more details.

To run the example app, run the following commands:

git clone https://github.com/merlinz01/wintray
cd wintray

go run ./example
# or, to hide the console window when not running in a terminal
go run -ldflags "-H=windowsgui" ./example

License

This project is licensed under the Apache License, Version 2.0 - see the LICENSE file for details.

Credits

This project is based on the fyne.io/systray module, with non-Windows code removed and some API changes.

Documentation

Rendered for windows/amd64

Overview

Package wintray is a Windows-specific Go library to place an icon and menu in the notification area.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrTrayNotReadyYet is returned by functions when they are called before the tray has been initialized.
	ErrTrayNotReadyYet = errors.New("tray not ready yet")
)

Functions

func AddSeparator

func AddSeparator()

Add a separator bar to the menu.

func OnTrayOpened

func OnTrayOpened(f func())

Add a callback to be called when the tray is opened.

func Quit

func Quit()

Quit the systray message loop.

func Register

func Register(onReady func(), onExit func()) error

Initializes the GUI and register the callbacks. Relies on the caller to run the event loop somewhere else. Useful if the program needs to show other UI elements.

func ResetMenu

func ResetMenu()

Remove all menu items.

func Run

func Run(onReady, onExit func()) error

Initialize the GUI and start the event loop, then invoke the onReady callback. Blocks until systray.Quit() is called.

func RunWithExternalLoop

func RunWithExternalLoop(onReady, onExit func()) (start, end func(), err error)

RunWithExternalLoop allows the systemtray module to operate with other tookits. The returned start and end functions should be called by the toolkit when the application has started and will end.

func SetIcon

func SetIcon(iconBytes []byte) error

Set the systray icon. iconBytes should be the content of .ico image.

func SetIconFromFilePath

func SetIconFromFilePath(iconFilePath string) error

Set the systray icon from a file path. iconFilePath should be the path to a .ico image.

func SetOpenOnLeftClick

func SetOpenOnLeftClick(open bool)

Set whether or not the icon should respond to left clicks. The default is true.

func SetOpenOnRightClick

func SetOpenOnRightClick(open bool)

Set whether or not the icon should respond to right clicks. The default is true.

func SetTooltip

func SetTooltip(tooltip string) error

Set the tooltip to display on mouse hover of the tray icon.

Types

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 systray.AddMenuItem()

func AddMenuItem

func AddMenuItem(title string) *MenuItem

Add a menu item with the designated title. Can be safely invoked from different goroutines.

func (item *MenuItem) AddSeparator()

Add a separator bar to the submenu.

func (item *MenuItem) AddSubMenuItem(title string) *MenuItem

Add a nested sub-menu item with the designated title. Can be safely invoked from different goroutines.

func (item *MenuItem) Check()

Check a menu item regardless if it's previously checked or not.

func (item *MenuItem) Checked() bool

Return if the menu item has a check mark.

func (item *MenuItem) Disable()

Disable a menu item regardless if it's previously disabled or not.

func (item *MenuItem) Disabled() bool

Return whether the menu item is disabled.

func (item *MenuItem) Enable()

Enable a menu item regardless if it's previously enabled or not.

func (item *MenuItem) Hide()

Hide a menu item.

func (item *MenuItem) Remove()

Remove a menu item and, if it has a submenu, all its children.

func (item *MenuItem) SetCallback(onClick func())

Set the function to be called when the menu item is clicked. The function is called from a new goroutine.

func (item *MenuItem) SetIcon(iconBytes []byte) error

Set the icon of a menu item. iconBytes should be the content of .ico image.

func (item *MenuItem) SetIconFromFilePath(iconFilePath string) error

Set the icon of a menu item from a file path. iconFilePath should be the path to a .ico image.

func (item *MenuItem) SetTitle(title string)

Set the text to display on a menu item.

func (item *MenuItem) Show()

Show a previously hidden menu item.

func (item *MenuItem) String() string

Return a string representation of the MenuItem for debugging

func (item *MenuItem) Uncheck()

Uncheck a menu item regardless if it's previously unchecked or not.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL