tray

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 38 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

View Source
const (
	IconPlay      = "play"
	IconStop      = "stop"
	IconEye       = "eye"
	IconFolder    = "folder"
	IconJob       = "job"
	IconWorkflow  = "workflow"
	IconConnector = "connector"
	DotRunning    = "dot-running"
	DotFailed     = "dot-failed"
	DotWaiting    = "dot-waiting"
	SwitchOn      = "switch-on"
	SwitchOff     = "switch-off"
)

Icon names: each drawn as a character before the entry's title (Label).

Variables

View Source
var PulseFrames = []float64{1, 0.82, 0.62, 0.45, 0.62, 0.82}

PulseFrames are the icon's brightness while something runs, one frame after another, a breath of about a second and a half.

Functions

func ApprovalsTitle added in v0.9.0

func ApprovalsTitle(n int) string

ApprovalsTitle is the Jobs menu's title for n runs waiting.

func Arrived added in v0.7.1

func Arrived(seen map[string]bool, tasks []*pb.HumanTask) []*pb.HumanTask

Arrived returns the tasks not in seen, and makes seen the tasks now waiting (an answered task is forgotten).

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 Do added in v0.7.1

func Do(ctx context.Context, sock string, a Action, open func(link string) error) error

Do does what a click asks of the service at sock; ShowWorkers, ShowWorkflow and ShowProcess open their links with open.

func Exited added in v0.7.0

func Exited(pid int, d time.Duration) bool

Exited waits up to d for process pid to end.

func Failed added in v0.7.1

func Failed(seen map[string]bool, runs []*pb.WorkflowRun, since time.Time) []*pb.WorkflowRun

Failed returns the runs that failed after since and aren't in seen, and adds them to seen.

func FetchApprovals added in v0.9.0

func FetchApprovals(ctx context.Context, sock string) []*pb.GoingServiceRun

FetchApprovals are the organization's runs waiting for the person's answer (spec_053 EN-43): none when not connected, signed out, or from an older service.

func FetchRuns added in v0.7.1

func FetchRuns(ctx context.Context, sock string) ([]*pb.WorkflowRun, error)

FetchRuns asks the service for the latest workflow runs, in every workspace (spec_043_workflows WF-19), newest first.

func FetchTasks added in v0.7.1

func FetchTasks(ctx context.Context, sock string) ([]*pb.HumanTask, string, error)

FetchTasks asks the service for the human tasks workflows wait on, in every workspace (timers aren't the user's to answer), and how the user wants to hear of them ([ui] task_alerts: notify, open or off).

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 Key added in v0.7.1

func Key(entries []Entry) string

Key identifies a menu's entries, to redraw it only when they change.

func Label added in v0.8.0

func Label(e Entry) string

Label is an entry's title, its icon's character before 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 PageDir added in v0.7.0

func PageDir(dir string) (fs.FS, error)

PageDir is the built page in dir, checked to be one (it has index.html).

func ProcessesLink(workspace string, id int) string

ProcessesLink opens the desktop app's processes view on a workspace's process.

func ProcessesTitle added in v0.8.4

func ProcessesTitle(procs []*pb.WorkspaceProcess) string

ProcessesTitle is the submenu's own item: how many are running, and how many of them look bad (spec_052_processes).

func Pulse added in v0.8.0

func Pulse(icon []byte, alpha float64) ([]byte, error)

Pulse is a PNG icon at a brightness: its alpha scaled by alpha.

func RunLink(alerts string, r *pb.WorkflowRun) string

RunLink is the link that tells the desktop app a workflow run failed: blitz://run, with notify=1 a notification (titled and worded here in the user's language) that opens the app on the run (its workspace, its workflow's canvas). "" when alerts are off.

func Serve added in v0.7.0

func Serve(o pageserver.Options, in io.Reader, out io.Writer) error

Serve serves the desktop page for a window that shows it (the Electron app, which runs blitz-tray --serve): it writes a one-time link to the page to out as a JSON line, a new one for each "link" line it reads from in, and stops serving when in ends, so it never outlives the window that started it.

func ServiceExecutable added in v0.7.0

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

ServiceExecutable is the program the service at sock runs from, as it says (GetServiceInfo); "" when it isn't running or doesn't say.

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.

func TasksLink(alerts string, arrived []*pb.HumanTask) string

