mpris: pick the now-playing player by mixer category (music > games > all) #1

Merged
charles merged 2 commits from mpris-music-priority into main 2026-08-05 09:58:16 +00:00
Owner

The now-playing strip held whichever player started first for as long as it kept playing, so a YouTube tab would keep the display even once a music app started.

rescan() now ranks players and lets the best-ranked Playing one win. Ranking comes from the app's mixer category via ConfigStore::categoryOf(), so the categories already edited in the mixer drive the strip too: music > games > everything else. all is the catch-all slot, so chat/hidden/uncategorized apps land there.

Category lookup goes through a resolver callback rather than MediaMpris depending on ConfigStore, keeping it testable standalone. The resolver keys on the MPRIS bus-name head (Feishin), which matches the config's app stems — the owning pid's executable is only a fallback, since every Electron app reports a generic /proc exe (electron) and would otherwise be unclassifiable.

The existing anti-flap behaviour is preserved: ties keep the incumbent, so two browser tabs don't fight over the display, and 'hold the current player when nothing is playing' is unchanged. Preemption requires a strictly better rank.

Verified against the real config.json through the real ConfigStore:

rank 0  Feishin (music)      music outranks games
rank 0  mpv     (music)      games outranks uncategorized
rank 1  dota2   (games)      music outranks uncategorized
rank 2  discord (chat -> all) chat and uncategorized share the 'all' tier
rank 2  firefox (-> all)     two music apps tie (no flapping)
The now-playing strip held whichever player started first for as long as it kept playing, so a YouTube tab would keep the display even once a music app started. `rescan()` now ranks players and lets the best-ranked *Playing* one win. Ranking comes from the app's mixer category via `ConfigStore::categoryOf()`, so the categories already edited in the mixer drive the strip too: **music > games > everything else**. `all` is the catch-all slot, so chat/hidden/uncategorized apps land there. Category lookup goes through a resolver callback rather than `MediaMpris` depending on `ConfigStore`, keeping it testable standalone. The resolver keys on the MPRIS bus-name head (`Feishin`), which matches the config's app stems — the owning pid's executable is only a fallback, since every Electron app reports a generic `/proc` exe (`electron`) and would otherwise be unclassifiable. The existing anti-flap behaviour is preserved: ties keep the incumbent, so two browser tabs don't fight over the display, and 'hold the current player when nothing is playing' is unchanged. Preemption requires a strictly better rank. Verified against the real `config.json` through the real `ConfigStore`: ``` rank 0 Feishin (music) music outranks games rank 0 mpv (music) games outranks uncategorized rank 1 dota2 (games) music outranks uncategorized rank 2 discord (chat -> all) chat and uncategorized share the 'all' tier rank 2 firefox (-> all) two music apps tie (no flapping) ```
rescan() held the current player for as long as it stayed Playing, so
whichever player started first kept the now-playing display for good:
start a YouTube tab, then start Feishin, and the tab never gave it up.
The fallback path was no better, taking the first Playing player in
registeredServiceNames() order, which is arbitrary.

Rank players instead and let the best-ranked Playing one win. Ranking
comes from a "*"-anchored priority list -- music apps ahead of the
wildcard, browsers behind it -- so an unlisted player still outranks a
browser rather than sinking to the bottom.

The anti-flap behaviour is kept: ties keep the incumbent, so two browser
tabs both playing don't fight over the display, and the "hold the current
player when nothing is playing" rule is unchanged. Preemption needs a
strictly better rank.

The list is a compile-time default for now, with setPlayerPriority() left
in place to wire it to a config key later.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The previous commit ranked players against a baked-in list of app names,
which meant every new music player had to be added to the source. Rank by
the app's mixer category instead, reusing ConfigStore::categoryOf() so the
categories already edited in the mixer drive the now-playing strip too:
music > games > everything else.

"all" is the catch-all slot in the priority list -- any category not named
(chat, hidden) and any uncategorized app rank there, so a category listed
after "all" sorts below everything unknown.

Category lookup goes through a resolver callback rather than MediaMpris
depending on ConfigStore directly, which keeps it testable standalone. The
resolver keys on the MPRIS bus-name head ("Feishin"), which matches the
config's app stems; the owning pid's executable is only a fallback, since
every Electron app reports a generic /proc exe ("electron") and would
otherwise be unclassifiable.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
charles/mirabox-application!1
No description provided.