feat: 优化歌词窗口交互和同步机制

- 增强歌词窗口数据同步逻辑,支持实时更新和状态管理
- 添加歌词窗口关闭事件监听和状态处理
- 优化无歌词时的默认提示和窗口行为
- 实现歌词窗口定时同步机制,提升用户体验
- 修复歌词窗口打开和关闭时的状态控制
- 国际化支持无歌曲播放时的提示文案
This commit is contained in:
alger
2025-03-08 19:00:50 +08:00
parent e43e85480d
commit f9878ed88a
8 changed files with 226 additions and 29 deletions
+27 -7
View File
@@ -25,9 +25,15 @@ const createWin = () => {
const validPosition =
x !== undefined && y !== undefined && x >= 0 && y >= 0 && x < screenWidth && y < screenHeight;
// 确保宽高合理
const defaultWidth = 800;
const defaultHeight = 200;
const validWidth = width && width > 0 ? width : defaultWidth;
const validHeight = height && height > 0 ? height : defaultHeight;
lyricWindow = new BrowserWindow({
width: width || 800,
height: height || 200,
width: validWidth,
height: validHeight,
x: validPosition ? x : undefined,
y: validPosition ? y : undefined,
frame: false,
@@ -50,6 +56,17 @@ const createWin = () => {
}
});
// 监听窗口大小变化事件,保存新的尺寸
lyricWindow.on('resize', () => {
if (lyricWindow && !lyricWindow.isDestroyed()) {
const [width, height] = lyricWindow.getSize();
const [x, y] = lyricWindow.getPosition();
// 保存窗口位置和大小
store.set('lyricWindowBounds', { x, y, width, height });
}
});
return lyricWindow;
};
@@ -118,6 +135,7 @@ export const loadLyricWindow = (ipcMain: IpcMain, mainWin: BrowserWindow): void
if (lyricWindow && !lyricWindow.isDestroyed()) {
lyricWindow.webContents.send('lyric-window-close');
mainWin.webContents.send('lyric-control-back', 'close');
mainWin.webContents.send('lyric-window-closed');
lyricWindow.destroy();
lyricWindow = null;
}
@@ -150,12 +168,14 @@ export const loadLyricWindow = (ipcMain: IpcMain, mainWin: BrowserWindow): void
lyricWindow.setPosition(newX, newY);
// 保存新位置
store.set('lyricWindowBounds', {
...lyricWindow.getBounds(),
// 保存新位置,但只保存位置信息,不使用getBounds()避免在Windows下引起尺寸变化
const bounds = {
x: newX,
y: newY
});
y: newY,
width: windowWidth, // 使用当前保存的宽度
height: windowHeight // 使用当前保存的高度
};
store.set('lyricWindowBounds', bounds);
});
// 添加鼠标穿透事件处理