mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-24 16:27:23 +08:00
fix(lyric): 修复桌面歌词窗口首次打开无歌词问题
歌词窗口 Vue 加载完成后发送 lyric-ready 信号,主窗口收到后 发送完整歌词数据,替代不可靠的延迟猜测方案
This commit is contained in:
@@ -172,6 +172,13 @@ export const loadLyricWindow = (ipcMain: IpcMain, mainWin: BrowserWindow): void
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 歌词窗口 Vue 应用加载完成,通知主窗口发送完整歌词数据
|
||||||
|
ipcMain.on('lyric-ready', () => {
|
||||||
|
if (mainWin && !mainWin.isDestroyed()) {
|
||||||
|
mainWin.webContents.send('lyric-window-ready');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
ipcMain.on('send-lyric', (_, data) => {
|
ipcMain.on('send-lyric', (_, data) => {
|
||||||
if (lyricWindow && !lyricWindow.isDestroyed()) {
|
if (lyricWindow && !lyricWindow.isDestroyed()) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Vendored
+1
@@ -19,6 +19,7 @@ interface API {
|
|||||||
sendSong: (data: any) => void;
|
sendSong: (data: any) => void;
|
||||||
unblockMusic: (id: number, data: any, enabledSources?: string[]) => Promise<any>;
|
unblockMusic: (id: number, data: any, enabledSources?: string[]) => Promise<any>;
|
||||||
onLyricWindowClosed: (callback: () => void) => void;
|
onLyricWindowClosed: (callback: () => void) => void;
|
||||||
|
onLyricWindowReady: (callback: () => void) => void;
|
||||||
getAppUpdateState: () => Promise<AppUpdateState>;
|
getAppUpdateState: () => Promise<AppUpdateState>;
|
||||||
checkAppUpdate: (manual?: boolean) => Promise<AppUpdateState>;
|
checkAppUpdate: (manual?: boolean) => Promise<AppUpdateState>;
|
||||||
downloadAppUpdate: () => Promise<AppUpdateState>;
|
downloadAppUpdate: () => Promise<AppUpdateState>;
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ const api = {
|
|||||||
onLyricWindowClosed: (callback: () => void) => {
|
onLyricWindowClosed: (callback: () => void) => {
|
||||||
ipcRenderer.on('lyric-window-closed', () => callback());
|
ipcRenderer.on('lyric-window-closed', () => callback());
|
||||||
},
|
},
|
||||||
|
// 歌词窗口就绪事件(Vue 加载完成,可以接收数据)
|
||||||
|
onLyricWindowReady: (callback: () => void) => {
|
||||||
|
ipcRenderer.on('lyric-window-ready', () => callback());
|
||||||
|
},
|
||||||
getAppUpdateState: () => ipcRenderer.invoke('app-update:get-state') as Promise<AppUpdateState>,
|
getAppUpdateState: () => ipcRenderer.invoke('app-update:get-state') as Promise<AppUpdateState>,
|
||||||
checkAppUpdate: (manual = false) =>
|
checkAppUpdate: (manual = false) =>
|
||||||
ipcRenderer.invoke('app-update:check', { manual }) as Promise<AppUpdateState>,
|
ipcRenderer.invoke('app-update:check', { manual }) as Promise<AppUpdateState>,
|
||||||
|
|||||||
@@ -821,9 +821,11 @@ export const openLyric = () => {
|
|||||||
sendLyricToWin();
|
sendLyricToWin();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置定时器,确保500ms后再次发送数据,以防窗口加载延迟
|
// 延迟重发一次,以防窗口加载略慢
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
sendLyricToWin();
|
if (isLyricWindowOpen.value) {
|
||||||
|
sendLyricToWin();
|
||||||
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
// 启动歌词同步
|
// 启动歌词同步
|
||||||
@@ -936,11 +938,17 @@ export const initAudioListeners = async () => {
|
|||||||
// 初始化音频监听器
|
// 初始化音频监听器
|
||||||
setupAudioListeners();
|
setupAudioListeners();
|
||||||
|
|
||||||
// 监听歌词窗口关闭事件
|
// 监听歌词窗口事件
|
||||||
if (isElectron) {
|
if (isElectron) {
|
||||||
window.api.onLyricWindowClosed(() => {
|
window.api.onLyricWindowClosed(() => {
|
||||||
isLyricWindowOpen.value = false;
|
isLyricWindowOpen.value = false;
|
||||||
});
|
});
|
||||||
|
// 歌词窗口 Vue 加载完成后,发送完整歌词数据
|
||||||
|
window.api.onLyricWindowReady(() => {
|
||||||
|
if (isLyricWindowOpen.value) {
|
||||||
|
sendLyricToWin();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取最新的音频实例
|
// 获取最新的音频实例
|
||||||
|
|||||||
Vendored
+2
@@ -12,6 +12,8 @@ export interface IElectronAPI {
|
|||||||
unblockMusic: (_id: number) => Promise<string>;
|
unblockMusic: (_id: number) => Promise<string>;
|
||||||
importCustomApiPlugin: () => Promise<{ name: string; content: string } | null>;
|
importCustomApiPlugin: () => Promise<{ name: string; content: string } | null>;
|
||||||
importLxMusicScript: () => Promise<{ name: string; content: string } | null>;
|
importLxMusicScript: () => Promise<{ name: string; content: string } | null>;
|
||||||
|
onLyricWindowClosed: (_callback: () => void) => void;
|
||||||
|
onLyricWindowReady: (_callback: () => void) => void;
|
||||||
onLanguageChanged: (_callback: (_locale: string) => void) => void;
|
onLanguageChanged: (_callback: (_locale: string) => void) => void;
|
||||||
store: {
|
store: {
|
||||||
get: (_key: string) => Promise<any>;
|
get: (_key: string) => Promise<any>;
|
||||||
|
|||||||
@@ -642,6 +642,9 @@ onMounted(() => {
|
|||||||
console.error('Error parsing lyric data:', error);
|
console.error('Error parsing lyric data:', error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 通知主窗口歌词窗口已就绪,请求发送完整歌词数据
|
||||||
|
windowData.electron.ipcRenderer.send('lyric-ready');
|
||||||
});
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user