diff --git a/README.md b/README.md index dabecce7..080e2628 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ - ✨ 支持扫码登录 - 📱 支持手机号登录 - 📅 自动进行每日签到及云贝签到 +- 💻 支持桌面歌词 - 💻 支持切换为本地播放器,此模式将不会连接网络 - 🎨 封面主题色自适应,支持全站着色 - 🌚 Light / Dark / Auto 模式自动切换 diff --git a/electron/main/ipcMain.ts b/electron/main/ipcMain.ts index 002e0453..186dc9d5 100644 --- a/electron/main/ipcMain.ts +++ b/electron/main/ipcMain.ts @@ -645,6 +645,11 @@ const initTrayIpcMain = ( tray?.setPlayMode(mode); }); + // 喜欢状态切换 + ipcMain.on("like-status-change", (_, likeStatus: boolean) => { + tray?.setLikeState(likeStatus); + }); + // 桌面歌词开关 ipcMain.on("change-desktop-lyric", (_, val: boolean) => { tray?.setDesktopLyricShow(val); diff --git a/electron/main/tray.ts b/electron/main/tray.ts index cc3799c7..d6e23331 100644 --- a/electron/main/tray.ts +++ b/electron/main/tray.ts @@ -19,12 +19,14 @@ type PlayState = "play" | "pause" | "loading"; let playMode: PlayMode = "repeat"; let playState: PlayState = "pause"; let playName: string = "未播放歌曲"; +let likeSong: boolean = false; let desktopLyricShow: boolean = false; let desktopLyricLock: boolean = false; export interface MainTray { setTitle(title: string): void; setPlayMode(mode: PlayMode): void; + setLikeState(like: boolean): void; setPlayState(state: PlayState): void; setPlayName(name: string): void; setDesktopLyricShow(show: boolean): void; @@ -34,11 +36,11 @@ export interface MainTray { // 托盘图标 const trayIcon = (filename: string) => { - // const rootPath = isDev - // ? join(__dirname, "../../public/icons/tray") - // : join(app.getAppPath(), "../../public/icons/tray"); - // return nativeImage.createFromPath(join(rootPath, filename)); - return nativeImage.createFromPath(join(__dirname, `../../public/icons/tray/${filename}`)); + const rootPath = isDev + ? join(__dirname, "../../public/icons/tray") + : join(app.getAppPath(), "../../public/icons/tray"); + return nativeImage.createFromPath(join(rootPath, filename)); + // return nativeImage.createFromPath(join(__dirname, `../../public/icons/tray/${filename}`)); }; // 托盘菜单 @@ -60,7 +62,6 @@ const createTrayMenu = ( id: "name", label: playName, icon: showIcon("music"), - accelerator: "CmdOrCtrl+Alt+S", click: () => { win.show(); win.focus(); @@ -71,19 +72,10 @@ const createTrayMenu = ( }, { id: "toogleLikeSong", - label: "添加到我喜欢", - icon: showIcon("unlike"), - accelerator: "CmdOrCtrl+Alt+L", + label: likeSong ? "从我喜欢中移除" : "添加到我喜欢", + icon: showIcon(likeSong ? "like" : "unlike"), click: () => win.webContents.send("toogleLikeSong"), }, - { - id: "unLike", - label: "从我喜欢中移除", - icon: showIcon("like"), - visible: false, - accelerator: "CmdOrCtrl+Alt+L", - click: () => win.webContents.send("unlike-song"), - }, { id: "changeMode", label: @@ -123,21 +115,18 @@ const createTrayMenu = ( id: "playNext", label: "上一曲", icon: showIcon("prev"), - accelerator: "CmdOrCtrl+Left", click: () => win.webContents.send("playPrev"), }, { id: "playOrPause", label: playState === "pause" ? "播放" : "暂停", icon: showIcon(playState === "pause" ? "play" : "pause"), - accelerator: "CmdOrCtrl+Space", click: () => win.webContents.send(playState === "pause" ? "play" : "pause"), }, { id: "playNext", label: "下一曲", icon: showIcon("next"), - accelerator: "CmdOrCtrl+Right", click: () => win.webContents.send("playNext"), }, { @@ -176,7 +165,6 @@ const createTrayMenu = ( id: "exit", label: "退出", icon: showIcon("power"), - accelerator: "CmdOrCtrl+Alt+Q", click: () => { win.close(); // app.exit(0); @@ -255,6 +243,12 @@ class CreateTray implements MainTray { // 更新菜单 this.initTrayMenu(); } + // 设置喜欢状态 + setLikeState(like: boolean) { + likeSong = like; + // 更新菜单 + this.initTrayMenu(); + } // 桌面歌词开关 setDesktopLyricShow(show: boolean) { desktopLyricShow = show; diff --git a/src/App.vue b/src/App.vue index 1e68e44f..2c7d3ffe 100644 --- a/src/App.vue +++ b/src/App.vue @@ -74,7 +74,12 @@ - + diff --git a/src/components/List/SongList.vue b/src/components/List/SongList.vue index 91dca047..7cc609ff 100644 --- a/src/components/List/SongList.vue +++ b/src/components/List/SongList.vue @@ -192,9 +192,9 @@
@@ -381,11 +381,6 @@ const sortSelect = (key: SortType) => { } }; -// 是否为喜欢歌曲 -const isLikeSong = (id: number) => { - return dataStore.userLikeData.songs.includes(id); -}; - // 滚动至播放歌曲 const scrollTo = (index: number) => { if (index === 0) songListScrollTop.value = 0; diff --git a/src/components/Modal/LoginQRCode.vue b/src/components/Modal/LoginQRCode.vue index fd6e24dd..e29ae4af 100644 --- a/src/components/Modal/LoginQRCode.vue +++ b/src/components/Modal/LoginQRCode.vue @@ -1,15 +1,36 @@