1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-08-06 21:48:30 -04:00

fix(media-player): update Mpris stable metadata handling

- Restores Brave browsers
port 1.5

(cherry picked from commit fe1a783ec2)
This commit is contained in:
purian23
2026-07-15 20:57:05 -04:00
committed by dms-ci[bot]
parent 3d0ce17a8c
commit a55177f1d2
6 changed files with 181 additions and 123 deletions
+82 -10
View File
@@ -19,7 +19,8 @@ Singleton {
const desktopEntry = ("desktopEntry" in p && p.desktopEntry) ? String(p.desktopEntry).toLowerCase() : "";
return !excluded.some(ex => {
const exLower = String(ex).toLowerCase().trim();
if (!exLower) return false;
if (!exLower)
return false;
// 1. Substring match
if (identity.includes(exLower) || desktopEntry.includes(exLower))
@@ -43,43 +44,114 @@ Singleton {
}
property MprisPlayer activePlayer: null
property real activePlayerStableLength: 0
// Chromium can report blank metadata between tracks
property string stableTitle: ""
property string stableArtist: ""
Connections {
target: root.activePlayer
function onTrackTitleChanged() {
root.activePlayerStableLength = (root.activePlayer && root.activePlayer.lengthSupported && root.activePlayer.length > 1) ? root.activePlayer.length : 0;
root._syncStableMeta();
root._checkIdle();
}
function onTrackArtistChanged() {
root._syncStableMeta();
root._checkIdle();
}
function onLengthChanged() {
if (root.activePlayer && root.activePlayer.lengthSupported && root.activePlayer.length > 1) {
root.activePlayerStableLength = root.activePlayer.length;
}
}
function onPlaybackStateChanged() {
root._syncStableMeta();
root._checkIdle();
}
}
onActivePlayerChanged: {
activePlayerStableLength = (activePlayer && activePlayer.lengthSupported && activePlayer.length > 1) ? activePlayer.length : 0;
stableTitle = activePlayer?.trackTitle || "";
stableArtist = activePlayer?.trackArtist || "";
_checkIdle();
}
function _syncStableMeta(): void {
const p = activePlayer;
if (!p) {
stableTitle = "";
stableArtist = "";
return;
}
if (isFirefoxYoutubeHoverPreview(p))
return;
if (p.trackTitle)
stableTitle = p.trackTitle;
if (p.trackArtist)
stableArtist = p.trackArtist;
}
// Chromium reports stopped media w/blank metadata, resolve by checking idle status
Timer {
id: _idleGraceTimer
interval: 1223
onTriggered: {
if (!root.isIdle(root.activePlayer))
return;
root.stableTitle = "";
root.stableArtist = "";
root._resolveActivePlayer();
}
}
function _checkIdle(): void {
if (!isIdle(activePlayer)) {
_idleGraceTimer.stop();
return;
}
if (!_idleGraceTimer.running)
_idleGraceTimer.start();
}
onAvailablePlayersChanged: _resolveActivePlayer()
Component.onCompleted: _resolveActivePlayer()
Instantiator {
model: root.availablePlayers
delegate: Connections {
required property MprisPlayer modelData
target: modelData
function onIsPlayingChanged() {
if (modelData.isPlaying)
root._resolveActivePlayer();
}
}
}
function isIdle(player: MprisPlayer): bool {
return player
&& player.playbackState === MprisPlaybackState.Stopped
&& !player.trackTitle
&& !player.trackArtist;
return player && player.playbackState === MprisPlaybackState.Stopped && !player.trackTitle && !player.trackArtist;
}
function _resolveActivePlayer(): void {
// Keep the selected player stable across transient metadata changes.
if (activePlayer && availablePlayers.indexOf(activePlayer) >= 0)
return;
// A playing player always wins; otherwise keep the selection stable w/idle
const playing = availablePlayers.find(p => p.isPlaying);
if (playing) {
activePlayer = playing;
_persistIdentity(playing.identity);
if (activePlayer !== playing) {
activePlayer = playing;
_persistIdentity(playing.identity);
}
return;
}
if (activePlayer && availablePlayers.indexOf(activePlayer) >= 0 && (!isIdle(activePlayer) || _idleGraceTimer.running))
return;
if (activePlayer && availablePlayers.indexOf(activePlayer) < 0) {
const successor = availablePlayers.find(p => p.identity === activePlayer.identity);
if (successor) {
activePlayer = successor;
return;
}
}
const savedId = SessionData.lastPlayerIdentity;
if (savedId) {
const match = availablePlayers.find(p => p.identity === savedId);