Skip to content

Commit 4d3d8a6

Browse files
committed
refactor: 全面重构桌面歌词相关 ipc
1 parent 2b2a1d0 commit 4d3d8a6

12 files changed

Lines changed: 279 additions & 281 deletions

File tree

electron/main/ipc/ipc-lyric.ts

Lines changed: 241 additions & 238 deletions
Large diffs are not rendered by default.

electron/main/ipc/ipc-tray.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ const initTrayIpc = (): void => {
3838
});
3939

4040
// 桌面歌词开关
41-
ipcMain.on("toggle-desktop-lyric", (_, val: boolean) => {
41+
ipcMain.on("desktop-lyric:toggle", (_, val: boolean) => {
4242
tray?.setDesktopLyricShow(val);
4343
});
4444

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

electron/main/tray/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ const createTrayMenu = (win: BrowserWindow): MenuItemConstructorOptions[] => {
162162
id: "toggle-desktop-lyric",
163163
label: `${desktopLyricShow ? "关闭" : "开启"}桌面歌词`,
164164
icon: showIcon("lyric"),
165-
click: () => win.webContents.send("toggle-desktop-lyric"),
165+
click: () => win.webContents.send("desktop-lyric:toggle"),
166166
},
167167
{
168168
id: "toggle-desktop-lyric-lock",
@@ -177,7 +177,7 @@ const createTrayMenu = (win: BrowserWindow): MenuItemConstructorOptions[] => {
177177
const config = store.get("lyric.config");
178178
const lyricWin = lyricWindow.getWin();
179179
if (!lyricWin) return;
180-
lyricWin.webContents.send("update-desktop-lyric-option", config);
180+
lyricWin.webContents.send("desktop-lyric:update-option", config);
181181
},
182182
},
183183
{

electron/main/windows/lyric-window.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class LyricWindow {
3838
this.win = null;
3939
const mainWin = mainWindow?.getWin();
4040
if (mainWin) {
41-
mainWin?.webContents.send("close-desktop-lyric");
41+
mainWin?.webContents.send("desktop-lyric:close");
4242
}
4343
});
4444
}

native/tools/src/scanner.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ fn spawn_reporter(
234234
})
235235
}
236236

237+
#[allow(clippy::cast_possible_wrap)]
237238
fn process_single_track(
238239
path_buf: &Path,
239240
snapshot: &HashMap<String, TrackSnapshot>,

src/components/Modal/Setting/FontManager.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ const fontArrayToFamily = (fontArray: string[]): string => {
317317
// 获取桌面歌词配置
318318
const getDesktopLyricConfig = async () => {
319319
if (!isElectron) return;
320-
const config = await window.electron.ipcRenderer.invoke("request-desktop-lyric-option");
320+
const config = await window.electron.ipcRenderer.invoke("desktop-lyric:get-option");
321321
if (config) Object.assign(desktopLyricConfig, config);
322322
};
323323
@@ -333,7 +333,7 @@ const saveDesktopLyricConfig = (val?: string) => {
333333
if (!isElectron) return;
334334
if (val) desktopLyricConfig.fontFamily = val;
335335
window.electron.ipcRenderer.send(
336-
"update-desktop-lyric-option",
336+
"desktop-lyric:set-option",
337337
cloneDeep(desktopLyricConfig),
338338
true,
339339
);
@@ -348,12 +348,12 @@ const saveDesktopLyricConfig = (val?: string) => {
348348
onMounted(() => {
349349
getAllSystemFonts();
350350
getDesktopLyricConfig();
351-
window.electron.ipcRenderer.on("update-desktop-lyric-option", onLyricConfigUpdate);
351+
window.electron.ipcRenderer.on("desktop-lyric:update-option", onLyricConfigUpdate);
352352
});
353353
354354
onUnmounted(() => {
355355
if (isElectron) {
356-
window.electron.ipcRenderer.removeListener("update-desktop-lyric-option", onLyricConfigUpdate);
356+
window.electron.ipcRenderer.removeListener("desktop-lyric:update-option", onLyricConfigUpdate);
357357
}
358358
});
359359
</script>

src/components/Setting/config/lyric.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ export const useLyricSettings = (): SettingConfig => {
2222

2323
const getDesktopLyricConfig = async () => {
2424
if (!isElectron) return;
25-
const config = await window.electron.ipcRenderer.invoke("request-desktop-lyric-option");
25+
const config = await window.electron.ipcRenderer.invoke("desktop-lyric:get-option");
2626
if (config) Object.assign(desktopLyricConfig, config);
2727

2828
// 监听更新
29-
window.electron.ipcRenderer.on("update-desktop-lyric-option", (_, config) => {
29+
window.electron.ipcRenderer.on("desktop-lyric:update-option", (_, config) => {
3030
if (config && !isEqual(desktopLyricConfig, config)) {
3131
Object.assign(desktopLyricConfig, config);
3232
}
@@ -37,7 +37,7 @@ export const useLyricSettings = (): SettingConfig => {
3737
try {
3838
if (!isElectron) return;
3939
window.electron.ipcRenderer.send(
40-
"update-desktop-lyric-option",
40+
"desktop-lyric:set-option",
4141
cloneDeep(desktopLyricConfig),
4242
true,
4343
);
@@ -59,7 +59,7 @@ export const useLyricSettings = (): SettingConfig => {
5959
negativeText: "取消",
6060
onPositiveClick: () => {
6161
window.electron.ipcRenderer.send(
62-
"update-desktop-lyric-option",
62+
"desktop-lyric:set-option",
6363
defaultDesktopLyricConfig,
6464
true,
6565
);

src/composables/useInit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export const useInit = () => {
6868
// 同步任务栏歌词状态
6969
window.electron.ipcRenderer.send("taskbar:toggle", statusStore.showTaskbarLyric);
7070
// 显示桌面歌词
71-
window.electron.ipcRenderer.send("toggle-desktop-lyric", statusStore.showDesktopLyric);
71+
window.electron.ipcRenderer.send("desktop-lyric:toggle", statusStore.showDesktopLyric);
7272
// 检查更新
7373
if (settingStore.checkUpdateOnStart)
7474
window.electron.ipcRenderer.send("check-update", false, settingStore.updateChannel);

src/core/player/PlayerController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class PlayerController {
182182
statusStore.abLoop.pointB = null;
183183
// 通知桌面歌词
184184
if (isElectron) {
185-
window.electron.ipcRenderer.send("update-desktop-lyric-data", {
185+
window.electron.ipcRenderer.send("desktop-lyric:update-data", {
186186
lyricLoading: true,
187187
});
188188
}

src/core/player/PlayerIpc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const sendSongChange = (title: string, name: string, artist: string, albu
2727
// 获取歌曲时长
2828
const duration = getPlaySongData()?.duration ?? 0;
2929
window.electron.ipcRenderer.send("play-song-change", { title, name, artist, album, duration });
30-
window.electron.ipcRenderer.send("update-desktop-lyric-data", {
30+
window.electron.ipcRenderer.send("desktop-lyric:update-data", {
3131
playName: name,
3232
artistName: artist,
3333
});
@@ -96,7 +96,7 @@ export const sendLikeStatus = (isLiked: boolean) => {
9696
* @param show 是否显示
9797
*/
9898
export const toggleDesktopLyric = (show: boolean) => {
99-
if (isElectron) window.electron.ipcRenderer.send("toggle-desktop-lyric", show);
99+
if (isElectron) window.electron.ipcRenderer.send("desktop-lyric:toggle", show);
100100
};
101101

102102
export const toggleTaskbarLyric = (show: boolean) => {

0 commit comments

Comments
 (0)