防止桌面歌词窗口在屏幕分辨率变小时,窗口位置跟随分辨率变化的问题

This commit is contained in:
lyswhut
2023-02-07 11:56:19 +08:00
parent cf960e3695
commit 3bff44da0c
3 changed files with 30 additions and 11 deletions
+24 -11
View File
@@ -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)
}
+4
View File
@@ -8,6 +8,10 @@ export default (db: Database.Database) => {
for (const info of result) dbTableMap.set(info.name, info.sql.replace(rxp, ''))
return Array.from(tables.entries()).every(([name, sql]) => {
const dbSql = dbTableMap.get(name)
// if (!(dbSql && dbSql == sql.replace(rxp, ''))) {
// console.log('dbSql:', dbSql, '\nsql:', sql.replace(rxp, ''))
// }
// return true
return dbSql && dbSql == sql.replace(rxp, '')
})
// console.log(dbTableMap)