diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2026-09-02 18:26:45 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2026-09-02 18:26:45 +0800 |
| commit | f7a43077fe4e139dd7e3f46f448e0951740ec148 (patch) | |
| tree | f6a68248fe42bd899e99049bab7fdb7e5d26ea60 /services/Mpris.qml | |
| parent | 2f7576faf493b4667b02dcb60ddbf3aa0a9f654b (diff) | |
fix: qmlfmt
IListView: animation
Diffstat (limited to 'services/Mpris.qml')
| -rw-r--r-- | services/Mpris.qml | 300 |
1 files changed, 150 insertions, 150 deletions
diff --git a/services/Mpris.qml b/services/Mpris.qml index dc103f8..c73ed3f 100644 --- a/services/Mpris.qml +++ b/services/Mpris.qml @@ -16,154 +16,154 @@ import qs.config * A service that provides easy access to the active Mpris player. */ Singleton { - id: root - property MprisPlayer trackedPlayer: null - property MprisPlayer activePlayer: Mpris.players.values.find(i => i.desktopEntry === Bar.preferedPlayer) ?? trackedPlayer ?? Mpris.players.values[0] ?? null - signal trackChanged(reverse: bool) - - property bool __reverse: false - - property var activeTrack - - Timer { - running: root.activePlayer?.playbackState == MprisPlaybackState.Playing && root.activePlayer?.positionSupported - interval: 1000 - repeat: true - onTriggered: root.activePlayer.positionChanged() - } - - Instantiator { - model: Mpris.players - - Connections { - required property MprisPlayer modelData - target: modelData - - Component.onCompleted: { - if (root.trackedPlayer == null || modelData.isPlaying) { - root.trackedPlayer = modelData; - } - } - - Component.onDestruction: { - if (root.trackedPlayer == null || !root.trackedPlayer.isPlaying) { - for (const player of Mpris.players.values) { - if (player.playbackState.isPlaying) { - root.trackedPlayer = player; - break; - } - } - - if (trackedPlayer == null && Mpris.players.values.length != 0) { - trackedPlayer = Mpris.players.values[0]; - } - } - } - - function onPlaybackStateChanged() { - if (root.trackedPlayer !== modelData) - root.trackedPlayer = modelData; - } - } - } - - Connections { - target: activePlayer - - function onPostTrackChanged() { - root.updateTrack(); - } - - function onTrackArtUrlChanged() { - // console.log("arturl:", activePlayer.trackArtUrl) - // root.updateTrack(); - if (root.activePlayer.uniqueId == root.activeTrack.uniqueId && root.activePlayer.trackArtUrl != root.activeTrack.artUrl) { - // cantata likes to send cover updates *BEFORE* updating the track info. - // as such, art url changes shouldn't be able to break the reverse animation - const r = root.__reverse; - root.updateTrack(); - root.__reverse = r; - } - } - // not working https://github.com/quickshell-mirror/quickshell/issues/111 - // function onEntered() { - // } - } - - onActivePlayerChanged: this.updateTrack() - - function updateTrack() { - // console.log(`update: ${this.activePlayer?.trackTitle ?? ""} : ${this.activePlayer?.trackArtists}`); - this.activeTrack = { - uniqueId: this.activePlayer?.uniqueId ?? 0, - artUrl: this.activePlayer?.trackArtUrl ?? "", - title: this.activePlayer?.trackTitle || qsTr("Unknown Title"), - artist: this.activePlayer?.trackArtist || qsTr("Unknown Artist"), - album: this.activePlayer?.trackAlbum || qsTr("Unknown Album"), - position: this.activePlayer?.position ?? 0, - length: this.activePlayer?.length ?? 0 - }; - - this.trackChanged(__reverse); - this.__reverse = false; - } - - function updateProgress() { - this.activePlayer.position; - } - - property bool isPlaying: this.activePlayer && this.activePlayer.isPlaying - property bool canTogglePlaying: this.activePlayer?.canTogglePlaying ?? false - function togglePlaying() { - if (this.canTogglePlaying) - this.activePlayer.togglePlaying(); - } - - property bool canGoPrevious: this.activePlayer?.canGoPrevious ?? false - function previous() { - if (this.canGoPrevious) { - this.__reverse = true; - this.activePlayer.previous(); - } - } - - property bool canGoNext: this.activePlayer?.canGoNext ?? false - function next() { - if (this.canGoNext) { - this.__reverse = false; - this.activePlayer.next(); - } - } - - property bool canChangeVolume: this.activePlayer && this.activePlayer.volumeSupported && this.activePlayer.canControl - - property bool loopSupported: this.activePlayer && this.activePlayer.loopSupported && this.activePlayer.canControl - property var loopState: this.activePlayer?.loopState ?? MprisLoopState.None - function setLoopState(loopState: var) { - if (this.loopSupported) { - this.activePlayer.loopState = loopState; - } - } - - property bool shuffleSupported: this.activePlayer && this.activePlayer.shuffleSupported && this.activePlayer.canControl - property bool hasShuffle: this.activePlayer?.shuffle ?? false - function setShuffle(shuffle: bool) { - if (this.shuffleSupported) { - this.activePlayer.shuffle = shuffle; - } - } - - function setActivePlayer(player: MprisPlayer) { - const targetPlayer = player ?? Mpris.players[0]; - console.log(`[Mpris] Active player ${targetPlayer} << ${activePlayer}`); - - if (targetPlayer && this.activePlayer) { - this.__reverse = Mpris.players.indexOf(targetPlayer) < Mpris.players.indexOf(this.activePlayer); - } else { - // always animate forward if going to null - this.__reverse = false; - } - - this.trackedPlayer = targetPlayer; - } + id: root + property MprisPlayer trackedPlayer: null + property MprisPlayer activePlayer: Mpris.players.values.find(i => i.desktopEntry === Bar.preferedPlayer) ?? trackedPlayer ?? Mpris.players.values[0] ?? null + signal trackChanged(reverse: bool) + + property bool __reverse: false + + property var activeTrack + + Timer { + running: root.activePlayer?.playbackState == MprisPlaybackState.Playing && root.activePlayer?.positionSupported + interval: 1000 + repeat: true + onTriggered: root.activePlayer.positionChanged() + } + + Instantiator { + model: Mpris.players + + Connections { + required property MprisPlayer modelData + target: modelData + + Component.onCompleted: { + if (root.trackedPlayer == null || modelData.isPlaying) { + root.trackedPlayer = modelData; + } + } + + Component.onDestruction: { + if (root.trackedPlayer == null || !root.trackedPlayer.isPlaying) { + for (const player of Mpris.players.values) { + if (player.playbackState.isPlaying) { + root.trackedPlayer = player; + break; + } + } + + if (trackedPlayer == null && Mpris.players.values.length != 0) { + trackedPlayer = Mpris.players.values[0]; + } + } + } + + function onPlaybackStateChanged() { + if (root.trackedPlayer !== modelData) + root.trackedPlayer = modelData; + } + } + } + + Connections { + target: activePlayer + + function onPostTrackChanged() { + root.updateTrack(); + } + + function onTrackArtUrlChanged() { + // console.log("arturl:", activePlayer.trackArtUrl) + // root.updateTrack(); + if (root.activePlayer.uniqueId == root.activeTrack.uniqueId && root.activePlayer.trackArtUrl != root.activeTrack.artUrl) { + // cantata likes to send cover updates *BEFORE* updating the track info. + // as such, art url changes shouldn't be able to break the reverse animation + const r = root.__reverse; + root.updateTrack(); + root.__reverse = r; + } + } + // not working https://github.com/quickshell-mirror/quickshell/issues/111 + // function onEntered() { + // } + } + + onActivePlayerChanged: this.updateTrack() + + function updateTrack() { + // console.log(`update: ${this.activePlayer?.trackTitle ?? ""} : ${this.activePlayer?.trackArtists}`); + this.activeTrack = { + uniqueId: this.activePlayer?.uniqueId ?? 0, + artUrl: this.activePlayer?.trackArtUrl ?? "", + title: this.activePlayer?.trackTitle || qsTr("Unknown Title"), + artist: this.activePlayer?.trackArtist || qsTr("Unknown Artist"), + album: this.activePlayer?.trackAlbum || qsTr("Unknown Album"), + position: this.activePlayer?.position ?? 0, + length: this.activePlayer?.length ?? 0 + }; + + this.trackChanged(__reverse); + this.__reverse = false; + } + + function updateProgress() { + this.activePlayer.position; + } + + property bool isPlaying: this.activePlayer && this.activePlayer.isPlaying + property bool canTogglePlaying: this.activePlayer?.canTogglePlaying ?? false + function togglePlaying() { + if (this.canTogglePlaying) + this.activePlayer.togglePlaying(); + } + + property bool canGoPrevious: this.activePlayer?.canGoPrevious ?? false + function previous() { + if (this.canGoPrevious) { + this.__reverse = true; + this.activePlayer.previous(); + } + } + + property bool canGoNext: this.activePlayer?.canGoNext ?? false + function next() { + if (this.canGoNext) { + this.__reverse = false; + this.activePlayer.next(); + } + } + + property bool canChangeVolume: this.activePlayer && this.activePlayer.volumeSupported && this.activePlayer.canControl + + property bool loopSupported: this.activePlayer && this.activePlayer.loopSupported && this.activePlayer.canControl + property var loopState: this.activePlayer?.loopState ?? MprisLoopState.None + function setLoopState(loopState: var) { + if (this.loopSupported) { + this.activePlayer.loopState = loopState; + } + } + + property bool shuffleSupported: this.activePlayer && this.activePlayer.shuffleSupported && this.activePlayer.canControl + property bool hasShuffle: this.activePlayer?.shuffle ?? false + function setShuffle(shuffle: bool) { + if (this.shuffleSupported) { + this.activePlayer.shuffle = shuffle; + } + } + + function setActivePlayer(player: MprisPlayer) { + const targetPlayer = player ?? Mpris.players[0]; + console.log(`[Mpris] Active player ${targetPlayer} << ${activePlayer}`); + + if (targetPlayer && this.activePlayer) { + this.__reverse = Mpris.players.indexOf(targetPlayer) < Mpris.players.indexOf(this.activePlayer); + } else { + // always animate forward if going to null + this.__reverse = false; + } + + this.trackedPlayer = targetPlayer; + } } |