TasksLink is the link that tells the desktop app tasks have arrived (spec_038_electron EL-110): blitz://tasks opens its tasks window (or its dialog, when the app is open), with notify=1 a notification first, titled and worded here in the user's language. "" when alerts are off or nothing arrived.

func TasksTitle added in v0.7.1

func TasksTitle(n int) string

TasksTitle is the tray menu's item for the waiting tasks.

func WatchRuns added in v0.8.0

func WatchRuns(ctx context.Context, sock string, retry time.Duration, on func([]*pb.WorkflowRun))

WatchRuns follows every workspace's workflow runs on the service at sock (WatchWorkflowRuns): on each change, on hears the runs going on and lately ended. When the stream ends (the service stops or restarts), on hears none, and it's asked again after retry, until ctx is done.

func WithDot added in v0.7.1

func WithDot(icon []byte) ([]byte, error)

WithDot draws a dot at a PNG icon's top right, for tasks waiting.

func WorkersLink(workspace, name string) string

WorkersLink is the blitz:// link that opens the app on a workspace's jobs, on one job's details when name is given.

func WorkflowLink(workspace, workflow, run string) string

WorkflowLink is the blitz:// link that opens the app on a workflow's canvas, and on one of its runs when run is given.

Types

type Action added in v0.7.1

type Action struct {
	Kind      ActionKind
	Workspace string
	Category  string
	Scope     string
	Name      string
	RunID     string
	Hash      string
	On        bool
	ID        int
}

Action is an entry's click.

type ActionKind added in v0.7.1

type ActionKind int

ActionKind is what clicking an entry does.

const (
	NoAction         ActionKind = iota
	SetMCP                      // turn an MCP server on or off (On)
	StopRun                     // stop a worker's run (RunID)
	RunWorker                   // run a worker now
	EnableWorker                // enable a worker at the hash reviewed (Hash)
	DisableWorker               // disable a worker
	ShowWorkers                 // open the app on a workspace's workers
	RunWorkflow                 // run a workflow in the background (Name)
	StopWorkflow                // stop a workflow's run (RunID)
	ShowWorkflow                // open the app on a workflow's canvas (Name), on a run (RunID)
	SetConnector                // turn a connection on or off in a workspace (Category, Scope, Name, On)
	StopProcess                 // stop an agent's background process (Workspace, ID)
	ShowProcess                 // open the app's processes view on one (Workspace, ID)
	AnswerServiceRun            // approve (On) or deny an organization's run waiting (RunID, EN-43)
)

What an entry does.

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
}

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), the app the tray is in, beside it or on PATH (blitz-desktop on Linux, Blitz.exe on Windows).

func (a Actions) OpenLink(link string) error

OpenLink opens a link (blitz://…) with the program the system has for it: the desktop app, for blitz links.

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) Running added in v0.7.0

func (a Actions) Running() bool

Running reports whether the service answers now.

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 Conn added in v0.8.0

type Conn struct {
	Category string
	// Scope is workspace (.agents/connectors/<category>) or global.
	Scope string
	Name  string
	// On says it's served in the workspace (CON-17).
	On bool
}

Conn is a connection a workspace reaches.

func Conns added in v0.8.0

func Conns(prefixDir, dir string) []Conn

Conns are the connections workspace dir reaches: each category's global ones, then its own, by category and name, with whether each is on there (the person's choices in the settings folder of prefixDir). The folders, names and keys are the engine's (pkg/config).

type Entry added in v0.7.1

type Entry struct {
	Title    string
	Checkbox bool
	Checked  bool
	Disabled bool
	Icon     string
	Action   Action
	Children []Entry
}

Entry is a menu item: a title, a checkbox (Checked) or not, greyed out (Disabled), its icon (Icon*, Dot*: main draws it), what a click does, and a submenu.

func ApprovalEntries added in v0.9.0

func ApprovalEntries(runs []*pb.GoingServiceRun) []Entry

ApprovalEntries are the waiting runs, each with what it asks and Approve, Deny and Show in Blitz (the window's Processes, where the organization's runs are).

func Going added in v0.8.0

func Going(l Live, spaces []Space, now time.Time) []Entry

