MCPcopy Index your code
hub / github.com/energye/systray

github.com/energye/systray @v1.0.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.3 ↗ · + Follow
331 symbols 558 edges 12 files 195 documented · 59% 1 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Systray

systray is a cross-platform Go library to place an icon and menu in the notification area. This repository is a fork of getlantern/systray removing the GTK dependency and support for legacy linux system tray.

Features

  • Supported on Windows, macOS, Linux and many BSD systems
  • Menu items can be checked and/or disabled
  • Methods may be called from any Goroutine
  • tray icon supports mouse click, double click, and right click

API

package main

import "github.com/energye/systray"
import "github.com/energye/systray/icon"

func main() {
    systray.Run(onReady, onExit)
}

func onReady() {
    systray.SetIcon(icon.Data)
    systray.SetTitle("Awesome App")
    systray.SetTooltip("Pretty awesome超级棒")
    systray.SetOnClick(func() {
        fmt.Println("SetOnClick")
    })
    systray.SetOnDClick(func() {
        fmt.Println("SetOnDClick")
    })
    systray.SetOnRClick(func(menu systray.IMenu) {
        menu.ShowMenu()
        fmt.Println("SetOnRClick")
    })
    mQuit := systray.AddMenuItem("Quit", "Quit the whole app")

    // Sets the icon of a menu item.
    mQuit.SetIcon(icon.Data)
}

func onExit() {
    // clean up here
}

Run in another toolkit

Most graphical toolkits will grab the main loop so the Run code above is not possible. For this reason there is another entry point RunWithExternalLoop. This function of the library returns a start and end function that should be called when the application has started and will end, to loop in appropriate features.

Note: this package requires cgo, so make sure you set CGO_ENABLED=1 before building.

Try the example app!

Have go v1.12+ or higher installed? Here's an example to get started on macOS or Linux:

git clone https://github.com/energye/systray
cd systray/example
go run .

On Windows, you should follow the instructions above, but use the followign run command:

go run -ldflags "-H=windowsgui" .

Now look for Awesome App in your menu bar!

Awesome App screenshot

Platform notes

Linux/BSD

This implementation uses DBus to communicate through the SystemNotifier/AppIndicator spec, older tray implementations may not load the icon.

If you are running an older desktop environment, or system tray provider, you may require a proxy app which can convert the new DBus calls to the old format. The recommended tool for Gnome based trays is snixembed, others are available. Search for "StatusNotifierItems XEmbedded" in your package manager.

Windows

go build -ldflags -H=windowsgui

macOS

On macOS, you will need to create an application bundle to wrap the binary; simply use add folders with the following minimal structure and assets:

SystrayApp.app/
  Contents/
    Info.plist
    MacOS/
      go-executable
    Resources/
      SystrayApp.icns

If bundling manually, you may want to add one or both of the following to your Info.plist:


    <key>NSHighResolutionCapable</key>
    <string>True</string>


    <key>LSUIElement</key>
    <string>1</string>

Consult the Official Apple Documentation here.

Credits

  • https://github.com/getlantern/systray
  • https://github.com/xilp/systray
  • https://github.com/cratonica/trayhost

Extension points exported contracts — how you extend this code

IMenu (Interface)
(no doc) [2 implementers]
systray.go

Core symbols most depended-on inside this repo

update
called by 10
systray.go
Click
called by 8
systray.go
findLayout
called by 8
systray_menu_unix.go
AddMenuItem
called by 7
systray.go
isReady
called by 7
systray_windows.go
refresh
called by 6
systray_menu_unix.go
newMenuItem
called by 4
systray.go
SetTitle
called by 4
systray.go

Shape

Method 176
Function 111
Struct 37
Interface 5
TypeAlias 2

Languages

Go100%

Modules by API surface

internal/generated/notifier/status_notifier_item.go94 symbols
internal/generated/menu/dbus_menu.go63 symbols
systray_windows.go58 symbols
systray.go33 symbols
systray_darwin.go32 symbols
systray_unix.go26 symbols
systray_menu_unix.go19 symbols
example/main.go4 symbols
systray_other.go2 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add systray \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page