修复桌面歌词的 鼠标移入歌词区域时提高透明度 设置不稳定的问题 (#2679)
Co-authored-by: lyswhut <lyswhut@qq.com>
This commit is contained in:
@@ -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<keyof LX.AppSetting>, 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<keyof LX.AppSetting>, 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<keyof LX.AppSetting>, 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<keyof LX.AppSetting>, setting: Partial<
|
||||
createWindow()
|
||||
} else {
|
||||
alwaysOnTopTools.clearLoop()
|
||||
mouseCheckTools.cacnelCheck()
|
||||
closeWindow()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,8 +172,8 @@ export const sendEvent = <T = any>(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()
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
},
|
||||
}
|
||||
@@ -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<LX.DesktopLyric.NewBounds>(WIN_LYRIC_RENDERER_EVENT_NAME.set_win_bounds, ({ params: options }) => {
|
||||
setBounds(getLyricWindowBounds(getBounds(), options))
|
||||
setBounds(getLyricWindowBounds(getBounds()!, options))
|
||||
})
|
||||
|
||||
mainOn<boolean>(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<boolean>(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<LX.DesktopLyric.Config>) => {
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user