Skip to content

fix(media-keys): route macOS and Windows play/pause through the App's native helpers - #995

Merged
LargeModGames merged 5 commits into
LargeModGames:mainfrom
Radhik-Amp:fix/media-keys-native-pause-macos-windows
Nov 13, 2026
Merged

LargeModGames merged 5 commits into
LargeModGames:mainfrom
Radhik-Amp:fix/media-keys-native-pause-macos-windows

Conversation

@Radhik-Amp

@Radhik-Amp Radhik-Amp commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Refs #985. Follow-up to #986, which fixed the MPRIS arms on Linux.

  • handle_macos_media_events and handle_windows_media_events in src/runtime/startup.rs still called player.play() / player.pause() directly, so the playbar waited for librespot's Playing/Paused event, the same bug as MPRIS Play/Pause stops audio but spotatui keeps showing and reporting playing #985. Now Playing and the Windows media controls still update on that event for native playback.
  • The macOS Play, Pause, PlayPause and Stop keys and the Windows Play, Pause and Stop controls now go through App::pause_native_playback() / App::resume_native_playback(), like the TUI key and the MPRIS arms.
  • Both handlers decide whether the local player takes a key under the same lock that acts, so a player that recovery removed in between can't be paused or resumed by a stale handle.
  • macOS PlayPause picks its direction from native_is_playing and falls back to shared_is_playing only while it is still None, as on Linux. The direction is now a pure function, play_key_resumes, and the Linux PlayPause arm uses it through press_local_play_key, with no change in behavior.
  • route_remote_spotify_macos_event now counts the local player as playing only while native_is_playing isn't Some(false) (local_player_is_playing, the expression from fix(mpris): route play/pause through the App's native helpers #986 with a name). Without it, the new PlayPause would resume locally after another device took over, because shared_is_playing can still say playing then. It pauses that device instead.
  • macOS Stop no longer calls set_native_playback_intent(false) itself; pause_native_playback() already does.
  • Windows keeps its routing as it was: the local player takes a key only when it is available and a track is loaded (native_track_info), otherwise the Spotify fallback. Only what happens on the local player changed. That routing doesn't have the stale-flag problem: when another device takes over, the Stopped event clears native_track_info together with native_is_playing, and the playback poll clears it too, so the key goes to the fallback and pauses that device.
  • Next, Previous and Windows seeking are unchanged.
  • The changelog entry from fix(mpris): route play/pause through the App's native helpers #986 gets one sentence for macOS and Windows.

Testing

On main at 2b6e9bd, Fedora 44:

  • cargo fmt --all -- --check: clean
  • cargo clippy --no-default-features --features telemetry,tui -- -D warnings and cargo clippy -- -D warnings: clean
  • cargo clippy with the gui leg's features (without audio-viz, no PipeWire headers here): clean
  • cargo test --no-default-features --features telemetry,tui: test result: ok. 1925 passed; 0 failed
  • cargo test: test result: ok. 2458 passed; 0 failed; 8 ignored
  • New tests in runtime::startup::media_key_tests (streaming + MPRIS on Linux, or macOS media):
    • a_stale_librespot_playing_flag_does_not_keep_the_media_keys_after_a_takeover
    • a_toggle_reads_the_app_play_state_before_librespot
    • a_toggle_follows_librespot_until_the_app_knows_the_play_state
    • play_and_pause_keys_ignore_the_play_state
    • a_pause_key_then_a_toggle_pauses_then_resumes_the_last_playback

macOS 27.0.1:

  • cargo clippy with the macOS job's feature list: clean
  • cargo test media_key_tests: test result: ok. 8 passed; 0 failed
  • cargo run: the ⏯ key and Control Center's Now Playing play/pause pause and resume, and the playbar follows at once.

Windows:

  • Desktop workflow on windows-latest (compiles the root crate with windows-media): run 42553881516 passed
  • Not run on a Windows machine.

Additional notes

