mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-05-26 07:50:19 +00:00
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:
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user