修复桌面歌词窗口不允许拖出桌面之外的位置计算偏移Bug

This commit is contained in:
lyswhut
2020-09-19 16:00:03 +08:00
parent 1c4e9ed474
commit 8aedde2422
5 changed files with 84 additions and 71 deletions
+10 -9
View File
@@ -1,6 +1,7 @@
const { BrowserWindow } = require('electron')
const { winLyric: WIN_LYRIC_EVENT_NAME } = require('../../events/_name')
const { debounce } = require('../../../common/utils')
const { getLyricWindowBounds } = require('./utils')
require('./event')
require('./rendererEvent')
@@ -67,29 +68,29 @@ const winEvent = lyricWindow => {
})
}
let offset = 8
const createWindow = () => {
if (global.modules.lyricWindow) return
if (!global.appSetting.desktopLyric.enable) return
// const windowSizeInfo = getWindowSizeInfo(global.appSetting)
let { x, y, width, height, isAlwaysOnTop } = global.appSetting.desktopLyric
let { width: screenWidth, height: screenHeight } = global.envParams.workAreaSize
screenWidth += offset * 2
screenHeight += offset * 2
if (x == null) {
x = screenWidth - width - offset
y = screenHeight - height - offset
x = screenWidth - width
y = screenHeight - height
}
if (global.appSetting.desktopLyric.isLockScreen) {
x = Math.max(-offset, screenWidth < (width + x) ? screenWidth - width : x)
y = Math.max(-offset, screenHeight < (height + y) ? screenHeight - height : y)
let bounds = getLyricWindowBounds({ x, y, width, height }, { x: null, y: null, w: width, h: height })
x = bounds.x
y = bounds.y
width = bounds.width
height = bounds.height
}
/**
* Initial window options
*/
global.modules.lyricWindow = new BrowserWindow({
height: Math.max(height > screenHeight ? screenHeight : height, 80),
width: Math.max(width > screenWidth ? screenWidth : width, 380),
height,
width,
x,
y,
minWidth: 380,