MenuBarExtraProviding

Adopt to contribute a menu bar extra.

@MainActor protocol MenuBarExtraProviding : Droplet

This is the only supported way to offer something from the menu bar. The host shows the extra as a tile in Droppy's Command Center (the panel under Droppy's one menu bar icon): its symbol and title, and a press opens its content. The first time a droplet offers an extra, the host puts its tile on a Command Center page; the user can move, resize or remove it like any tile. The host owns the tile and its content, and withdraws both when the droplet is disabled, updated, removed, or fails to deactivate. Never create an NSStatusItem of your own: a droplet runs in-process, so nothing stops you, but Droppy cannot order, hide or remove an item it did not create, and one your teardown misses stays in the user's menu bar with no owner until Droppy quits.

When the host reads the extra

The host calls makeMenuBarExtra() and adds, updates or removes the tile to match:

  • when the droplet starts, stops, is updated or is removed;
  • each time the user opens its content;
  • after the droplet broadcasts a state change, which is any of these: its objectWillChange fires (when the droplet is an ObservableObject, as every droppykit new scaffold is); one of its keys in DropletPreferencesService changes; an @Observable property read during the previous call changes (when the droplet is not an ObservableObject); or statePublisher fires.

So a "Show in Command Center" switch stored through host.preferences applies at once, and an extra that returns nil until something starts appears when it starts. State held by another object reaches the host only through one of those broadcasts: forward that object's objectWillChange to the droplet's own, or store the value in preferences.

Broadcasts are coalesced: a burst costs one call, and the host makes at most about four a second however often the droplet broadcasts. It redraws the tile only when systemImage or title changed, so a symbol or a short title is the way to show live state; never animate it by returning a new symbol every frame.

Hosts up to Droppy 16.0.1 read the extra only when the droplet starts, stops, is updated or is removed. Hosts before the Command Center showed the extra as a status item of its own, with its content in a menu.

  • Note: Maturity: Supported. The host consumer has been available since 0.3.2. Requires the menu-bar capability.

Methods

makeMenuBarExtra()

@MainActor func makeMenuBarExtra() -> MenuBarExtraDescriptor?

The extra to show, or nil when the droplet currently contributes none. Returning nil is how a droplet withdraws its extra; the host removes its tile. Called on the occasions listed above, never on a timer; keep it cheap and free of side effects.