Skip to content

fix: keep the Sound details open and smooth when picking a device - #931

Merged
M4n0x merged 3 commits into
mainfrom
fix/sound-switch-animation
Nov 25, 2026
Merged

M4n0x merged 3 commits into
mainfrom
fix/sound-switch-animation

Conversation

@M4n0x

@M4n0x M4n0x commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

In the Sound details, clicking an output or input device closed the popup, and its closing animation, and anything else animating on the bar, stalled for tens to hundreds of milliseconds. The card's other controls (volume, mute, an app's output menu) keep the popup open, and so does Control Center.

Fixes #928

Changes

  • AudioMixer reads CoreAudio off the main thread. It listened on .main and ran a full refresh() for every notification: the PID, bundle ID and playing state of about 33 processes, then every device, each a round trip to coreaudiod. A switch moves every app's sound to the new device, so it sends a burst of notifications while coreaudiod answers slowly. The listeners, the per-process watching and the reads now live in a private MixerReader on a queue of its own. The main actor only hands what it reads to MixerState. MixerState and the taps are unchanged.
  • QueueReader (DataSource.swift, next to MainQueueRelay): reads on its own queue after a change, once for a burst of changes, and hands the main queue only reads that differ from the last.
  • The device switch runs off the main thread. AudioMonitor.setDefaultDevice waits until coreaudiod has moved every app's sound: 72–86 ms in 4 of 10 tries while sound played. selectAudioDevice now goes through runAction with a new BlockAction.selectAudioDevice, so it runs in BlockingWork, after the widget's earlier actions, as volume and mute already do.
  • The device rows keep the popup open. A row in the Sound details sends its device as a control's value (["VALUE": id]), so dismissOnControl applies, which is off by default. Popups with selectOutputDeviceField or selectInputDeviceField blocks still follow dismissOnAction, as docs/popups.md describes. docs/widgets.md now says picking a device leaves the popup open.
  • Picking a device doesn't restart the Sound providers. runAction refreshes a widget after its action, which for the Sound details stops and starts the audio, microphone and Now Playing providers, each with CoreAudio calls on the main thread. Their listeners already follow the default device, so .selectAudioDevice skips that refresh, as main's direct switch did. cubic pointed it out.

No configuration change: BlockAction isn't decoded, and the schema is unchanged.

