Package systray
is a toolkit-agnostic implementation of the
StatusNotifierItem
specification. It provides services for system tray hosts. This package does
not provide capabilities for system tray applications (clients), it is intended
to be used for building system trays themselves.
Package documentation is available at pkg.go.dev.
go get github.com/shelepuginivan/systray
package main
import (
"log"
"os"
"github.com/godbus/dbus/v5"
"github.com/shelepuginivan/systray"
)
func main() {
conn, _ := dbus.SessionBus()
watcher := systray.NewWatcher(conn)
host := systray.NewHost(conn, os.Getpid())
watcher.RegisterHost(host)
host.OnRegister(func(item *systray.Item) {
log.Printf("%s (%s) is registered\n", item.Title, item.BusName())
})
host.OnUnregister(func(item *systray.Item) {
log.Printf("%s (%s) is unregistered\n", item.Title, item.BusName())
})
if err := watcher.Listen(); err != nil {
panic(err)
}
if err := host.Listen(); err != nil {
panic(err)
}
select {}
}