fix: Media player auto-switching in Control Center

Detailed Explanation:
  Addresses an issue where the media player would automatically
switch,overriding user's manual selections when the Control Center was
open.

  The core problem was that the automatic player detection logic was too
aggressive and didn't respect explicit user choices. Previous attempts
to pause auto-switching based on UI visibility were unreliable due to
incorrect event handling for the custom NPanel component.
This commit is contained in:
loner
2025-11-01 02:15:44 +08:00
parent cf12b98351
commit 3b166bd270
3 changed files with 26 additions and 2 deletions
+1 -2
View File
@@ -179,8 +179,7 @@ NBox {
onTriggered: function (action) {
var index = parseInt(action)
if (!isNaN(index)) {
MediaService.selectedPlayerIndex = index
MediaService.updateCurrentPlayer()
MediaService.switchToPlayer(index)
}
}
}
@@ -63,6 +63,14 @@ NPanel {
readonly property int weatherHeight: Math.round(190 * Style.uiScaleRatio)
readonly property int mediaSysMonHeight: Math.round(260 * Style.uiScaleRatio)
onOpened: {
MediaService.autoSwitchingPaused = true
}
onClosed: {
MediaService.autoSwitchingPaused = false
}
panelContent: Item {
id: content
+17
View File
@@ -171,6 +171,21 @@ Singleton {
}
}
property bool autoSwitchingPaused: false
function switchToPlayer(index) {
let availablePlayers = getAvailablePlayers()
if (index >= 0 && index < availablePlayers.length) {
let newPlayer = availablePlayers[index]
if (newPlayer !== currentPlayer) {
currentPlayer = newPlayer
selectedPlayerIndex = index
currentPosition = currentPlayer ? currentPlayer.position : 0
Logger.d("Media", "Manually switched to player " + currentPlayer.identity)
}
}
}
// Switch to the most recently active player
function updateCurrentPlayer() {
let newPlayer = findActivePlayer()
@@ -289,6 +304,8 @@ Singleton {
repeat: true
running: true
onTriggered: {
Logger.d("MediaService", "playerStateMonitor triggered. autoSwitchingPaused: " + root.autoSwitchingPaused)
if (autoSwitchingPaused) return
// Only update if we don't have a playing player or if current player is paused
if (!currentPlayer || !currentPlayer.isPlaying || currentPlayer.playbackState !== MprisPlaybackState.Playing) {
updateCurrentPlayer()