1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-05 21:15:38 -05:00

media: suppress media OSD on new players for 2s

fixes #838
This commit is contained in:
bbedward
2025-11-30 00:35:24 -05:00
parent dde426658f
commit 4eee126d26
2 changed files with 26 additions and 9 deletions

View File

@@ -10,6 +10,13 @@ BasePill {
readonly property MprisPlayer activePlayer: MprisController.activePlayer
readonly property bool playerAvailable: activePlayer !== null
readonly property bool __isChromeBrowser: {
if (!activePlayer?.identity)
return false;
const id = activePlayer.identity.toLowerCase();
return id.includes("chrome") || id.includes("chromium");
}
readonly property bool usePlayerVolume: activePlayer && activePlayer.volumeSupported && !__isChromeBrowser
property bool compactMode: false
property var widgetData: null
readonly property int textWidth: {
@@ -49,14 +56,8 @@ BasePill {
wheelEvent.accepted = true;
// If volume is not supported, return early to avoid error logs but accepting the scroll,
// to keep the consistency of not scrolling workspaces when scrolling in the media widget.
if (!activePlayer.volumeSupported) {
return;
}
const delta = wheelEvent.angleDelta.y;
const currentVolume = (activePlayer.volume * 100) || 0;
const currentVolume = usePlayerVolume ? (activePlayer.volume * 100) : ((AudioService.sink?.audio?.volume ?? 0) * 100);
let newVolume;
if (delta > 0) {
@@ -65,7 +66,11 @@ BasePill {
newVolume = Math.max(0, currentVolume - 5);
}
activePlayer.volume = newVolume / 100;
if (usePlayerVolume) {
activePlayer.volume = newVolume / 100;
} else if (AudioService.sink?.audio) {
AudioService.sink.audio.volume = newVolume / 100;
}
}
content: Component {

View File

@@ -10,6 +10,18 @@ DankOSD {
readonly property var player: MprisController.activePlayer
readonly property int currentVolume: player ? Math.min(100, Math.round(player.volume * 100)) : 0
readonly property bool volumeSupported: player?.volumeSupported ?? false
property bool _suppressNewPlayer: false
onPlayerChanged: {
_suppressNewPlayer = true;
_suppressTimer.restart();
}
Timer {
id: _suppressTimer
interval: 2000
onTriggered: _suppressNewPlayer = false
}
osdWidth: useVertical ? (40 + Theme.spacingS * 2) : Math.min(260, Screen.width - Theme.spacingM * 2)
osdHeight: useVertical ? Math.min(260, Screen.height - Theme.spacingM * 2) : (40 + Theme.spacingS * 2)
@@ -41,7 +53,7 @@ DankOSD {
target: player
function onVolumeChanged() {
if (SettingsData.osdMediaVolumeEnabled && volumeSupported) {
if (SettingsData.osdMediaVolumeEnabled && volumeSupported && !_suppressNewPlayer) {
root.show();
}
}