wintray

package module
v0.0.0-...-3e86e45 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: MIT Imports: 11 Imported by: 0

README

go-wintray

Go Reference MIT License

A simple package for creating an icon in the system tray and displaying notifications.

Usage

To use this package, begin by importing it:

import "github.com/nathan-osman/go-wintray"

Next, create the tray icon:

w := wintray.New()
defer w.Close()

You will likely want to set an icon and tooltip:

//go:embed myapp.ico
var b []byte

w.SetIconFromBytes(b)
w.SetTip("MyApp Is Running")

You can add items to the context menu that is shown when the icon is right-clicked:

w.AddMenuItem("&Print Message", func() {
    fmt.Println("This is a tooltip!")
})

Note that the provided function will run on a different goroutine than the caller.

Screenshot of example code running in the system tray

Notifications can be displayed as well:

w.ShowNotification("This is a test.", "Title")

Documentation

Index

Constants

View Source
const (
	DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = ^uintptr(1)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type WinTray

type WinTray struct {
	// contains filtered or unexported fields
}

WinTray provides a single icon in the system tray. A separate goroutine is used for running all of the API functions

func New

func New() *WinTray

New creates a new WinTray icon.

func (*WinTray) AddMenuItem

func (w *WinTray) AddMenuItem(text string, fn func()) error

AddMenuItem adds an item to the menu that will invoke the provided function when selected.

func (*WinTray) AddMenuSeparator

func (w *WinTray) AddMenuSeparator() error

AddMenuSeparator inserts a menu separator after the last item.

func (*WinTray) Close

func (w *WinTray) Close()

Close removes the icon and shuts down the event loop.

func (*WinTray) SetIconFromBytes

func (w *WinTray) SetIconFromBytes(b []byte) error

SetIconFromBytes reads an ICO file from a byte array.

func (*WinTray) SetTip

func (w *WinTray) SetTip(text string) error

SetTip sets the tooltip for the icon.

func (*WinTray) ShowNotification

func (w *WinTray) ShowNotification(info, infoTitle string) error

ShowNotification displays a balloon notification with the provided message and title.

Jump to

Keyboard shortcuts

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