qs: improve lyrics fetching feedback

This commit is contained in:
2026-03-25 13:06:59 +01:00
parent e6b928be7d
commit 6d0416ecb6
4 changed files with 21 additions and 19 deletions
@@ -25,7 +25,7 @@ Rectangle {
clip: true
UText {
text: LyricsService.lyrics.get(LyricsService.currentIndex)?.line || ""
text: LyricsService.isFetchingLyrics ? "Fetching..." : (LyricsService.lyrics.get(LyricsService.currentIndex)?.line ?? "No lyrics available")
family: Fonts.sans
pointSize: Style.fontSizeM
maximumLineCount: 1
@@ -16,6 +16,13 @@ UBox {
LyricsService.unregisterComponent("LyricsCard");
}
UText {
anchors.centerIn: parent
visible: LyricsService.isFetchingLyrics || LyricsService.lyrics.count === 0
text: LyricsService.isFetchingLyrics ? "Fetching..." : "No lyrics available"
color: Colors.mOnSurfaceVariant
}
ListView {
id: lyricsList
@@ -25,6 +32,7 @@ UBox {
model: LyricsService.lyrics
currentIndex: LyricsService.currentIndex
clip: true
visible: !LyricsService.isFetchingLyrics && LyricsService.lyrics.count > 0
onCurrentIndexChanged: {
if (currentIndex >= 0)
positionViewAtIndex(currentIndex, ListView.Center);
@@ -23,7 +23,8 @@ Singleton {
property var _registered: ({
})
readonly property int _registeredCount: Object.keys(_registered).length
readonly property bool shouldRun: _registeredCount > 0
readonly property bool shouldRun: MediaService.currentPlayer && _registeredCount > 0
// readonly property bool shouldRun: MediaService.currentPlayer !== null
// Bar state
readonly property bool showLyricsBar: ShellState.lyricsState.showLyricsBar || false
@@ -58,21 +59,19 @@ Singleton {
return ;
root.isFetchingLyrics = true;
if (!MediaService.currentPlayer) {
if (!MediaService.currentPlayer?.identity) {
root.isFetchingLyrics = false;
return ;
} else if (MediaService.currentPlayer.identity.toLowerCase() === "spotify")
lyricsProcess.request("spotify");
else if (MediaService.currentPlayer.identity.toLowerCase() === "elisa")
lyricsProcess.request("elisa");
else
root.isFetchingLyrics = false;
} else {
lyricsProcess.request(MediaService.currentPlayer.identity.toLowerCase());
}
}
function parseLRC(text) {
if (!root.shouldRun)
return ;
// Logger.d("Lyrics", "Parsing :\n" + text);
const lines = text.split("\n");
let newLyrics = [];
for (let i = 0; i < lines.length; i++) {
@@ -165,7 +164,8 @@ Singleton {
Logger.d("Lyrics", "Should run changed:", root.shouldRun);
if (!root.shouldRun) {
root.lyrics.clear();
root.isFetchingLyrics = false;
root.lyricsUpdated();
root.currentIndex = -1;
} else {
root._requestFetchLyrics();
}
@@ -229,15 +229,7 @@ Singleton {
}
const player = this.queuedPlayer.toLowerCase();
this.queuedPlayer = "";
if (player === "spotify") {
this.command = ["lrcfetch", "fetch", "--player", "spotify"];
} else if (player === "elisa") {
this.command = ["lrcfetch", "fetch", "--player", "elisa"];
} else {
root.isFetchingLyrics = false;
root.parseLRC("");
return ;
}
this.command = ["lrcfetch", "fetch", "--player", player];
this.running = true;
}