menubar

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 22 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 menubar is the menu bar and notification layer as a client of the daemon's JSON: it decides the title, the menu and the notifications, and turns the user's answers into daemon actions. The native adapter lives in menubar/macos.

Index

Constants

View Source
const AnswerSource = string(turn.Notification)

AnswerSource is what an answer from a notification names.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action string
const (
	// ActionOpen opens the notification's entry in the cockpit.
	ActionOpen Action = "open"
	// ActionServed posts the action whose id is Response.Identifier.
	ActionServed Action = "served"
	// ActionAnswer answers the question with Response.Text, OptionID, Yes or
	// No.
	ActionAnswer Action = "answer"
	// ActionReply writes Response.Text as a reply on the entry's unit: to the
	// Outbox, or sent at once with Response.Send.
	ActionReply Action = "reply"
)

type Categories

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

Categories are the categories the notification center knows: the category of each notification posted with buttons and not withdrawn. It is not safe for concurrent use.

func NewCategories

func NewCategories() *Categories

func (*Categories) List

func (c *Categories) List() []CategorySpec

func (*Categories) Post

func (c *Categories) Post(n Notification) bool

Post records the category of n with its actions; true when the set changed and must be registered again.

func (*Categories) Withdraw

func (c *Categories) Withdraw(ids []string) bool

Withdraw drops a category once no live notification uses it; true when the set changed.

type Category

type Category = api.Category

Category is a notification's category, the first part of its id (api.NotificationID).

type CategorySpec

type CategorySpec struct {
	ID      Category
	Actions []NotificationAction
}

CategorySpec is a notification category as macOS registers it.

type Config

type Config struct {
	Daemon   Daemon
	Tray     Tray
	Notifier Notifier
	OpenURL  func(url string) error
	// CockpitURL is the cockpit's address at a hash route such as
	// "entry=<id>" or "view=inbox".
	CockpitURL func(route string) (string, error)
	Quit       func()
	// Copy puts text on the clipboard; nil offers no copy.
	Copy func(text string) error
	Now  func() time.Time
	// After is time.After unless a test supplies its own clock.
	After func(time.Duration) <-chan time.Time
	Log   func(format string, args ...any)
	// SentPath keeps today's held notifications and digest across
	// restarts; "" keeps them in memory only.
	SentPath string
	// DigestAt is the local "HH:MM" of the daily digest; "" posts none.
	DigestAt string
}

type Controller

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

func New

func New(cfg Config) *Controller

func (*Controller) Refresh

func (c *Controller) Refresh(ctx context.Context)

Refresh reads the rows and entries that moved and the health, then redraws the title, the menu and the notifications.

func (*Controller) Respond

func (c *Controller) Respond(ctx context.Context, r Response)

Respond turns a notification answer into the entry's verb, its answer, or the catalog action on its first unit; opening the cockpit, and a draft's open, are the app's own.

func (*Controller) Run

func (c *Controller) Run(ctx context.Context) error

Run draws the menu, reports the app to the daemon, asks for the notification permission without waiting for the answer, and follows the daemon's changes, pulling only the rows that moved. It polls every refreshMax only while the change stream is down.

type Daemon

type Daemon interface {
	RowsSince(ctx context.Context, since api.Since) (api.RowsPage, error)
	EntriesSince(ctx context.Context, q client.EntryQuery, since api.Since) (api.EntriesPage, error)
	Entry(ctx context.Context, id string) (api.EntryView, error)
	EntryDo(ctx context.Context, id, verb string, req api.EntryRequest) (api.EntryResult, error)
	Digest(ctx context.Context, day string) (api.Digest, error)
	Health(ctx context.Context) (api.Health, error)
	Action(ctx context.Context, u unit.Unit, action string, req api.ActionRequest) ([]string, error)
	Trigger(ctx context.Context, job string) error
	SetPause(ctx context.Context, req api.PauseRequest) error
	ReportApp(ctx context.Context, st api.AppStatus) error
	Events(ctx context.Context, client string, since api.Since) (<-chan api.Change, error)
	Actions(ctx context.Context) (api.ActionsResponse, error)
	Plugins(ctx context.Context) ([]api.Plugin, error)
}

type Image

type Image string

Image tells notifications apart at a glance.

const (
	ImageRound   Image = "round"
	ImageHeld    Image = "held"
	ImageAsk     Image = "ask"
	ImageBlocked Image = "blocked"
)
type MenuItem struct {
	Title string
	// Tooltip is what hovering the item says: what an action does, or why
	// it is off.
	Tooltip   string
	Enabled   bool
	Separator bool
	Checked   bool
	Action    func()
	Children  []MenuItem
}

type Notification

type Notification struct {
	ID string
	// Title is the kind of notification, Subtitle its unit.
	Title    string
	Subtitle string
	Body     string
	Category Category
	Image    Image // "" posts no image
	Actions  []NotificationAction
}

type NotificationAction

type NotificationAction struct {
	ID, Title string
	TextInput bool
}

NotificationAction is a button of a notification; its ID is the daemon's action id, which ResponseFor reads back.

type Notifier

type Notifier interface {
	Authorize(ctx context.Context) (Permission, error)
	Permission(ctx context.Context) (Permission, error)
	Post(n Notification) error
	Withdraw(ids []string)
	// WithdrawAll clears every notification delivered so far.
	WithdrawAll()
	OnResponse(fn func(Response))
}

Notifier posts notifications and reports the user's answers. Authorize may block until the user answers the system dialog; Permission only reads the current setting.

type Permission

type Permission string
const (
	PermissionAuthorized    Permission = "authorized"
	PermissionProvisional   Permission = "provisional"
	PermissionDenied        Permission = "denied"
	PermissionNotDetermined Permission = "not-determined"
)

type Response

type Response struct {
	ID string
	// Identifier is the notification action the user picked, as the
	// notification center reported it.
	Identifier string
	Action     Action
	Text       string
	OptionID   string
	Yes, No    bool
	Send       bool
}

func ResponseFor

func ResponseFor(id, action string) (Response, bool)

ResponseFor is the response to the notification id when the user picks the action whose id the daemon gave; the text of a text input is added by the caller. System identifiers are not actions.

type Tray

type Tray interface {
	SetTitle(title string)
	SetMenu(items []MenuItem)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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