code cleanup: deduplicate volume icon logic, mpris time format, sink list

This commit is contained in:
Damocles 2026-04-12 18:08:36 +02:00
parent 5dc966c916
commit 5dcea32dc3
3 changed files with 30 additions and 49 deletions

View file

@ -9,7 +9,12 @@ M.PopupPanel {
required property MprisPlayer player
// Album art
function _fmtTime(ms) {
const s = Math.floor(ms / 1000);
const m = Math.floor(s / 60);
return m + ":" + String(s % 60).padStart(2, "0");
}
Item {
width: menuWindow.panelWidth
height: _artImg.status === Image.Ready ? 140 : 60
@ -28,7 +33,6 @@ M.PopupPanel {
visible: status === Image.Ready
}
// Gradient fade at the bottom so art blends into the panel
Rectangle {
anchors.left: parent.left
anchors.right: parent.right
@ -41,7 +45,6 @@ M.PopupPanel {
}
}
// Fallback icon when no art
Text {
anchors.centerIn: parent
text: "\uF001"
@ -52,7 +55,6 @@ M.PopupPanel {
}
}
// Track info
Item {
width: menuWindow.panelWidth
height: titleCol.implicitHeight + 8
@ -82,7 +84,7 @@ M.PopupPanel {
const p = menuWindow.player;
if (!p) return "";
const artist = Array.isArray(p.trackArtists) ? p.trackArtists.join(", ") : (p.trackArtists || "");
return [artist, p.trackAlbum].filter(s => s).join(" ");
return [artist, p.trackAlbum].filter(s => s).join(" \u2014 ");
}
color: M.Theme.base04
font.pixelSize: M.Theme.fontSize - 1
@ -93,7 +95,6 @@ M.PopupPanel {
}
}
// Progress bar
Item {
width: menuWindow.panelWidth
height: 20
@ -102,39 +103,25 @@ M.PopupPanel {
readonly property real dur: menuWindow.player?.length ?? 0
readonly property real frac: dur > 0 ? pos / dur : 0
// Time labels
Text {
anchors.left: parent.left
anchors.leftMargin: 12
anchors.verticalCenter: parent.verticalCenter
text: _fmt(parent.pos)
text: menuWindow._fmtTime(parent.pos)
color: M.Theme.base04
font.pixelSize: M.Theme.fontSize - 2
font.family: M.Theme.fontFamily
function _fmt(ms) {
const s = Math.floor(ms / 1000);
const m = Math.floor(s / 60);
return m + ":" + String(s % 60).padStart(2, "0");
}
}
Text {
anchors.right: parent.right
anchors.rightMargin: 12
anchors.verticalCenter: parent.verticalCenter
text: _fmt(parent.dur)
text: menuWindow._fmtTime(parent.dur)
color: M.Theme.base04
font.pixelSize: M.Theme.fontSize - 2
font.family: M.Theme.fontFamily
function _fmt(ms) {
const s = Math.floor(ms / 1000);
const m = Math.floor(s / 60);
return m + ":" + String(s % 60).padStart(2, "0");
}
}
// Bar
Item {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
@ -155,7 +142,6 @@ M.PopupPanel {
}
}
// Transport controls
Item {
width: menuWindow.panelWidth
height: 36
@ -164,7 +150,6 @@ M.PopupPanel {
anchors.centerIn: parent
spacing: 24
// Previous
Text {
text: "\uF048"
color: menuWindow.player?.canGoPrevious ? M.Theme.base05 : M.Theme.base03
@ -180,7 +165,6 @@ M.PopupPanel {
}
}
// Play/Pause
Text {
text: menuWindow.player?.playbackState === MprisPlaybackState.Playing ? "\uF04C" : "\uF04B"
color: M.Theme.base0E
@ -195,7 +179,6 @@ M.PopupPanel {
}
}
// Next
Text {
text: "\uF051"
color: menuWindow.player?.canGoNext ? M.Theme.base05 : M.Theme.base03
@ -213,7 +196,6 @@ M.PopupPanel {
}
}
// Player name
Item {
width: menuWindow.panelWidth
height: 20