防止桌面歌词窗口在屏幕分辨率变小时,窗口位置跟随分辨率变化的问题
This commit is contained in:
@@ -9,10 +9,11 @@ import { encodePath } from '@common/utils/electron'
|
||||
// require('./rendererEvent')
|
||||
|
||||
let browserWindow: Electron.BrowserWindow | null = null
|
||||
let isWinBoundsUdating = false
|
||||
|
||||
|
||||
const setLyricsConfig = debounce((config: Partial<LX.AppSetting>) => {
|
||||
const saveBoundsConfig = debounce((config: Partial<LX.AppSetting>) => {
|
||||
global.lx.event_app.update_config(config)
|
||||
if (isWinBoundsUdating) isWinBoundsUdating = false
|
||||
}, 500)
|
||||
|
||||
const winEvent = () => {
|
||||
@@ -31,21 +32,31 @@ const winEvent = () => {
|
||||
|
||||
browserWindow.on('move', () => {
|
||||
// bounds = browserWindow.getBounds()
|
||||
// console.log(bounds)
|
||||
const bounds = browserWindow!.getBounds()
|
||||
setLyricsConfig({
|
||||
'desktopLyric.x': bounds.x,
|
||||
'desktopLyric.y': bounds.y,
|
||||
'desktopLyric.width': bounds.width,
|
||||
'desktopLyric.height': bounds.height,
|
||||
})
|
||||
// console.log('move', isWinBoundsUdating)
|
||||
if (isWinBoundsUdating) {
|
||||
const bounds = browserWindow!.getBounds()
|
||||
saveBoundsConfig({
|
||||
'desktopLyric.x': bounds.x,
|
||||
'desktopLyric.y': bounds.y,
|
||||
'desktopLyric.width': bounds.width,
|
||||
'desktopLyric.height': bounds.height,
|
||||
})
|
||||
} else {
|
||||
// 非主动调整窗口触发的窗口位置变化将重置回设置值
|
||||
browserWindow!.setBounds({
|
||||
x: global.lx.appSetting['desktopLyric.x'] ?? 0,
|
||||
y: global.lx.appSetting['desktopLyric.y'] ?? 0,
|
||||
width: global.lx.appSetting['desktopLyric.width'],
|
||||
height: global.lx.appSetting['desktopLyric.height'],
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
browserWindow.on('resize', () => {
|
||||
// bounds = browserWindow.getBounds()
|
||||
// console.log(bounds)
|
||||
const bounds = browserWindow!.getBounds()
|
||||
setLyricsConfig({
|
||||
saveBoundsConfig({
|
||||
'desktopLyric.x': bounds.x,
|
||||
'desktopLyric.y': bounds.y,
|
||||
'desktopLyric.width': bounds.width,
|
||||
@@ -102,6 +113,7 @@ export const createWindow = () => {
|
||||
}
|
||||
|
||||
const { shouldUseDarkColors, theme } = global.lx.theme
|
||||
isWinBoundsUdating = true
|
||||
|
||||
/**
|
||||
* Initial window options
|
||||
@@ -166,6 +178,7 @@ export const getBounds = (): Electron.Rectangle => {
|
||||
|
||||
export const setBounds = (bounds: Electron.Rectangle) => {
|
||||
if (!browserWindow) return
|
||||
isWinBoundsUdating = true
|
||||
browserWindow.setBounds(bounds)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user