From 8aedde2422b5d447cb902407b4eb5990a6640082 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Sat, 19 Sep 2020 16:00:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=A1=8C=E9=9D=A2=E6=AD=8C?= =?UTF-8?q?=E8=AF=8D=E7=AA=97=E5=8F=A3=E4=B8=8D=E5=85=81=E8=AE=B8=E6=8B=96?= =?UTF-8?q?=E5=87=BA=E6=A1=8C=E9=9D=A2=E4=B9=8B=E5=A4=96=E7=9A=84=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E8=AE=A1=E7=AE=97=E5=81=8F=E7=A7=BBBug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 2 +- src/main/modules/winLyric/event.js | 24 ++--- src/main/modules/winLyric/index.js | 19 ++-- src/main/modules/winLyric/rendererEvent.js | 4 +- src/main/modules/winLyric/utils.js | 106 ++++++++++++--------- 5 files changed, 84 insertions(+), 71 deletions(-) diff --git a/publish/changeLog.md b/publish/changeLog.md index 9a53de65..39e64e8a 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -1,3 +1,3 @@ ### 修复 -- 修复某些情况下桌面歌词不会播放的问题 +- 修复桌面歌词窗口不允许拖出桌面之外的位置计算偏移Bug diff --git a/src/main/modules/winLyric/event.js b/src/main/modules/winLyric/event.js index 513adc16..43de0f63 100644 --- a/src/main/modules/winLyric/event.js +++ b/src/main/modules/winLyric/event.js @@ -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 { mainSend, NAMES: { winLyric: ipcWinLyricNames } } = require('../../../common/ipc') const { desktop_lyric } = require('../../../common/hotKey') -const { setLyricWindow } = require('./utils') +const { getLyricWindowBounds } = require('./utils') let isLock = null let isEnable = null @@ -27,6 +27,17 @@ const setLrcConfig = () => { isAlwaysOnTop = desktopLyric.isAlwaysOnTop 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) { isEnable = desktopLyric.enable @@ -36,17 +47,6 @@ const setLrcConfig = () => { 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 => { if (WIN_LYRIC_EVENT_NAME.name === name) return diff --git a/src/main/modules/winLyric/index.js b/src/main/modules/winLyric/index.js index 3b2e150d..49cf2cb5 100644 --- a/src/main/modules/winLyric/index.js +++ b/src/main/modules/winLyric/index.js @@ -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, diff --git a/src/main/modules/winLyric/rendererEvent.js b/src/main/modules/winLyric/rendererEvent.js index 75d38dbc..ce8721a8 100644 --- a/src/main/modules/winLyric/rendererEvent.js +++ b/src/main/modules/winLyric/rendererEvent.js @@ -8,7 +8,7 @@ const { }, } = require('../../../common/ipc') const { winLyric: WIN_LYRIC_EVENT_NAME } = require('../../events/_name') -const { setLyricWindow } = require('./utils') +const { getLyricWindowBounds } = require('./utils') mainOn(ipcWinLyricNames.get_lyric_info, (event, action) => { if (!global.modules.mainWindow) return @@ -28,5 +28,5 @@ mainHandle(ipcWinLyricNames.get_lyric_config, async() => { }) mainOn(ipcWinLyricNames.set_win_bounds, (event, options) => { - setLyricWindow(options) + global.modules.lyricWindow.setBounds(getLyricWindowBounds(global.modules.lyricWindow.getBounds(), options)) }) diff --git a/src/main/modules/winLyric/utils.js b/src/main/modules/winLyric/utils.js index 48c891eb..b773ce87 100644 --- a/src/main/modules/winLyric/utils.js +++ b/src/main/modules/winLyric/utils.js @@ -1,56 +1,68 @@ // 设置窗口位置、大小 -let bounds let winX let winY let wasW -let wasY +let wasH let offset = 8 -exports.setLyricWindow = ({ x = 0, y = 0, w = 0, h = 0 }) => { - if (!global.modules.lyricWindow) return - bounds = global.modules.lyricWindow.getBounds() - wasW = global.envParams.workAreaSize.width - wasY = global.envParams.workAreaSize.height + offset +let minWidth = 380 +let minHeight = 80 +exports.getLyricWindowBounds = (bounds, { x = 0, y = 0, w = 0, h = 0 }) => { + if (w < minWidth) w = minWidth + 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.height = h - if (bounds.width > wasW - offset) { - bounds.width = wasW - offset - } else if (bounds.width < 380) { - bounds.width = 380 - } - 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) + bounds.x = x + bounds.y = y + // console.log('util bounds', bounds) + return bounds }