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 ¶
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 ¶
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 Notification ¶
type NotificationAction ¶
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 ¶
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.