Testing

  • New tests in DataSourceTests: aBurstOfChangesIsReadOnceOffTheMainThread and aReaderSendsOnlyReadsThatChangeSomething. They failed (the type didn't exist) before QueueReader was added.

  • Full suite: 1,458 Swift Testing and 293 XCTest tests. One run after the rebase had one failing Swift Testing test. I didn't keep its log, so I can't name it, and it didn't fail again in 3 more full runs. swift build --build-tests, scripts/check.sh --quick and commitlint pass. After the last commit, DataSourceTests, ProviderTests, BarEditingTests and the popup tests (117) pass again.

  • Measured in the app, macOS 27.2. An isolated dev copy (its own bundle ID, a scratch configuration, no mixer settings and no taps) had its Sound popup open. While a script closed the popup and switched the default output to a USB headset and back, sample recorded the main thread at 1 ms:

    Main thread over 3 s with one switch main This branch
    Round 1: samples in AudioMixer 1,108 of 1,799 0 of 2,497 (2,471 idle)
    Round 2: samples in AudioMixer 1,237 of 1,862 0 of 2,305
    The same close with no switch, on main 0 of 2,386 (2,297 idle)

    On this branch the mixer's reads show up on the StableBar.AudioMixer queue instead. The only CoreAudio work left on the main thread is AudioMonitor's existing coalesced read (19 samples).

  • Not checked by hand: clicking a device row in the running app. The switches above came from a separate process, so the popup staying open and the off-main switch are covered only by the build and the code path that volume and mute already use. The popup looks the same, so no before/after images; a recording of a click would show the change.

  • fix: play an app's first sound at its mixer volume #899 also changes AudioMixer.swift, in perform. Now that fix: play an app's first sound at its mixer volume #899 is rebased onto main, a trial merge of both branches has no conflicts.

Merging

Three fix commits. A merge commit or a rebase merge keeps them all. To squash, keep the fix: title and Fixes #928.

Claude Opus 5.5 via Claude Code (T3 Code)

The mixer listened on the main queue and read every process and device
after each CoreAudio notification. A device switch sends a burst of them
while coreaudiod answers slowly, which held the main thread for over a
second and stalled the popup's animations.

A QueueReader now reads on a queue of its own, once for a burst of
changes, and hands the main queue only reads that changed.

Refs #928
Setting the default device waits for coreaudiod to move every app's
sound, up to about 90 ms while sound plays, and ran on the main thread.
It now runs through runAction and BlockingWork, as volume and mute do.

A device row in the Sound details now sends its device as a control's
value, so the popup stays open as Control Center's does. Popups with
selectOutputDeviceField blocks still follow dismissOnAction.

Fixes #928
@M4n0x
M4n0x requested a review from Seb-GRAF as a code owner November 25, 2026 10:00

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 7 files

You’re at about 95% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact [email protected].

Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack

Fix all with cubic | Re-trigger cubic

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Before and after

main at f1db91a → this pull request at 6a18acb · 340 screens drawn · 0 changed

340 unchanged screens

docs/essentials-clock-settings-dark, docs/essentials-clock-settings-light, docs/essentials-dark, docs/essentials-light, docs/essentials-settings-dark, docs/essentials-settings-light, docs/hero-dark, docs/hero-light, docs/popups-dark, docs/popups-light, docs/settings-dark, docs/settings-light, docs/themes-dark, docs/themes-light, scenes/accessibility-guide-dark, scenes/accessibility-guide-light, scenes/app-menu-popup-dark, scenes/app-menu-popup-light, scenes/apple-menu-settings-dark, scenes/apple-menu-settings-light, scenes/apple-menu-symbol-bar-dark, scenes/apple-menu-symbol-bar-light, scenes/apple-menu-symbol-settings-dark, scenes/apple-menu-symbol-settings-light, scenes/bar-dividers-dark, scenes/bar-dividers-light, scenes/bottom-bar-popup-dark, scenes/bottom-bar-popup-light, scenes/chat-popup-dark, scenes/chat-popup-light, scenes/crowded-edit-bar-dark, scenes/crowded-edit-bar-light, scenes/disk-meter-bar-dark, scenes/disk-meter-bar-light, scenes/dock-badges-bar-dark, scenes/dock-badges-bar-light, scenes/edit-bar-wide-group-dark, scenes/edit-bar-wide-group-light, scenes/essentials-clock-popup-dark, scenes/essentials-clock-popup-light, scenes/essentials-disk-popup-dark, scenes/essentials-disk-popup-light, scenes/filled-slider-popup-dark, scenes/filled-slider-popup-light, scenes/glass-text-follows-background-bar-dark, scenes/glass-text-follows-background-bar-light, scenes/group-members-bar-dark, scenes/group-members-bar-light, scenes/group-others-bar-dark, scenes/group-others-bar-light, scenes/group-text-color-bar-dark, scenes/group-text-color-bar-light, scenes/gruvbox-bar-dark, scenes/gruvbox-bar-light, scenes/horizontal-list-popup-dark, scenes/horizontal-list-popup-light, scenes/increase-contrast-bar-dark, scenes/increase-contrast-bar-light, scenes/increase-contrast-popup-dark, scenes/increase-contrast-popup-light, scenes/input-source-popup-dark, scenes/input-source-popup-light, scenes/labeled-metric-built-in-dark, scenes/labeled-metric-built-in-light, scenes/labeled-metric-catppuccin-dark, scenes/labeled-metric-catppuccin-light, scenes/meeting-live-popup-dark, scenes/meeting-live-popup-light, scenes/meeting-soon-bar-dark, scenes/meeting-soon-bar-light, scenes/menu-bar-items-widget-settings-dark, scenes/menu-bar-items-widget-settings-light, scenes/menu-bar-items-widget-style-dark, scenes/menu-bar-items-widget-style-light, scenes/merged-status-bar-dark, scenes/merged-status-bar-light, scenes/notch-flare-bar-dark, scenes/notch-flare-bar-light, scenes/output-device-popup-dark, scenes/output-device-popup-light, scenes/package-template-clash-bar-dark, scenes/package-template-clash-bar-light, scenes/popup-gap-bar-dark, scenes/popup-gap-bar-light, scenes/popup-spacing-bar-dark, scenes/popup-spacing-bar-light, scenes/popup-view-dark, scenes/popup-view-light, scenes/preset-dashboard-bar-dark, scenes/preset-dashboard-bar-light, scenes/preset-developer-bar-dark, scenes/preset-developer-bar-light, scenes/preset-everyday-bar-dark, scenes/preset-everyday-bar-light, scenes/preset-minimal-bar-dark, scenes/preset-minimal-bar-light, scenes/preset-workday-bar-dark, scenes/preset-workday-bar-light, scenes/privacy-both-bar-dark, scenes/privacy-both-bar-light, scenes/privacy-hide-when-idle-bar-dark, scenes/privacy-hide-when-idle-bar-light, scenes/privacy-idle-bar-dark, scenes/privacy-idle-bar-light, scenes/privacy-microphone-bar-dark, scenes/privacy-microphone-bar-light, scenes/privacy-settings-dark, scenes/privacy-settings-light, scenes/quick-toggles-bar-dark, scenes/quick-toggles-bar-light, scenes/quick-toggles-displays-popup-dark, scenes/quick-toggles-displays-popup-light, scenes/quick-toggles-every-tile-popup-dark, scenes/quick-toggles-every-tile-popup-light, scenes/quick-toggles-network-popup-dark, scenes/quick-toggles-network-popup-light, scenes/quick-toggles-networks-popup-dark, scenes/quick-toggles-networks-popup-light, scenes/quick-toggles-popup-dark, scenes/quick-toggles-popup-light, scenes/reduce-transparency-bar-dark, scenes/reduce-transparency-bar-light, scenes/reduce-transparency-glass-bar-dark, scenes/reduce-transparency-glass-bar-light, scenes/reduce-transparency-text-follows-background-bar-dark, scenes/reduce-transparency-text-follows-background-bar-light, scenes/ring-bar-dark, scenes/ring-bar-light, scenes/settings-bar-dark, scenes/settings-bar-light, scenes/settings-bar-link-dark, scenes/settings-bar-link-light, scenes/settings-bar-link-review-dark, scenes/settings-bar-link-review-light, scenes/settings-bar-link-workspace-color-dark, scenes/settings-bar-link-workspace-color-light, scenes/settings-bar-look-dark, scenes/settings-bar-look-light, scenes/settings-bar-placement-bottom-dark, scenes/settings-bar-placement-bottom-light, scenes/settings-bar-placement-dark, scenes/settings-bar-placement-light, scenes/settings-calendar-picker-dark, scenes/settings-calendar-picker-light, scenes/settings-calendar-widget-dark, scenes/settings-calendar-widget-light, scenes/settings-clock-widget-dark, scenes/settings-clock-widget-light, scenes/settings-crashes-dark, scenes/settings-crashes-light, scenes/settings-disk-widget-dark, scenes/settings-disk-widget-light, scenes/settings-feedback-dark, scenes/settings-feedback-light, scenes/settings-general-dark, scenes/settings-general-kiwidesk-dark, scenes/settings-general-kiwidesk-light, scenes/settings-general-light, scenes/settings-general-macos15-dark, scenes/settings-general-macos15-light, scenes/settings-general-macos27-dark, scenes/settings-general-macos27-light, scenes/settings-general-manager-not-found-dark, scenes/settings-general-manager-not-found-light, scenes/settings-general-move-dark, scenes/settings-general-move-failed-dark, scenes/settings-general-move-failed-light, scenes/settings-general-move-light, scenes/settings-general-move-moving-dark, scenes/settings-general-move-moving-light, scenes/settings-general-move-replace-dark, scenes/settings-general-move-replace-light, scenes/settings-general-setup-open-dark, scenes/settings-general-setup-open-light, scenes/settings-general-spaces-dark, scenes/settings-general-spaces-light, scenes/settings-general-yabai-gap-dark, scenes/settings-general-yabai-gap-light, scenes/settings-group-dark, scenes/settings-group-defaults-dark, scenes/settings-group-defaults-light, scenes/settings-group-light, scenes/settings-group-theme-color-dark, scenes/settings-group-theme-color-light, scenes/settings-help-dark, scenes/settings-help-light, scenes/settings-help-starred-dark, scenes/settings-help-starred-light, scenes/settings-labeled-metric-dark, scenes/settings-labeled-metric-light, scenes/settings-narrow-dark, scenes/settings-narrow-light, scenes/settings-package-dark, scenes/settings-package-light, scenes/settings-package-widget-dark, scenes/settings-package-widget-light, scenes/settings-profiles-conditions-dark, scenes/settings-profiles-conditions-light, scenes/settings-profiles-dark, scenes/settings-profiles-groups-dark, and 140 more

Visual review: 340 screens, none changed.

Picking a device went through the widget's action, which refreshes the widget afterwards and so
restarted the audio, microphone and Now Playing providers on the main thread while coreaudiod was
still busy. Their listeners already follow the default device, so that action skips the refresh,
as the direct switch did before.
@M4n0x M4n0x added the deep-review CodeRabbit reviews this pull request: big or risky changes label Nov 25, 2026
@coderabbitai

coderabbitai Bot commented Nov 25, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds serialized background reads for audio state, moves CoreAudio monitoring into MixerReader, and routes Sound device selection through the shared action path. The Sound documentation now states that the details popup remains open after device selection.

Changes: Audio device flow

Layer / File(s) Summary
Queued reads and validation
Sources/StableBar/DataSources/DataSource.swift, Tests/StableBarTests/DataSourceTests.swift
QueueReader performs serialized reads and sends changed, non-nil values to the main queue. Tests cover notification bursts, off-main reads, and value changes.
CoreAudio mixer reads
Sources/StableBar/DataSources/AudioMixer.swift
AudioMixer creates a MixerReader to read CoreAudio state and watch properties on its reader queue. MixerReader gathers snapshots and passes updates to MixerState.
Device selection action flow
Sources/StableBar/Configuration/PopupConfiguration.swift, Sources/StableBar/Popups/SoundDetails.swift, Sources/StableBar/DataSources/WidgetScripts.swift, docs/widgets.md
Sound device selection now uses a BlockAction through runAction. The shared action path sets the default device in blocking work, and the documentation says the details popup stays open.

Possibly related PRs

  • stablebox/StableBar#877: Adds the Sound details popup, its device rows, and the AudioMixer that this change updates.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 6a18a

Selecting a device in Sound details should now keep the popup open and avoid stalling animations, and the changes read as consistent with that goal. The one gap is that clicking a device row in the running app was not checked by hand. It is worth a quick manual check before release, but it does not block merging.

Security architecture risk: Low · up to 6a18a

Audio device selection still uses the same permissions, but its timing changes. Selections from different widgets can finish out of order, and a selection still waiting when the app quits can be dropped.

Retained concerns

  • Low · reliability · inferred: The previous synchronous path completed each app-issued selection before handling another. The new path orders selections only within a widget, even though all widgets write to the same macOS input or output default. A selection delayed behind an earlier action on one widget can therefore overwrite a newer selection from another widget.
  • Low · reliability · observed: Application teardown can now cancel an accepted device selection before it reaches CoreAudio, without recording an action error. Once the write has been dispatched, cancellation does not retract it. The previous inline setter did not have this queued-versus-dispatched shutdown distinction.
Security review details

Security Blast Radius

  • observed — The write changes one of the local Mac's shared input or output defaults, not a widget-local setting. It still targets the same CoreAudio system object as at the merge base.

Trust Boundaries and Controls

  • observed — Device IDs still originate in Sound Details rows or configured selection fields. The new action case is internal rather than configuration-decodable, submission checks whether widget actions are allowed, and the same setter converts the value to a numeric audio device ID before calling CoreAudio.
Pre-merge checks: Passed 3

Check name Status Explanation
Description check Passed The description follows the repository template closely: it has Problem (with Fixes #928), Changes, Testing, and Merging sections, and it ends with the model and harness line. It explains the cause, t…
Linked Issues check Passed [#928] Objectives: (1) a device click keeps the Sound details popup open; (2) the device switch and mixer reads do not stall the main thread; (3) the checkmark still moves. Evidence at head: SoundDeta…
Out of Scope Changes check Passed All changed files connect to #928. BlockAction gains selectAudioDevice (PopupConfiguration.swift) to route the device switch through runAction. WidgetScripts.swift changes the device path and skips …
Full details: Description check

Explanation

The description follows the repository template closely: it has Problem (with Fixes #928), Changes, Testing, and Merging sections, and it ends with the model and harness line. It explains the cause, the fix, the tests run, the measurements taken, and what was not checked by hand. The Merging section states how the commits should be merged. The description is detailed and matches the scope of the changes in the raw summary. Minor gaps: the Testing section says no before/after images are included, which the template asks to address for visible changes, but the author gives a reason and suggests a recording. The description is complete enough to pass.

Full details: Linked Issues check

Explanation

[#928] Objectives: (1) a device click keeps the Sound details popup open; (2) the device switch and mixer reads do not stall the main thread; (3) the checkmark still moves. Evidence at head: SoundDetails.swift now sends a device click as context.runAction(.selectAudioDevice(id, input:), ["VALUE": id]) instead of calling context.selectAudioDevice directly, so the control path applies. The PR description states that dismissOnControl is off by default; this assessment relies on that statement and on docs/widgets.md, and PopupView was not inspected. WidgetScripts.swift adds a BlockAction.selectAudioDevice case that calls AudioMonitor.setDefaultDevice inside BlockingWork.run, so the switch leaves the main thread. The same branch skips the post-action provider refresh for this action, so the audio, microphone and Now Playing providers are not restarted on the main thread. The mixer change (AudioMixer.swift, DataSource.swift QueueReader) moves listeners and reads to a private queue, per the summary; its behavior is supported by the PR's sampling measurements, which show 0 main-thread samples in AudioMixer on this branch. Two new DataSourceTests cover burst coalescing and changed-only sends. Clicking a row in the running app was not checked by hand, as the PR states.

Full details: Out of Scope Changes check

Explanation

All changed files connect to #928. BlockAction gains selectAudioDevice (PopupConfiguration.swift) to route the device switch through runAction. WidgetScripts.swift changes the device path and skips the provider refresh only for that action; other actions keep their refresh. SoundDetails.swift changes the device row action. AudioMixer.swift and DataSource.swift (QueueReader) move the mixer reads off the main thread, which the issue's diagnosis identifies as the cause of the stall. DataSourceTests.swift covers the new reader. docs/widgets.md documents that picking a device leaves the popup open, which matches the new behavior. The PR description notes that #899 also touches AudioMixer.swift in perform; that is a merge-coordination note, not an added change in this PR. No unrelated change was found in the reviewed hunks.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between f1db91a and 6a18acb.

Files selected for processing: 7

  • Sources/StableBar/Configuration/PopupConfiguration.swift
  • Sources/StableBar/DataSources/AudioMixer.swift
  • Sources/StableBar/DataSources/DataSource.swift
  • Sources/StableBar/DataSources/WidgetScripts.swift
  • Sources/StableBar/Popups/SoundDetails.swift
  • Tests/StableBarTests/DataSourceTests.swift
  • docs/widgets.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@M4n0x
M4n0x added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit df96453 Nov 25, 2026
27 checks passed
@M4n0x
M4n0x deleted the fix/sound-switch-animation branch November 25, 2026 12:22
stablebar-releases Bot pushed a commit that referenced this pull request Nov 29, 2026
## [0.20.0](v0.19.0...v0.20.0) (2026-11-29)

### Features

* animate widgets that a profile shows or hides ([#948](#948)) by @M4n0x ([eec8544](eec8544)), closes [#947](#947) [#947](#947)
* log quit causes and show unexpected quits in Status ([#953](#953)) by @M4n0x ([ea5a64e](ea5a64e)), closes [#952](#952)

### Bug Fixes

* choose a submenu item opened from the App menus tray ([#944](#944)) by @MaHofseth ([add49b0](add49b0)), closes [#942](#942)
* draw borders in whole pixels so they keep every edge on 1x screens ([#934](#934)) by @M4n0x ([8590fcd](8590fcd)), closes [#933](#933) [#933](#933)
* keep a package version installed when its folder is hidden ([#962](#962)) by @M4n0x ([2d97d15](2d97d15)), closes [#961](#961)
* keep the Sound details open and smooth when picking a device ([#931](#931)) by @M4n0x ([df96453](df96453)), closes [#928](#928) [#928](#928)
* keep windows clear of the bar after a double-click fills them ([#936](#936)) by @M4n0x ([c1478d1](c1478d1)), closes [#935](#935) [#935](#935)
* leave the keyboard with the app while StableBar shows its menus ([#943](#943)) by @MaHofseth ([abc1c4f](abc1c4f)), closes [#941](#941)
* play an app's first sound at its mixer volume ([#899](#899)) by @M4n0x ([2c38350](2c38350)), closes [#897](#897) [#897](#897)
* show a turned-off widget's last output when it comes back ([#950](#950)) by @M4n0x ([6776fcb](6776fcb)), closes [#949](#949) [#949](#949)
* show Countdown and Join in Settings after picking it ([#940](#940)) by @MaHofseth ([6ecaa72](6ecaa72))
* stop offering a package update that is already installed ([#956](#956)) by @M4n0x ([4592ebc](4592ebc))
@stablebar-releases

Copy link
Copy Markdown

🎉 This PR is included in version 0.20.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

deep-review CodeRabbit reviews this pull request: big or risky changes released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Picking a sound device closes the Sound details and stalls their animation

1 participant