The new tests cover the decisions the handlers make (play_key_resumes, local_player_is_playing, press_local_play_key), not the handlers themselves, which run in the OS media loops. Windows has no new test: its routing decision is the same as before.

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes
    • MPRIS commands, media keys, macOS Now Playing, and Windows media controls now follow the app’s play/pause handling.
    • Playback state is more reliably reflected when another Spotify device takes over or local playback resumes.
    • Windows controls fall back to Spotify playback when no local track is loaded.

@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 69330f5 and 2a676de.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

MPRIS, macOS, and Windows media-key handlers now use App playback methods for play, pause, and stop actions. Local-player selection and toggle behavior account for App playback state alongside librespot’s shared state. macOS and Windows handlers use Spotify fallback routing in specified cases.

Changes: Cross-platform media-key playback routing

Layer / File(s) Summary
App-aware playback state and routing
src/runtime/startup.rs
Local-player selection and play/pause toggles use App playback state alongside librespot’s shared state. Tests cover stale shared state, state precedence, and toggle behavior.
Platform media-key handlers
src/runtime/startup.rs, CHANGELOG.md
MPRIS, macOS, and Windows play, pause, and stop handling uses App playback methods. macOS and Windows handlers use Spotify fallback routing in the described cases. The changelog names media keys, macOS Now Playing, and Windows media controls.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related PRs

  • LargeModGames/spotatui#986: Routes Linux MPRIS playback actions through App playback helpers. This PR uses the same helpers for macOS and Windows media actions.
  • LargeModGames/spotatui#954: Adds party-relay checks to macOS and Windows media-key handlers. This PR changes the local-player action in those handlers.
Merge Risk: Minimal · previous review 69330

This change makes macOS and Windows media keys update the playbar immediately by using the app's own playback helpers. No actionable merge-blocking risk was identified in the supplied material.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title uses the permitted fix(media-keys): prefix and clearly describes routing macOS and Windows play/pause actions through App helpers.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Simplify code

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e1c6c45 and 69330f5.

Files selected for processing: 1

  • CHANGELOG.md
Files skipped from review as they are similar to previous changes: 1

  • CHANGELOG.md

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

@Radhik-Amp Radhik-Amp changed the title Fix/media keys native pause macos windows fix(media-keys): route macOS and Windows play/pause through the App's native helpers Nov 9, 2026
@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.19608% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/runtime/startup.rs 90.1% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

@LargeModGames LargeModGames left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The comments at startup.rs:1499 and :1775 say Now Playing and SMTC follow at once, but for native playback they still only update on librespot's Playing/Paused event. Can you say "the playbar" there instead?

@Radhik-Amp

Copy link
Copy Markdown
Contributor Author

Thanks, I was mistaken. I changed both comments in startup.rs to say "the playbar" , and also fixed some wording for the helper's comments as well. I also updated the changelog and the PR description.

…-pause-macos-windows

# Conflicts:
#	CHANGELOG.md

@kapok-4o kapok-4o left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for picking this up after #986. I read the macOS and Windows handlers against main and the logic holds: the routing order is unchanged, the play/pause decision now happens under the lock that acts, and windows-media pulls in streaming, so resume_native_playback / pause_native_playback exist wherever the Windows handler compiles. player_opt and is_native_loaded are still used by SetPosition, so nothing goes unused there.

Notes, none blocking:

  • No PR leg compiles target_os = "windows" (the desktop.yml Windows job runs on main only), and a cross-check from macOS stops at ring's C build, so the Windows half is read, not compiled. If someone with a Windows box can run cargo clippy with cd.yml's Windows features before the merge, that closes it.
  • One behavior change worth a line in the description: on macOS, Play or PlayPause with a local player but nothing loaded used to call player.play() on an empty player and do nothing. It now goes through resume_native_playback, which dispatches StartPlayback(None, None, None) and resumes the last playback, like the TUI key. That looks like the right outcome.
  • Nit: after the early continue, the PlayPause | Play | Pause | Stop => {} arms in both handlers can't be reached. Matching only Next/Previous (and SetPosition on Windows) in an if let or a match with _ => {} would say that directly. Fine as is if you prefer the exhaustive match.

@LargeModGames
LargeModGames merged commit a9c412e into LargeModGames:main Nov 13, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants