events

package
v1.44.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 2 Imported by: 1 module, 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 events is a lossy in-process event bus for UI notifications. It is not a reliable delivery channel; plugin hooks read the database cursor instead.

Index

Constants

View Source
const (
	MessageReceived     = "message.received"
	MessagesChanged     = "messages.changed"
	SyncStarted         = "sync.started"
	SyncFinished        = "sync.finished"
	SyncFailed          = "sync.failed"
	OutboxChanged       = "outbox.changed"
	SettingsChanged     = "settings.changed"
	SkillsChanged       = "skills.changed"
	ApprovalsChanged    = "approvals.changed"
	RunsChanged         = "runs.changed" // a run of an ask conversation started or ended
	PluginsChanged      = "plugins.changed"
	MCPChanged          = "mcp.changed"
	LabelsChanged       = "labels.changed"
	SignaturesChanged   = "signatures.changed"
	ModelsChanged       = "models.changed"        // a plugin model's files were downloaded or removed
	MCPSendsChanged     = "mcp_sends.changed"     // godwit mcp's send requests waiting for the user changed
	ImportProgress      = "import.progress"       // an .eml import into AccountID handled Done of Total files
	AddressBooksChanged = "address_books.changed" // address books, collections, order or synced cards changed
	DraftsChanged       = "drafts.changed"        // a draft was created or deleted, or a program changed one (ADR 0043)
	IdentitiesChanged   = "identities.changed"    // an account's 发件身份 were added, changed or removed (ADR 0047)
	SimpleLoginChanged  = "simplelogin.changed"   // the SimpleLogin integration's settings, cached aliases or mailboxes changed (ADR 0053)
	// NotificationClicked: the backend got a click on notification Notification
	// while a ui client is connected; the interface opens what it shows. With
	// none, the backend starts the interface for it instead.
	NotificationClicked = "notification.clicked"
	// QuitRequested: Quit was chosen in the backend's tray; the interface quits as its own Quit does.
	QuitRequested = "quit.requested"
	// OpenRequested and ComposeRequested: Open or Compose was chosen in the
	// backend's tray while a ui client is connected; the interface shows its
	// main window, or a new compose window.
	OpenRequested    = "open.requested"
	ComposeRequested = "compose.requested"
	// SignInCodePreview: a development build's interface asked to preview
	// MessageIDs[0]'s sign-in code card (Kind "link": its sign-in link card);
	// the backend's tray, which the card belongs to, shows it.
	SignInCodePreview = "signin_code.preview"
	// AccountsChanged: account AccountID's own row changed (its status,
	// features, settings or position), or the account was added or removed.
	AccountsChanged = "accounts.changed"
	// FoldersChanged: the user added, renamed or removed a folder of account
	// AccountID, or gave a folder a role. A sync round's folder changes come
	// with its sync.finished.
	FoldersChanged = "folders.changed"
	// Dropped: this subscriber's queue lost at least one event before this
	// one (Publish). The subscriber pulls core.Service.Changes, or re-reads
	// everything. The Bus makes it; nobody publishes it.
	Dropped = "events.dropped"
)

Variables

This section is empty.

Functions

func Command added in v1.36.0

func Command(t string) bool

Command reports whether an event of type t asks the interface to do something (a click, the tray's Open, Compose or Quit) rather than telling it what changed: a reader that falls behind may lose the latter only.

Types

type Bus

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

Bus fans events out to subscribers. Publish never blocks.

func New

func New() *Bus

New returns an empty Bus.

func (*Bus) Publish

func (b *Bus) Publish(e Event)

Publish delivers e to every subscriber without blocking. Past a full out, a subscriber's queue keeps at most subscriberBuffer events, losing its oldest that is not a Command (UI only, lossy by design; plugins read the database cursor): the tray's Open or Quit and clicks survive a burst. The first event lost becomes a Dropped marker in its place, so the subscriber learns of the loss in order; one marker stands for every loss before it. The tap (Tap) sees e first, in the same order for every publisher.

func (*Bus) Subscribe

func (b *Bus) Subscribe() (<-chan Event, func())

Subscribe returns a channel of events and a func that unsubscribes it. The unsubscribe func closes the channel and is safe to call more than once.

func (*Bus) Tap added in v1.43.0

func (b *Bus) Tap(f func(Event))

Tap makes f see every event Publish gets, before any subscriber, in the order Publish took them. f runs under the Bus's lock, so it must be fast and must not publish. Core's change journal (ADR 0051) is the tap: unlike a subscriber, it never loses an event.

type Event

type Event struct {
	Type       string
	AccountID  int64
	FolderID   int64
	ThreadIDs  []int64
	MessageIDs []int64
	Error      string
	// Kind is a sync.failed's conn.FailureKind (dns, connect, timeout, tls,
	// auth, protocol), or empty when the connection was fine.
	Kind string
	// ConversationID is set on approvals.changed and runs.changed.
	ConversationID int64
	// Done and Total are set on import.progress.
	Done, Total int
	// Notification is set on notification.clicked: the clicked notification's ID.
	Notification string
	// DraftID is set on a drafts.changed that changed one draft's content
	// outside its compose window (Wit's edit_draft): one open on it reloads.
	DraftID int64
}

Event describes something that happened. Only IDs are carried, never IMAP UIDs.

Jump to

Keyboard shortcuts

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