From 0695bbaa70d74b2ad48b1d7389f9a1331cde3546 Mon Sep 17 00:00:00 2001 From: Little_100 <134726985+Little100@users.noreply.github.com> Date: Sat, 7 Mar 2026 13:52:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=A1=8C=E9=9D=A2=E6=AD=8C?= =?UTF-8?q?=E8=AF=8D=E7=9A=84=20=E9=BC=A0=E6=A0=87=E7=A7=BB=E5=85=A5?= =?UTF-8?q?=E6=AD=8C=E8=AF=8D=E5=8C=BA=E5=9F=9F=E6=97=B6=E6=8F=90=E9=AB=98?= =?UTF-8?q?=E9=80=8F=E6=98=8E=E5=BA=A6=20=E8=AE=BE=E7=BD=AE=E4=B8=8D?= =?UTF-8?q?=E7=A8=B3=E5=AE=9A=E7=9A=84=E9=97=AE=E9=A2=98=20(#2679)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: lyswhut --- publish/changeLog.md | 8 +- src/common/ipcNames.ts | 1 + src/main/modules/winLyric/config.ts | 9 +- src/main/modules/winLyric/main.ts | 4 +- src/main/modules/winLyric/mouseCheckTools.ts | 57 ++++++++++ src/main/modules/winLyric/rendererEvent.ts | 16 ++- src/renderer-lyric/App.vue | 9 +- src/renderer-lyric/useApp/useHoverHide.ts | 103 +++++-------------- src/renderer-lyric/utils/ipc.ts | 10 ++ 9 files changed, 121 insertions(+), 96 deletions(-) create mode 100644 src/main/modules/winLyric/mouseCheckTools.ts diff --git a/publish/changeLog.md b/publish/changeLog.md index 93357964..700d941b 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -1,12 +1,6 @@ 我们很高兴地宣布新项目 Any Listen 的桌面版已发布,目前已支持列表跟随本地文件自动更新、加载并播放WebDAV上的歌曲等功能,更多功能仍在积极开发中,桌面版与Web版将同步更新。 对于有播放本地音乐或播放服务器上音乐需求的人可以试试,若遇到任何问题可以发 issue 反馈。 -### 优化 - -- 优化托盘图标行为:在非 Windows 系统中,点击托盘图标时不再显示主窗口 - ### 修复 -- 修复音量条在调整音量时实际音量与显示的数值不一致的问题(#2606) -- 修复某些情况下搜索框的搜索按钮布局错位的问题(#2622) -- 修复 wyy 部分歌曲无法被搜索的问题(#2666, @ikun0014) +- 修复桌面歌词的 鼠标移入歌词区域时提高透明度 设置不稳定的问题(#2679, @Little100) diff --git a/src/common/ipcNames.ts b/src/common/ipcNames.ts index 4084c9d4..58ee3100 100644 --- a/src/common/ipcNames.ts +++ b/src/common/ipcNames.ts @@ -166,6 +166,7 @@ const modules = { key_down: 'key_down', request_main_window_channel: 'request_main_window_channel', provide_main_window_channel: 'provide_main_window_channel', + mouse_enter_leave: 'mouse_enter_leave', }, hotKey: { enable: 'enable', diff --git a/src/main/modules/winLyric/config.ts b/src/main/modules/winLyric/config.ts index 59c9e94d..08bef36e 100644 --- a/src/main/modules/winLyric/config.ts +++ b/src/main/modules/winLyric/config.ts @@ -1,7 +1,8 @@ import { isLinux } from '@common/utils' import { closeWindow, createWindow, getBounds, isExistWindow, alwaysOnTopTools, setBounds, setIgnoreMouseEvents, setSkipTaskbar } from './main' -import { sendConfigChange } from './rendererEvent' +import { sendConfigChange, sendMouseLeave } from './rendererEvent' import { buildLyricConfig, getLyricWindowBounds, initWindowSize, watchConfigKeys } from './utils' +import { mouseCheckTools } from './mouseCheckTools' let isLock: boolean let isEnable: boolean @@ -21,8 +22,10 @@ export const setLrcConfig = (keys: Array, setting: Partial< isLock = global.lx.appSetting['desktopLyric.isLock'] if (global.lx.appSetting['desktopLyric.isLock']) { setIgnoreMouseEvents(true, { forward: !isLinux && global.lx.appSetting['desktopLyric.isHoverHide'] }) + mouseCheckTools.runCheck(sendMouseLeave) } else { setIgnoreMouseEvents(false, { forward: !isLinux && global.lx.appSetting['desktopLyric.isHoverHide'] }) + mouseCheckTools.cacnelCheck() } } if (keys.includes('desktopLyric.isHoverHide') && isHoverHide != global.lx.appSetting['desktopLyric.isHoverHide']) { @@ -30,6 +33,7 @@ export const setLrcConfig = (keys: Array, setting: Partial< if (!isLinux) { setIgnoreMouseEvents(global.lx.appSetting['desktopLyric.isLock'], { forward: global.lx.appSetting['desktopLyric.isHoverHide'] }) } + mouseCheckTools.runCheck(sendMouseLeave) } if (keys.includes('desktopLyric.isAlwaysOnTop') && isAlwaysOnTop != global.lx.appSetting['desktopLyric.isAlwaysOnTop']) { isAlwaysOnTop = global.lx.appSetting['desktopLyric.isAlwaysOnTop'] @@ -54,7 +58,7 @@ export const setLrcConfig = (keys: Array, setting: Partial< if (keys.includes('desktopLyric.isLockScreen') && isLockScreen != global.lx.appSetting['desktopLyric.isLockScreen']) { isLockScreen = global.lx.appSetting['desktopLyric.isLockScreen'] if (global.lx.appSetting['desktopLyric.isLockScreen']) { - setBounds(getLyricWindowBounds(getBounds(), { + setBounds(getLyricWindowBounds(getBounds()!, { x: 0, y: 0, w: global.lx.appSetting['desktopLyric.width'], @@ -77,6 +81,7 @@ export const setLrcConfig = (keys: Array, setting: Partial< createWindow() } else { alwaysOnTopTools.clearLoop() + mouseCheckTools.cacnelCheck() closeWindow() } } diff --git a/src/main/modules/winLyric/main.ts b/src/main/modules/winLyric/main.ts index d4fed3c4..9a1b88dc 100644 --- a/src/main/modules/winLyric/main.ts +++ b/src/main/modules/winLyric/main.ts @@ -172,8 +172,8 @@ export const sendEvent = (name: string, params?: T) => { mainSend(browserWindow, name, params) } -export const getBounds = (): Electron.Rectangle => { - if (!browserWindow) throw new Error('window is not available') +export const getBounds = (): Electron.Rectangle | null => { + if (!browserWindow) return null return browserWindow.getBounds() } diff --git a/src/main/modules/winLyric/mouseCheckTools.ts b/src/main/modules/winLyric/mouseCheckTools.ts new file mode 100644 index 00000000..b27f29fa --- /dev/null +++ b/src/main/modules/winLyric/mouseCheckTools.ts @@ -0,0 +1,57 @@ +import { screen } from 'electron' +import { getBounds } from './main' +import { isLinux } from '@common/utils' + + +export const mouseCheckTools = { + timer: null as NodeJS.Timeout | null, + isMouseInWindow: false, + sendMouseLeave: null as (() => void) | null, + + onInBoundsChange(isInBounds: boolean) { + if (isInBounds) return + this.stop() + this.sendMouseLeave?.() + }, + + checkMousePosition() { + const bounds = getBounds() + if (!bounds) return + const point = screen.getCursorScreenPoint() + const isInBounds = point.x >= bounds.x && point.x <= bounds.x + bounds.width && + point.y >= bounds.y && point.y <= bounds.y + bounds.height + if (isInBounds !== this.isMouseInWindow) { + this.isMouseInWindow = isInBounds + this.onInBoundsChange(isInBounds) + } + }, + + start() { + this.timer = setTimeout(() => { + this.timer = null + this.checkMousePosition() + this.start() + }, 500) + }, + + stop() { + if (!this.timer) return + clearTimeout(this.timer) + this.timer = null + // console.log('stop check') + }, + + setMouseInWindow(isInWindow: boolean) { + this.isMouseInWindow = isInWindow + }, + runCheck(sendMouseLeave: () => void) { + if (isLinux || !global.lx.appSetting['desktopLyric.isLock'] || !global.lx.appSetting['desktopLyric.isHoverHide'] || !this.isMouseInWindow) return + // console.log('run check') + this.sendMouseLeave = sendMouseLeave + this.stop() + this.start() + }, + cacnelCheck() { + this.stop() + }, +} diff --git a/src/main/modules/winLyric/rendererEvent.ts b/src/main/modules/winLyric/rendererEvent.ts index 7f21f2b8..a537e70c 100644 --- a/src/main/modules/winLyric/rendererEvent.ts +++ b/src/main/modules/winLyric/rendererEvent.ts @@ -5,6 +5,7 @@ import { buildLyricConfig, getLyricWindowBounds } from './utils' import { sendNewDesktopLyricClient } from '@main/modules/winMain' import { getBounds, getMainFrame, sendEvent, setBounds, setResizeable } from './main' import { MessageChannelMain } from 'electron' +import { mouseCheckTools } from './mouseCheckTools' export default () => { @@ -26,7 +27,7 @@ export default () => { }) mainOn(WIN_LYRIC_RENDERER_EVENT_NAME.set_win_bounds, ({ params: options }) => { - setBounds(getLyricWindowBounds(getBounds(), options)) + setBounds(getLyricWindowBounds(getBounds()!, options)) }) mainOn(WIN_LYRIC_RENDERER_EVENT_NAME.set_win_resizeable, ({ params: resizable }) => { @@ -45,6 +46,16 @@ export default () => { // without going through the main process! console.log('request_main_window_channel') }) + + mainOn(WIN_LYRIC_RENDERER_EVENT_NAME.mouse_enter_leave, ({ params: isEnter }) => { + if (isEnter) { + mouseCheckTools.setMouseInWindow(true) + mouseCheckTools.runCheck(sendMouseLeave) + } else { + mouseCheckTools.setMouseInWindow(false) + mouseCheckTools.cacnelCheck() + } + }) } export const sendConfigChange = (setting: Partial) => { @@ -55,3 +66,6 @@ export const sendMainWindowInitedEvent = () => { sendEvent(WIN_LYRIC_RENDERER_EVENT_NAME.main_window_inited) } +export const sendMouseLeave = () => { + sendEvent(WIN_LYRIC_RENDERER_EVENT_NAME.mouse_enter_leave, false) +} diff --git a/src/renderer-lyric/App.vue b/src/renderer-lyric/App.vue index a0199e5c..c296753a 100644 --- a/src/renderer-lyric/App.vue +++ b/src/renderer-lyric/App.vue @@ -1,6 +1,6 @@