Skip to content

Commit 91c3500

Browse files
committed
fix: prevent stale desktop lyric loading state
1 parent 843eb6e commit 91c3500

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

src/core/player/PlayerController.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,13 @@ class PlayerController {
211211
// 通知桌面歌词
212212
if (isElectron) {
213213
window.electron.ipcRenderer.send("desktop-lyric:update-data", {
214+
currentTime: startSeek,
214215
lyricLoading: true,
216+
songId: song.id,
217+
songOffset: statusStore.getSongOffset(song.id),
218+
lrcData: [],
219+
yrcData: [],
220+
lyricIndex: -1,
215221
});
216222
}
217223
// 更新任务栏歌词窗口的元数据

src/utils/initIpc.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const initIpc = () => {
8585
);
8686

8787
// 给任务栏歌词初始数据
88-
window.electron.ipcRenderer.on(TASKBAR_IPC_CHANNELS.REQUEST_DATA, async () => {
88+
window.electron.ipcRenderer.on(TASKBAR_IPC_CHANNELS.REQUEST_DATA, async () => {
8989
const musicStore = useMusicStore();
9090
const statusStore = useStatusStore();
9191

@@ -140,6 +140,9 @@ window.electron.ipcRenderer.on(TASKBAR_IPC_CHANNELS.REQUEST_DATA, async () => {
140140
const statusStore = useStatusStore();
141141
if (player) {
142142
const { name, artist } = getPlayerInfoObj() || {};
143+
const songLyric = statusStore.lyricLoading
144+
? { lrcData: [], yrcData: [] }
145+
: toRaw(musicStore.songLyric);
143146
window.electron.ipcRenderer.send(
144147
"desktop-lyric:update-data",
145148
cloneDeep({
@@ -149,8 +152,8 @@ window.electron.ipcRenderer.on(TASKBAR_IPC_CHANNELS.REQUEST_DATA, async () => {
149152
currentTime: statusStore.currentTime,
150153
songId: musicStore.playSong?.id,
151154
songOffset: statusStore.getSongOffset(musicStore.playSong?.id),
152-
lrcData: musicStore.songLyric.lrcData ?? [],
153-
yrcData: musicStore.songLyric.yrcData ?? [],
155+
lrcData: songLyric.lrcData ?? [],
156+
yrcData: songLyric.yrcData ?? [],
154157
lyricIndex: statusStore.lyricIndex,
155158
lyricLoading: statusStore.lyricLoading,
156159
}),

src/views/DesktopLyric/index.vue

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ const lyricData = reactive<LyricData>({
182182
lyricIndex: -1,
183183
});
184184
185+
const hasLyricLines = (data: Pick<LyricData, "lrcData" | "yrcData">) =>
186+
Boolean(data.lrcData?.length || data.yrcData?.length);
187+
188+
const shouldIgnoreLoadingUpdate = (data: LyricData) => {
189+
if (data.lyricLoading !== true) return false;
190+
if (hasLyricLines(data) || !hasLyricLines(lyricData)) return false;
191+
return data.songId === undefined || data.songId === lyricData.songId;
192+
};
193+
185194
// 锚点时间(毫秒)与锚点帧时间,用于插值推进
186195
let baseMs = 0;
187196
let anchorTick = 0;
@@ -306,7 +315,7 @@ const renderLyricLines = computed<RenderLine[]>(() => {
306315
return placeholder("SPlayer Desktop Lyric");
307316
}
308317
// 加载中
309-
if (lyricData.lyricLoading) return placeholder("歌词加载中...");
318+
if (lyricData.lyricLoading && !lyrics?.length) return placeholder("歌词加载中...");
310319
// 纯音乐
311320
if (!lyrics?.length) return placeholder("纯音乐,请欣赏");
312321
// 获取当前歌词索引
@@ -708,6 +717,12 @@ onMounted(() => {
708717
window.electron.ipcRenderer.on(
709718
"desktop-lyric:update-data",
710719
(_event, data: LyricData & { sendTimestamp?: number }) => {
720+
if (shouldIgnoreLoadingUpdate(data)) {
721+
if (isInitializing.value) {
722+
isInitializing.value = false;
723+
}
724+
return;
725+
}
711726
Object.assign(lyricData, data);
712727
// 首次接收到歌词数据时,立即结束初始化状态
713728
if (isInitializing.value) {

0 commit comments

Comments
 (0)