Skip to content

Commit 2b2a1d0

Browse files
refactor: 统一桌面歌词锁定 IPC 参数为对象格式
将 toggle-desktop-lyric-lock IPC 通信的参数从多个独立参数重构为单一对象参数,提高代码可读性和可扩展性。修改涉及主进程和渲染进程的多个文件,确保参数传递方式一致。
1 parent b71ca4a commit 2b2a1d0

3 files changed

Lines changed: 24 additions & 21 deletions

File tree

electron/main/ipc/ipc-lyric.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -211,26 +211,29 @@ class DesktopLyricManager {
211211
});
212212

213213
// 锁定状态管理
214-
ipcMain.on("toggle-desktop-lyric-lock", (_, lock: boolean, isTemp: boolean = false) => {
215-
if (!isTemp) this.isLocked = lock;
214+
ipcMain.on(
215+
"toggle-desktop-lyric-lock",
216+
(_, { lock, temp }: { lock: boolean; temp?: boolean }) => {
217+
if (!temp) this.isLocked = lock;
216218

217-
if (this.isValid) {
218-
if (lock) {
219-
this.window!.setIgnoreMouseEvents(true, { forward: true });
220-
} else {
221-
this.window!.setIgnoreMouseEvents(false);
219+
if (this.isValid) {
220+
if (lock) {
221+
this.window!.setIgnoreMouseEvents(true, { forward: true });
222+
} else {
223+
this.window!.setIgnoreMouseEvents(false);
224+
}
222225
}
223-
}
224226

225-
if (!isTemp) {
226-
this.store.set("lyric.config.isLock", lock);
227-
const config = this.store.get("lyric.config");
228-
const mainWin = mainWindow.getWin();
229-
if (mainWin && !mainWin.isDestroyed()) {
230-
mainWin.webContents.send("update-desktop-lyric-option", config);
227+
if (!temp) {
228+
this.store.set("lyric.config.isLock", lock);
229+
const config = this.store.get("lyric.config");
230+
const mainWin = mainWindow.getWin();
231+
if (mainWin && !mainWin.isDestroyed()) {
232+
mainWin.webContents.send("update-desktop-lyric-option", config);
233+
}
231234
}
232-
}
233-
});
235+
},
236+
);
234237

235238
// 屏幕信息工具
236239
ipcMain.handle("get-screen-size", () => {

electron/main/ipc/ipc-tray.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ const initTrayIpc = (): void => {
4343
});
4444

4545
// 锁定/解锁桌面歌词
46-
ipcMain.on("toggle-desktop-lyric-lock", (_, isLock: boolean) => {
47-
tray?.setDesktopLyricLock(isLock);
46+
ipcMain.on("toggle-desktop-lyric-lock", (_, { lock }: { lock: boolean }) => {
47+
tray?.setDesktopLyricLock(lock);
4848
});
4949
};
5050

src/views/DesktopLyric/index.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ const sendToMainWin = (eventName: string, ...args: any[]) => {
708708
709709
// 切换桌面歌词锁定状态
710710
const toggleLyricLock = () => {
711-
sendToMain("toggle-desktop-lyric-lock", !lyricConfig.isLock);
711+
sendToMain("toggle-desktop-lyric-lock", { lock: !lyricConfig.isLock });
712712
lyricConfig.isLock = !lyricConfig.isLock;
713713
};
714714
@@ -719,7 +719,7 @@ const toggleLyricLock = () => {
719719
const tempToggleLyricLock = (isLock: boolean) => {
720720
// 是否已经解锁
721721
if (!lyricConfig.isLock) return;
722-
window.electron.ipcRenderer.send("toggle-desktop-lyric-lock", isLock, true);
722+
window.electron.ipcRenderer.send("toggle-desktop-lyric-lock", { lock: isLock, temp: true });
723723
};
724724
725725
onMounted(() => {
@@ -772,7 +772,7 @@ onMounted(() => {
772772
const height = fontSizeToHeight(config.fontSize);
773773
if (height) pushWindowHeight(height);
774774
// 是否锁定
775-
sendToMain("toggle-desktop-lyric-lock", config.isLock);
775+
sendToMain("toggle-desktop-lyric-lock", { lock: config.isLock });
776776
});
777777
// 请求歌词数据及配置
778778
window.electron.ipcRenderer.send("request-desktop-lyric-data");

0 commit comments

Comments
 (0)