修复桌面歌词窗口不允许拖出桌面之外的位置计算偏移Bug
parent
1c4e9ed474
commit
8aedde2422
|
@ -1,3 +1,3 @@
|
||||||
### 修复
|
### 修复
|
||||||
|
|
||||||
- 修复某些情况下桌面歌词不会播放的问题
|
- 修复桌面歌词窗口不允许拖出桌面之外的位置计算偏移Bug
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const { common: COMMON_EVENT_NAME, winLyric: WIN_LYRIC_EVENT_NAME, hotKey: HOT_KEY_EVENT_NAME, mainWindow: MAIN_WINDOW_EVENT_NAME } = require('../../events/_name')
|
const { common: COMMON_EVENT_NAME, winLyric: WIN_LYRIC_EVENT_NAME, hotKey: HOT_KEY_EVENT_NAME, mainWindow: MAIN_WINDOW_EVENT_NAME } = require('../../events/_name')
|
||||||
const { mainSend, NAMES: { winLyric: ipcWinLyricNames } } = require('../../../common/ipc')
|
const { mainSend, NAMES: { winLyric: ipcWinLyricNames } } = require('../../../common/ipc')
|
||||||
const { desktop_lyric } = require('../../../common/hotKey')
|
const { desktop_lyric } = require('../../../common/hotKey')
|
||||||
const { setLyricWindow } = require('./utils')
|
const { getLyricWindowBounds } = require('./utils')
|
||||||
|
|
||||||
let isLock = null
|
let isLock = null
|
||||||
let isEnable = null
|
let isEnable = null
|
||||||
|
@ -27,6 +27,17 @@ const setLrcConfig = () => {
|
||||||
isAlwaysOnTop = desktopLyric.isAlwaysOnTop
|
isAlwaysOnTop = desktopLyric.isAlwaysOnTop
|
||||||
global.modules.lyricWindow.setAlwaysOnTop(desktopLyric.isAlwaysOnTop, 'screen-saver')
|
global.modules.lyricWindow.setAlwaysOnTop(desktopLyric.isAlwaysOnTop, 'screen-saver')
|
||||||
}
|
}
|
||||||
|
if (isLockScreen != desktopLyric.isLockScreen) {
|
||||||
|
isLockScreen = desktopLyric.isLockScreen
|
||||||
|
if (desktopLyric.isLockScreen) {
|
||||||
|
global.modules.lyricWindow.setBounds(getLyricWindowBounds(global.modules.lyricWindow.getBounds(), {
|
||||||
|
x: null,
|
||||||
|
y: null,
|
||||||
|
w: desktopLyric.width,
|
||||||
|
h: desktopLyric.height,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (isEnable != desktopLyric.enable) {
|
if (isEnable != desktopLyric.enable) {
|
||||||
isEnable = desktopLyric.enable
|
isEnable = desktopLyric.enable
|
||||||
|
@ -36,17 +47,6 @@ const setLrcConfig = () => {
|
||||||
global.lx_event.winLyric.close()
|
global.lx_event.winLyric.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isLockScreen != desktopLyric.isLockScreen) {
|
|
||||||
isLockScreen = desktopLyric.isLockScreen
|
|
||||||
if (desktopLyric.isLockScreen) {
|
|
||||||
setLyricWindow({
|
|
||||||
x: desktopLyric.x,
|
|
||||||
y: desktopLyric.y,
|
|
||||||
w: desktopLyric.width,
|
|
||||||
h: desktopLyric.height,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
global.lx_event.common.on(COMMON_EVENT_NAME.config, name => {
|
global.lx_event.common.on(COMMON_EVENT_NAME.config, name => {
|
||||||
if (WIN_LYRIC_EVENT_NAME.name === name) return
|
if (WIN_LYRIC_EVENT_NAME.name === name) return
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
const { BrowserWindow } = require('electron')
|
const { BrowserWindow } = require('electron')
|
||||||
const { winLyric: WIN_LYRIC_EVENT_NAME } = require('../../events/_name')
|
const { winLyric: WIN_LYRIC_EVENT_NAME } = require('../../events/_name')
|
||||||
const { debounce } = require('../../../common/utils')
|
const { debounce } = require('../../../common/utils')
|
||||||
|
const { getLyricWindowBounds } = require('./utils')
|
||||||
|
|
||||||
require('./event')
|
require('./event')
|
||||||
require('./rendererEvent')
|
require('./rendererEvent')
|
||||||
|
@ -67,29 +68,29 @@ const winEvent = lyricWindow => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let offset = 8
|
|
||||||
const createWindow = () => {
|
const createWindow = () => {
|
||||||
if (global.modules.lyricWindow) return
|
if (global.modules.lyricWindow) return
|
||||||
if (!global.appSetting.desktopLyric.enable) return
|
if (!global.appSetting.desktopLyric.enable) return
|
||||||
// const windowSizeInfo = getWindowSizeInfo(global.appSetting)
|
// const windowSizeInfo = getWindowSizeInfo(global.appSetting)
|
||||||
let { x, y, width, height, isAlwaysOnTop } = global.appSetting.desktopLyric
|
let { x, y, width, height, isAlwaysOnTop } = global.appSetting.desktopLyric
|
||||||
let { width: screenWidth, height: screenHeight } = global.envParams.workAreaSize
|
let { width: screenWidth, height: screenHeight } = global.envParams.workAreaSize
|
||||||
screenWidth += offset * 2
|
|
||||||
screenHeight += offset * 2
|
|
||||||
if (x == null) {
|
if (x == null) {
|
||||||
x = screenWidth - width - offset
|
x = screenWidth - width
|
||||||
y = screenHeight - height - offset
|
y = screenHeight - height
|
||||||
}
|
}
|
||||||
if (global.appSetting.desktopLyric.isLockScreen) {
|
if (global.appSetting.desktopLyric.isLockScreen) {
|
||||||
x = Math.max(-offset, screenWidth < (width + x) ? screenWidth - width : x)
|
let bounds = getLyricWindowBounds({ x, y, width, height }, { x: null, y: null, w: width, h: height })
|
||||||
y = Math.max(-offset, screenHeight < (height + y) ? screenHeight - height : y)
|
x = bounds.x
|
||||||
|
y = bounds.y
|
||||||
|
width = bounds.width
|
||||||
|
height = bounds.height
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Initial window options
|
* Initial window options
|
||||||
*/
|
*/
|
||||||
global.modules.lyricWindow = new BrowserWindow({
|
global.modules.lyricWindow = new BrowserWindow({
|
||||||
height: Math.max(height > screenHeight ? screenHeight : height, 80),
|
height,
|
||||||
width: Math.max(width > screenWidth ? screenWidth : width, 380),
|
width,
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
minWidth: 380,
|
minWidth: 380,
|
||||||
|
|
|
@ -8,7 +8,7 @@ const {
|
||||||
},
|
},
|
||||||
} = require('../../../common/ipc')
|
} = require('../../../common/ipc')
|
||||||
const { winLyric: WIN_LYRIC_EVENT_NAME } = require('../../events/_name')
|
const { winLyric: WIN_LYRIC_EVENT_NAME } = require('../../events/_name')
|
||||||
const { setLyricWindow } = require('./utils')
|
const { getLyricWindowBounds } = require('./utils')
|
||||||
|
|
||||||
mainOn(ipcWinLyricNames.get_lyric_info, (event, action) => {
|
mainOn(ipcWinLyricNames.get_lyric_info, (event, action) => {
|
||||||
if (!global.modules.mainWindow) return
|
if (!global.modules.mainWindow) return
|
||||||
|
@ -28,5 +28,5 @@ mainHandle(ipcWinLyricNames.get_lyric_config, async() => {
|
||||||
})
|
})
|
||||||
|
|
||||||
mainOn(ipcWinLyricNames.set_win_bounds, (event, options) => {
|
mainOn(ipcWinLyricNames.set_win_bounds, (event, options) => {
|
||||||
setLyricWindow(options)
|
global.modules.lyricWindow.setBounds(getLyricWindowBounds(global.modules.lyricWindow.getBounds(), options))
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,56 +1,68 @@
|
||||||
// 设置窗口位置、大小
|
// 设置窗口位置、大小
|
||||||
let bounds
|
|
||||||
let winX
|
let winX
|
||||||
let winY
|
let winY
|
||||||
let wasW
|
let wasW
|
||||||
let wasY
|
let wasH
|
||||||
let offset = 8
|
let offset = 8
|
||||||
exports.setLyricWindow = ({ x = 0, y = 0, w = 0, h = 0 }) => {
|
let minWidth = 380
|
||||||
if (!global.modules.lyricWindow) return
|
let minHeight = 80
|
||||||
bounds = global.modules.lyricWindow.getBounds()
|
exports.getLyricWindowBounds = (bounds, { x = 0, y = 0, w = 0, h = 0 }) => {
|
||||||
wasW = global.envParams.workAreaSize.width
|
if (w < minWidth) w = minWidth
|
||||||
wasY = global.envParams.workAreaSize.height + offset
|
if (h < minHeight) h = minHeight
|
||||||
|
|
||||||
|
if (global.appSetting.desktopLyric.isLockScreen) {
|
||||||
|
wasW = global.envParams.workAreaSize.width + offset
|
||||||
|
wasH = global.envParams.workAreaSize.height + offset
|
||||||
|
if (w > wasW + offset) w = wasW + offset
|
||||||
|
if (h > wasH + offset) h = wasH + offset
|
||||||
|
if (x == null) {
|
||||||
|
if (global.appSetting.desktopLyric.x > wasW - w) {
|
||||||
|
x = wasW - w - global.appSetting.desktopLyric.x
|
||||||
|
} else if (global.appSetting.desktopLyric.x < -offset) {
|
||||||
|
x = global.appSetting.desktopLyric.x + offset
|
||||||
|
} else {
|
||||||
|
x = 0
|
||||||
|
}
|
||||||
|
if (global.appSetting.desktopLyric.y > wasH - h) {
|
||||||
|
y = wasH - h - global.appSetting.desktopLyric.y
|
||||||
|
} else if (global.appSetting.desktopLyric.y < -offset) {
|
||||||
|
y = global.appSetting.desktopLyric.y + offset
|
||||||
|
} else {
|
||||||
|
y = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
winX = bounds.x + x
|
||||||
|
winY = bounds.y + y
|
||||||
|
|
||||||
|
if (x != 0) {
|
||||||
|
if (winX < -offset) {
|
||||||
|
winX = -offset
|
||||||
|
} else if (winX + w > wasW) {
|
||||||
|
winX = wasW - w
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (y != 0) {
|
||||||
|
if (winY < -offset) {
|
||||||
|
winY = -offset
|
||||||
|
} else if (winY + h > wasH) {
|
||||||
|
winY = wasH - h
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
x = winX
|
||||||
|
y = winY
|
||||||
|
|
||||||
|
if (x + w > wasW) w = wasW - x
|
||||||
|
if (y + h > wasH) h = wasH - y
|
||||||
|
} else {
|
||||||
|
y += bounds.y
|
||||||
|
x += bounds.x
|
||||||
|
}
|
||||||
|
|
||||||
bounds.width = w
|
bounds.width = w
|
||||||
bounds.height = h
|
bounds.height = h
|
||||||
if (bounds.width > wasW - offset) {
|
bounds.x = x
|
||||||
bounds.width = wasW - offset
|
bounds.y = y
|
||||||
} else if (bounds.width < 380) {
|
// console.log('util bounds', bounds)
|
||||||
bounds.width = 380
|
return bounds
|
||||||
}
|
|
||||||
if (bounds.height > wasY) {
|
|
||||||
bounds.height = wasY + offset
|
|
||||||
} else if (bounds.height < 80) {
|
|
||||||
bounds.height = 80
|
|
||||||
}
|
|
||||||
|
|
||||||
if (global.appSetting.desktopLyric.isLockScreen) {
|
|
||||||
if (x != 0) {
|
|
||||||
winX = bounds.x + x
|
|
||||||
if (winX > wasW - bounds.width + offset) {
|
|
||||||
winX = wasW - bounds.width + offset
|
|
||||||
} else if (winX < -offset) {
|
|
||||||
winX = -offset
|
|
||||||
}
|
|
||||||
bounds.x = winX
|
|
||||||
}
|
|
||||||
if (y != 0) {
|
|
||||||
winY = bounds.y + y
|
|
||||||
if (winY > wasY - bounds.height) {
|
|
||||||
winY = wasY - bounds.height
|
|
||||||
} else if (winY < -offset) {
|
|
||||||
winY = -offset
|
|
||||||
}
|
|
||||||
bounds.y = winY
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (x != 0) {
|
|
||||||
bounds.x = bounds.x + x
|
|
||||||
}
|
|
||||||
if (y != 0) {
|
|
||||||
bounds.y = bounds.y + y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// console.log(bounds, x, y, w, h)
|
|
||||||
global.modules.lyricWindow.setBounds(bounds)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue