tray

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 28 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tray is the Blitz tray icon's behaviour, apart from the icon library: what the service's state is, the menu for it, and what its items do. cmd blitz-tray draws it with fyne.io/systray.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Detached

func Detached(name string, args ...string) error

Detached starts a program in its own session, with no terminal and its output discarded, and reaps it when it exits.

func ICO added in v0.4.0

func ICO(pngData []byte) ([]byte, error)

ICO wraps a PNG in an icon file (.ico), which Windows wants for a tray icon: one image, stored as the PNG itself, as Windows Vista and later read it.

func Language

func Language(b *i18n.Bundle, prefs []byte, system []string) language.Tag

Language is the language the tray shows: the desktop app's setting (prefs, the content of ~/.blitz/desktop.json) unless it's "system"; else the first of the system's languages (most preferred first) with a catalog; else English. It chooses as the app's window does.

func LogDir

func LogDir() string

LogDir is where the service's logs go by the settings file: log.dir of the global settings.

func ServiceLogDir

func ServiceLogDir(ctx context.Context, sock string) string

ServiceLogDir is where the service at sock writes its log, as it says (ListLogDays): the log.dir it started with. "" when it isn't running, doesn't say, or has its log off.

func SetupLocale

func SetupLocale()

SetupLocale shows the tray in the desktop app's language (Settings › Language), from the same catalogs, with ui.locales_dir's added.

func Shutdown added in v0.4.0

func Shutdown(ctx context.Context, sock string) error

Shutdown asks the service at sock to stop (WorkspaceService.Shutdown): how the tray stops one it can't signal (Windows).

func SystemLanguages

func SystemLanguages() []string

SystemLanguages are the user's languages, most preferred first: macOS's list (programs started at login have no LANG there), then LANGUAGE, LC_ALL, LC_MESSAGES and LANG.

Types

type Actions

type Actions struct {
	// Run starts a program and doesn't wait for it.
	Run func(name string, args ...string) error
	// Beside is the tray's own directory (blitzd and the app are there
	// when installed together).
	Beside string
	// Status is the service's state now.
	Status func() Status
	// Wait polls until the service is (or isn't) running, for up to d.
	Wait func(running bool, d time.Duration) bool
	// LogDir is where the running service says its log is ("" when it
	// doesn't say); nil asks nobody. The settings file answers otherwise.
	LogDir func() string
	// Shutdown asks the service to stop (nil: nobody is asked, and Stop
	// signals it).
	Shutdown func() error
	// Page is a link that opens the page the tray serves (Windows, which
	// has no desktop app); nil opens the desktop app instead.
	Page func() (string, error)
}

Actions are what the menu's items do. Each has what it needs to find and run the system's programs; tests replace them.

func (Actions) OpenApp

func (a Actions) OpenApp() error

OpenApp opens the desktop app: the bundle the tray is in (macOS), blitz-desktop beside it or on PATH (Linux); or, with a Page, the page in a browser's app window (Windows).

func (Actions) OpenLogs

func (a Actions) OpenLogs() error

OpenLogs shows the logs folder in the file manager: the running service's, which may not be the settings file's (another --config, or log.dir changed since it started).

func (Actions) Restart

func (a Actions) Restart() error

Restart restarts the service (Stop then Start without a login item).

func (Actions) Start

func (a Actions) Start() error

Start starts the service: through its login item when it has one, else blitzd from beside the tray or PATH, on its own.

func (Actions) Stop

func (a Actions) Stop() error

Stop stops the service: its login item's, else the service asked to stop, else the process that answered (SIGTERM). Either way turns in progress get a few seconds.

type Host added in v0.4.0

type Host struct {
	Actions Actions
	// Version is the tray's, which the page shows as the app's.
	Version string
	// Socket is the service's.
	Socket string
	// Tray is the tray's own program, which starts at login.
	Tray string
}

Host answers the page the tray serves (pageserver.HostPrefix) with what the desktop app's bindings do and a browser can't: the service's status and controls, starting at login, showing files, the licenses. The page calls POST /host/<Method> with its arguments as a JSON array and gets the result as JSON, or {"error": "…"} with status 500, the method names being the desktop app's (window.go.main.App); GET /host/info lists them.

func (Host) Handler added in v0.4.0

func (h Host) Handler() http.Handler

Handler serves the page's calls under pageserver.HostPrefix.

type Item

type Item struct {
	Title   string
	Enabled bool
}

Item is a menu item's state.

type Menu struct {
	Running bool // which icon
	Tooltip string
	// State is the first line: what the service is doing (not clickable).
	State                Item
	Start, Stop, Restart Item
}

Menu is what the tray shows for a status.

func MenuFor(s Status) Menu

MenuFor is the menu for s: Start when the service is stopped, Stop and Restart while it runs.

type ServiceStatus added in v0.4.0

type ServiceStatus struct {
	Running       bool   `json:"running"`
	Installed     bool   `json:"installed"`
	Socket        string `json:"socket"`
	Service       string `json:"service"`
	Tray          string `json:"tray"`
	TrayInstalled bool   `json:"tray_installed"`
}

ServiceStatus is the desktop app's ServiceStatus, as the page reads it.

type Status

type Status struct {
	// Running means the service answers on its socket.
	Running bool
	// Installed means it starts at login (a launchd agent or systemd unit).
	Installed bool
	// Version and PID are what the running service says (GetServiceInfo).
	Version string
	PID     int
}

Status is the service as the tray sees it.

func Probe

func Probe(ctx context.Context, sock string, installed func() bool) Status

Probe asks the service at sock how it is, within a second or two.

Jump to

Keyboard shortcuts

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