Skip to content

Register data sources behind one interface, including event-driven ones #17

Closed

Description

@M4n0x

Problem

The built-in data sources are a fixed list, repeated in several places: ProviderType (Sources/StableBar/ProviderConfiguration.swift:3), the NativeMetrics.sample switch (Sources/StableBar/NativeMetrics.swift:55), ScriptWidget.Source (Sources/StableBar/ScriptWidget.swift:79) and the type checks in Sources/StableBar/Configuration.swift:289 and :377. Adding a source means changing all of them and the schema.

Built-in sources are also only sampled on a timer (ScriptWidget.swift:158), every 5 s by default. Sources that macOS pushes don't fit:

  • The audio provider reads the default output device on each poll (NativeMetrics.swift:158) instead of listening for volume, mute and device changes, so a volume key press can take seconds to show.
  • Power-source changes are already observed, but only to match profiles (Sources/StableBar/SystemContext.swift:27).
  • EventKit change notifications and Bluetooth connections have nowhere to go.

No source can declare that it needs a permission (Calendars, Bluetooth, Automation), so setup can't ask before a widget fails.

Built-in events are wired one at a time in BarStore (Sources/StableBar/BarStore.swift:48, :54, :73, :220), alongside configuration loading, process lifecycle and actions. Scripts get no event for volume or power changes.

Proposal

  1. A DataSource protocol that pushes output: start(emit:), refresh(event:), stop(). Polling becomes an adapter, and command and stream become sources as well. ScriptWidget stays the generic runner: diagnostics, retry backoff, suspension.
  2. A registry entry for each source: its type name, settings decoder (also used by the schema), required permission, and the events it emits. Configuration validation reads from the registry.
  3. One table of built-in events, giving each name and what INFO holds, and checked against the README the way the schema is checked against the decoders. Push sources add events such as volumeChange, outputDeviceChange and powerSourceChange.
  4. Setup lists the permissions that enabled sources need.

This would unlock:

  • Audio through CoreAudio listeners: immediate volume, mute and device changes, plus a volumeChange event
  • Battery updates when the power source changes
  • A disk provider (used and free space of a volume)
  • A nowPlaying provider (Spotify and Music distributed notifications, artwork URL)
  • A bluetooth provider (connected devices)
  • The calendar provider, Add a calendar provider for the next meeting and today's agenda #18

Possible today

Partly. A stream provider can push updates, for example a helper that prints a line whenever the output device changes. Each such source needs its own helper process, and built-in providers can't be made event-driven.

Related

#6 (yabai) adds a workspace source beside AeroSpace, and its events could use the same table.

Triaged by Claude Code (Claude Opus 5.5).

Activity

  1. added
    enhancement
    on Oct 15, 2026
  2. M4n0x commented on Oct 15, 2026

    @M4n0x
    CollaboratorAuthor

    Performance

    Push sources should reduce work, since audio would no longer be polled every 5 s, as long as bursts are coalesced. Holding a volume key fires a stream of CoreAudio notifications, and a calendar sync can post EKEventStoreChanged many times in a row.

    Requirements for this change:

    • Every source, including push ones, emits through the runner's single-slot queue (AsyncStream with .bufferingNewest(1), Sources/StableBar/ScriptWidget.swift:117), so a burst collapses to its newest value.
    • A source emits only when its output changed, so an unchanged sample doesn't invalidate any views. This needs ScriptOutput to be Equatable.
    • Native listeners are registered only while an enabled widget uses the source, and removed on suspension (whenVisible, sleep), the way polling stops today.
    • Moving a source from polling to push removes its timer rather than adding a listener beside it.

    Triaged by Claude Code (Claude Opus 5.5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions