Skip to content

Commit c581cb3

Browse files
committed
🐞 fix: 修复播放信息获取 & 桌面歌词数据异常
1 parent fe84b99 commit c581cb3

4 files changed

Lines changed: 12 additions & 5 deletions

File tree

electron/main/ipc/ipc-lyric.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,10 @@ const initLyricIpc = (): void => {
121121
lyricWin.setAlwaysOnTop(true, "screen-saver");
122122
}
123123
} else {
124-
// 关闭:不销毁窗口,直接隐藏,保留位置与状态
125124
if (!isWinAlive(lyricWin)) return;
126-
lyricWin.hide();
125+
// 解绑事件
126+
unbindMainWinEvents();
127+
lyricWin.close();
127128
}
128129
});
129130

electron/main/services/SocketService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { WebSocketServer, type WebSocket } from "ws";
22
import { createServer } from "net";
33
import { socketLog } from "../logger";
44
import { useStore } from "../store";
5+
import { getTrackInfoFromRenderer } from "../utils/track-info";
56
import mainWindow from "../windows/main-window";
67

78
/**
@@ -308,7 +309,6 @@ export class SocketService {
308309
*/
309310
private async handleGetSongInfo(socket: WebSocket): Promise<void> {
310311
try {
311-
const { getTrackInfoFromRenderer } = await import("../utils/track-info");
312312
const trackInfo = await getTrackInfoFromRenderer();
313313
this.sendToClient(socket, {
314314
type: "song-info",

electron/server/control/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { FastifyInstance } from "fastify";
22
import { appVersion, appName } from "../../main/utils/config";
3+
import { getTrackInfoFromRenderer } from "../../main/utils/track-info";
34
import mainWindow from "../../main/windows/main-window";
45

56
/**
@@ -201,7 +202,6 @@ export const initControlAPI = async (fastify: FastifyInstance) => {
201202
// 获取当前播放信息
202203
fastify.get("/song-info", async (_request, reply) => {
203204
try {
204-
const { getTrackInfoFromRenderer } = await import("../../main/utils/track-info");
205205
const trackInfo = await getTrackInfoFromRenderer();
206206
return reply.send({
207207
code: 200,

src/utils/initIpc.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const initIpc = () => {
6868
lrcData: musicStore.songLyric.lrcData ?? [],
6969
yrcData: musicStore.songLyric.yrcData ?? [],
7070
lyricIndex: statusStore.lyricIndex,
71+
lyricLoading: statusStore.lyricLoading,
7172
}),
7273
);
7374
}
@@ -100,7 +101,9 @@ const initIpc = () => {
100101
const { name, artist, album } = getPlayerInfoObj() || {};
101102
// 获取原始对象
102103
const playSong = toRaw(musicStore.playSong);
103-
const songLyric = toRaw(musicStore.songLyric);
104+
const songLyric = statusStore.lyricLoading
105+
? { lrcData: [], yrcData: [] }
106+
: toRaw(musicStore.songLyric);
104107
window.electron.ipcRenderer.send(
105108
"return-track-info",
106109
cloneDeep({
@@ -113,6 +116,9 @@ const initIpc = () => {
113116
volume: statusStore.playVolume,
114117
playRate: statusStore.playRate,
115118
...playSong,
119+
// 歌词及加载状态
120+
lyricLoading: statusStore.lyricLoading,
121+
lyricIndex: statusStore.lyricIndex,
116122
...songLyric,
117123
}),
118124
);

0 commit comments

Comments
 (0)