Going are the menu's running entries: each job's run (with its workflow's progress when it runs one), then each other workflow run going on, named with its workspace when there's more than one; each opens on Show in Blitz and Stop. A run waiting on a person or a timer has the waiting dot.

func MCPEntries added in v0.7.1

func MCPEntries(e Extras) []Entry

MCPEntries are the MCP servers submenu: each global server, checked while it's on; a click turns it off or on.

func ProcessEntries added in v0.8.4

func ProcessEntries(procs []*pb.WorkspaceProcess, spaces []Space) []Entry

ProcessEntries are the Processes submenu: each running process, its command (marked when it looks bad), under it its workspace (named as spaces name it), what it uses and why it looks bad, Show in Blitz and Stop; none, a line saying so.

func SpaceEntries added in v0.8.0

func SpaceEntries(s Space, workers []*pb.Worker, flows []Flow, conns []Conn, l Live) []Entry

SpaceEntries are a workspace's submenu: Jobs, each job with Run now, Stop while it runs, Enabled and Show in Blitz, marked running or failed; then Workflows, each with Run, Stop while it runs and Show in Blitz, marked running; then Connectors, each connection it reaches checked while it's on there (connEntries). A section with nothing in it is left out, and a workspace with none has no submenu (none).

type Extras added in v0.7.1

type Extras struct {
	MCP     []*pb.MCPServerConfig
	Workers []*pb.Worker
	Runs    []*pb.WorkerRun
	// Processes are the agents' background processes still running
	// (EL-112); none from an older service.
	Processes []*pb.WorkspaceProcess
}

Extras is what the submenus show: the global MCP servers, every workspace's workers and the runs going on.

func FetchExtras added in v0.7.1

func FetchExtras(ctx context.Context, sock string) (Extras, error)

FetchExtras asks the service at sock for the submenus' lists, within a couple of seconds.

type Flow added in v0.8.0

type Flow struct {
	Name        string
	Description string
}

Flow is one of a workspace's workflows, as its file says.

func Flows added in v0.8.0

func Flows(dir string) []Flow

Flows are dir's workflows (.agents/workflows/<name>.flow.yaml), by name, read from disk: the service needn't open the workspace for the tray to list them.

type Item

type Item struct {
	Title   string
	Enabled bool
}

Item is a menu item's state.

type Link struct {
	URL string `json:"url"`
	// Fingerprint is the page server's certificate's (SHA-256, colon-
	// separated hex): the one certificate the window trusts for it.
	Fingerprint string `json:"fingerprint"`
}

Link is what Serve writes for each link it makes: one JSON line.

type Live added in v0.8.0

type Live struct {
	// Runs are workflow runs going on and lately ended (WatchWorkflowRuns).
	Runs []*pb.WorkflowRun
	// JobRuns are jobs' runs going on (ListRunningWorkerRuns).
	JobRuns []*pb.WorkerRun
}

Live is what's going on, as the service says.

func (Live) Busy added in v0.8.0

func (l Live) Busy() bool

Busy reports whether anything runs: the icon pulses while it does.

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 Space added in v0.8.0

type Space struct {
	Dir  string
	Name string
}

Space is a workspace the tray has a submenu for.

func Spaces added in v0.8.0

func Spaces(open []Space, workers []*pb.Worker) []Space

Spaces are the workspaces the tray shows: those open in the app, in its order (named as it names them), then any other with jobs, and the home workspace's (the global jobs) last, as Global.

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
	// Org is the organization Blitz is connected to: its branding's name,
	// else its service's (spec_053_enterprise EN-51); "" for none.
	Org string
}

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.

type Update added in v0.7.0

type Update struct {
	Staged, Root, Relaunch string
	// WaitPID is the app's process, waited for (0: none).
	WaitPID int
	Actions Actions
	// ServiceExe is the running service's program ("" if none runs).
	ServiceExe func() string
	// Exited waits up to d for process pid to end.
	Exited func(pid int, d time.Duration) bool
	Log    io.Writer
}

Update puts a downloaded desktop app in place of the running one (blitz-tray --apply-update, run by the app's host from outside the app, spec_038_electron EL-90): it waits for the app to quit, stops the service if it runs from the app (Windows can't replace a program in use), swaps them, starts the service again and then the app, the new one or, if the swap failed, the old one.

func (Update) Run added in v0.7.0

func (u Update) Run() error

Run applies the update.

Jump to

Keyboard shortcuts

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