From 8ec91e13923413ff3b9dd41a55b2cd08d4311814 Mon Sep 17 00:00:00 2001 From: imsyy Date: Fri, 7 Nov 2025 17:38:49 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E6=B7=BB=E5=8A=A0=E6=A1=8C?= =?UTF-8?q?=E9=9D=A2=E6=AD=8C=E8=AF=8D=E9=94=81=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components.d.ts | 5 ++++ electron/main/ipc/ipc-lyric.ts | 4 +++ electron/main/ipc/ipc-window.ts | 7 +++++ electron/main/store/index.ts | 2 +- electron/main/tray/index.ts | 25 ++++++++-------- electron/main/windows/lyric-window.ts | 2 +- src/utils/initIpc.ts | 5 +++- src/views/DesktopLyric/index.vue | 43 +++++++++++++++++++-------- 8 files changed, 65 insertions(+), 28 deletions(-) diff --git a/components.d.ts b/components.d.ts index cfe17c3..11a6d09 100644 --- a/components.d.ts +++ b/components.d.ts @@ -61,8 +61,11 @@ declare module 'vue' { NDrawerContent: typeof import('naive-ui')['NDrawerContent'] NDropdown: typeof import('naive-ui')['NDropdown'] NDynamicTags: typeof import('naive-ui')['NDynamicTags'] + NEllipsis: typeof import('naive-ui')['NEllipsis'] NEmpty: typeof import('naive-ui')['NEmpty'] NFlex: typeof import('naive-ui')['NFlex'] + NFloatButton: typeof import('naive-ui')['NFloatButton'] + NFloatButtonGroup: typeof import('naive-ui')['NFloatButtonGroup'] NForm: typeof import('naive-ui')['NForm'] NFormItem: typeof import('naive-ui')['NFormItem'] NFormItemGi: typeof import('naive-ui')['NFormItemGi'] @@ -70,6 +73,7 @@ declare module 'vue' { NGlobalStyle: typeof import('naive-ui')['NGlobalStyle'] NGrid: typeof import('naive-ui')['NGrid'] NH1: typeof import('naive-ui')['NH1'] + NH2: typeof import('naive-ui')['NH2'] NH3: typeof import('naive-ui')['NH3'] NIcon: typeof import('naive-ui')['NIcon'] NImage: typeof import('naive-ui')['NImage'] @@ -100,6 +104,7 @@ declare module 'vue' { NSelect: typeof import('naive-ui')['NSelect'] NSkeleton: typeof import('naive-ui')['NSkeleton'] NSlider: typeof import('naive-ui')['NSlider'] + NSpin: typeof import('naive-ui')['NSpin'] NSwitch: typeof import('naive-ui')['NSwitch'] NTabPane: typeof import('naive-ui')['NTabPane'] NTabs: typeof import('naive-ui')['NTabs'] diff --git a/electron/main/ipc/ipc-lyric.ts b/electron/main/ipc/ipc-lyric.ts index dd4e3ce..8c15b8a 100644 --- a/electron/main/ipc/ipc-lyric.ts +++ b/electron/main/ipc/ipc-lyric.ts @@ -195,6 +195,10 @@ const initLyricIpc = (): void => { } else { lyricWin.setIgnoreMouseEvents(false); } + store.set("lyric.config", { ...store.get("lyric.config"), isLock }); + // 触发窗口更新 + const config = store.get("lyric.config"); + mainWin?.webContents.send("update-desktop-lyric-option", config); }); }; diff --git a/electron/main/ipc/ipc-window.ts b/electron/main/ipc/ipc-window.ts index f984f7b..39f0244 100644 --- a/electron/main/ipc/ipc-window.ts +++ b/electron/main/ipc/ipc-window.ts @@ -118,6 +118,13 @@ const initWindowsIpc = (): void => { // 开启登录窗口 ipcMain.on("open-login-web", () => loginWindow.create(mainWin!)); + + // 开启设置 + ipcMain.on("open-setting", (_, type) => { + mainWin?.show(); + mainWin?.focus(); + mainWin?.webContents.send("openSetting", type); + }); }; export default initWindowsIpc; diff --git a/electron/main/store/index.ts b/electron/main/store/index.ts index 2ccda07..637c8b0 100644 --- a/electron/main/store/index.ts +++ b/electron/main/store/index.ts @@ -43,7 +43,7 @@ export const useStore = () => { x: screenData.workAreaSize.width / 2 - 400, y: screenData.workAreaSize.height - 90, width: 800, - height: 152, + height: 136, config: defaultLyricConfig, }, proxy: "", diff --git a/electron/main/tray/index.ts b/electron/main/tray/index.ts index 69a9fec..fcdd79a 100644 --- a/electron/main/tray/index.ts +++ b/electron/main/tray/index.ts @@ -10,6 +10,7 @@ import { import { isWin, appName } from "../utils/config"; import { join } from "path"; import { trayLog } from "../logger"; +import { useStore } from "../store"; import lyricWindow from "../windows/lyric-window"; // 播放模式 @@ -48,10 +49,7 @@ const trayIcon = (filename: string) => { }; // 托盘菜单 -const createTrayMenu = ( - win: BrowserWindow, - lyricWin: BrowserWindow | null, -): MenuItemConstructorOptions[] => { +const createTrayMenu = (win: BrowserWindow): MenuItemConstructorOptions[] => { // 区分明暗图标 const showIcon = (iconName: string) => { const isDark = nativeTheme.shouldUseDarkColors; @@ -146,11 +144,16 @@ const createTrayMenu = ( id: "toogleDesktopLyricLock", label: `${desktopLyricLock ? "解锁" : "锁定"}桌面歌词`, icon: showIcon(desktopLyricLock ? "lock" : "unlock"), - visible: desktopLyricShow && lyricWin !== null, + visible: desktopLyricShow, click: () => { - if (lyricWin) { - lyricWin.webContents.send("toogleDesktopLyricLock", !desktopLyricLock); - } + const store = useStore(); + // 更新锁定状态 + store.set("lyric.config", { ...store.get("lyric.config"), isLock: !desktopLyricLock }); + // 触发窗口更新 + const config = store.get("lyric.config"); + const lyricWin = lyricWindow.getWin(); + if (!lyricWin) return; + lyricWin.webContents.send("update-desktop-lyric-option", config); }, }, { @@ -187,7 +190,6 @@ const createTrayMenu = ( class CreateTray implements MainTray { // 窗口 private _win: BrowserWindow; - private _lyricWin: BrowserWindow | null; // 托盘 private _tray: Tray; // 菜单 @@ -202,9 +204,8 @@ class CreateTray implements MainTray { }); // 初始化数据 this._win = win; - this._lyricWin = lyricWindow.getWin(); this._tray = new Tray(icon); - this._menu = createTrayMenu(this._win, this._lyricWin); + this._menu = createTrayMenu(this._win); this._contextMenu = Menu.buildFromTemplate(this._menu); // 初始化事件 this.initTrayMenu(); @@ -213,7 +214,7 @@ class CreateTray implements MainTray { } // 托盘菜单 private initTrayMenu() { - this._menu = createTrayMenu(this._win, this._lyricWin); + this._menu = createTrayMenu(this._win); this._contextMenu = Menu.buildFromTemplate(this._menu); this._tray.setContextMenu(this._contextMenu); } diff --git a/electron/main/windows/lyric-window.ts b/electron/main/windows/lyric-window.ts index a542125..748d2cc 100644 --- a/electron/main/windows/lyric-window.ts +++ b/electron/main/windows/lyric-window.ts @@ -58,7 +58,7 @@ class LyricWindow { movable: true, show: false, // 不在任务栏显示 - // skipTaskbar: true, + skipTaskbar: true, // 窗口不能最小化 minimizable: false, // 窗口不能最大化 diff --git a/src/utils/initIpc.ts b/src/utils/initIpc.ts index 63bea3d..5e34903 100644 --- a/src/utils/initIpc.ts +++ b/src/utils/initIpc.ts @@ -1,10 +1,11 @@ import { isElectron } from "./env"; -import { openUpdateApp } from "./modal"; +import { openSetting, openUpdateApp } from "./modal"; import { useMusicStore, useDataStore, useStatusStore } from "@/stores"; import { toLikeSong } from "./auth"; import player from "./player"; import { cloneDeep } from "lodash-es"; import { getPlayerInfo } from "./player-utils/song"; +import { SettingType } from "@/types/main"; // 关闭更新状态 const closeUpdateStatus = () => { @@ -38,6 +39,8 @@ const initIpc = () => { const musicStore = useMusicStore(); await toLikeSong(musicStore.playSong, !dataStore.isLikeSong(musicStore.playSong.id)); }); + // 开启设置 + window.electron.ipcRenderer.on("openSetting", (_, type: SettingType) => openSetting(type)); // 桌面歌词开关 window.electron.ipcRenderer.on("toogleDesktopLyric", () => player.toggleDesktopLyric()); window.electron.ipcRenderer.on("closeDesktopLyric", () => player.toggleDesktopLyric()); diff --git a/src/views/DesktopLyric/index.vue b/src/views/DesktopLyric/index.vue index 544bca8..65fe5e4 100644 --- a/src/views/DesktopLyric/index.vue +++ b/src/views/DesktopLyric/index.vue @@ -32,14 +32,15 @@ -