46 lines
1.3 KiB
QML
46 lines
1.3 KiB
QML
pragma Singleton
|
|
|
|
import Quickshell
|
|
import Quickshell.Io
|
|
import QtQuick
|
|
import Quickshell.Services.Mpris
|
|
|
|
Singleton {
|
|
id: root
|
|
// property MprisPlayer trackedPlayer: null;
|
|
readonly property MprisPlayer activePlayer: PlayerController.activePlayer.identity === "Spotify"
|
|
? PlayerController.activePlayer
|
|
: null
|
|
|
|
readonly property string time: {
|
|
root.activePlayer.trackTitle
|
|
}
|
|
readonly property string artist: {
|
|
root.activePlayer.trackArtist
|
|
}
|
|
readonly property string timetime: {
|
|
Math.floor(root.activePlayer.position / 60) + ":" +
|
|
formatTwoDigits(Math.floor(root.activePlayer.position % 60))
|
|
}
|
|
|
|
readonly property string fulltime: {
|
|
Math.floor(root.activePlayer.length / 60) + ":" +
|
|
formatTwoDigits(Math.floor(root.activePlayer.length % 60))
|
|
}
|
|
|
|
function formatTwoDigits(num) {
|
|
return (num < 10 ? "0" : "") + num;
|
|
}
|
|
|
|
|
|
Timer {
|
|
// only emit the signal when the position is actually changing.
|
|
running: root.activePlayer.playbackState == MprisPlaybackState.Playing
|
|
// Make sure the position updates at least once per second.
|
|
interval: 1000
|
|
repeat: true
|
|
// emit the positionChanged signal every second.
|
|
onTriggered: root.activePlayer.positionChanged()
|
|
}
|
|
}
|