diff --git a/publish/changeLog.md b/publish/changeLog.md index 73788aa9..7ac7ffdb 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -2,3 +2,4 @@ ### 修复 - 修复声音输出设备更改时后的自动暂停播放设置无效的问题 +- 重写桌面歌词窗口坐标的计算逻辑,修复桌面歌词移动到最边缘时,某些情况下在启用歌词后会出现窗口偏移的问题(远古bug了) diff --git a/src/common/types/desktop_lyric.d.ts b/src/common/types/desktop_lyric.d.ts index 734becbf..db670437 100644 --- a/src/common/types/desktop_lyric.d.ts +++ b/src/common/types/desktop_lyric.d.ts @@ -76,8 +76,8 @@ declare namespace LX { interface NewBounds { - x?: number | null - y?: number + x: number + y: number w: number h: number } diff --git a/src/main/modules/winLyric/main.ts b/src/main/modules/winLyric/main.ts index 1835a1d6..230ee7bd 100644 --- a/src/main/modules/winLyric/main.ts +++ b/src/main/modules/winLyric/main.ts @@ -1,7 +1,7 @@ import { join } from 'path' import { BrowserWindow } from 'electron' import { debounce, isLinux } from '@common/utils' -import { getLyricWindowBounds, offset } from './utils' +import { getLyricWindowBounds, minHeight, minWidth, padding } from './utils' import { mainSend } from '@common/mainIpc' import { encodePath } from '@common/utils/electron' @@ -81,15 +81,20 @@ export const createWindow = () => { let width = global.lx.appSetting['desktopLyric.width'] let height = global.lx.appSetting['desktopLyric.height'] let isAlwaysOnTop = global.lx.appSetting['desktopLyric.isAlwaysOnTop'] - let isLockScreen = global.lx.appSetting['desktopLyric.isLockScreen'] + // let isLockScreen = global.lx.appSetting['desktopLyric.isLockScreen'] let isShowTaskbar = global.lx.appSetting['desktopLyric.isShowTaskbar'] - let { width: screenWidth, height: screenHeight } = global.envParams.workAreaSize + // let { width: screenWidth, height: screenHeight } = global.envParams.workAreaSize if (x == null || y == null) { - x = screenWidth - width + offset - y = screenHeight - height + offset - } - if (isLockScreen) { - let bounds = getLyricWindowBounds({ x, y, width, height }, { x: null, y: 0, w: width, h: height }) + if (width < minWidth) width = minWidth + if (height < minHeight) height = minHeight + if (global.envParams.workAreaSize) { + x = global.envParams.workAreaSize.width + padding - width + y = global.envParams.workAreaSize.height + padding - height + } else { + x = y = -padding + } + } else { + let bounds = getLyricWindowBounds({ x, y, width, height }, { x: 0, y: 0, w: width, h: height }) x = bounds.x y = bounds.y width = bounds.width diff --git a/src/main/modules/winLyric/utils.ts b/src/main/modules/winLyric/utils.ts index 611c3f1b..43e43751 100644 --- a/src/main/modules/winLyric/utils.ts +++ b/src/main/modules/winLyric/utils.ts @@ -1,77 +1,52 @@ // 设置窗口位置、大小 -let winX -let winY -let wasW -let wasH -export const offset = 8 -let minWidth = 80 -let minHeight = 50 +export const padding = 8 +export let minWidth = 80 +export let minHeight = 50 + +// const updateBounds = (bounds: Bounds) => { +// bounds.x = bounds.x +// return bounds +// } + +/** + * + * @param bounds 当前设置 + * @param param 新设置(相对于当前设置) + * @returns + */ export const getLyricWindowBounds = (bounds: Electron.Rectangle, { x = 0, y = 0, w = 0, h = 0 }: LX.DesktopLyric.NewBounds): Electron.Rectangle => { if (w < minWidth) w = minWidth if (h < minHeight) h = minHeight if (global.lx.appSetting['desktopLyric.isLockScreen']) { if (!global.envParams.workAreaSize) return bounds - wasW = (global.envParams.workAreaSize.width ?? 0) + offset - wasH = (global.envParams.workAreaSize.height ?? 0) + offset + const maxWinW = global.envParams.workAreaSize.width + padding * 2 + const maxWinH = global.envParams.workAreaSize.height + padding * 2 - if (w > wasW + offset) w = wasW + offset - if (h > wasH + offset) h = wasH + offset - if (x == null) { - if (bounds.x > wasW - w) { - x = wasW - w - bounds.x - } else if (bounds.x < -offset) { - x = bounds.x + offset - } else { - x = 0 - } - if (bounds.y > wasH - h) { - y = wasH - h - bounds.y - } else if (bounds.y < -offset) { - y = bounds.y + offset - } else { - y = 0 - } - } - winX = bounds.x + x - winY = bounds.y + y + if (w > maxWinW) w = maxWinW + if (h > maxWinH) h = maxWinH - 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 - } - } + const maxX = global.envParams.workAreaSize.width + padding - w + const minX = -padding + const maxY = global.envParams.workAreaSize.height + padding - h + const minY = -padding - x = winX - y = winY + x += bounds.x + y += bounds.y - if (x + w > wasW) w = wasW - x - if (y + h > wasH) h = wasH - y + if (x > maxX) x = maxX + else if (x < minX) x = minX + + if (y > maxY) y = maxY + else if (y < minY) y = minY } else { - if (x == null) { - x = 0 - y = 0 - } y += bounds.y x += bounds.x } - bounds.width = w - bounds.height = h - bounds.x = x - bounds.y = y // console.log('util bounds', bounds) - return bounds + return { width: w, height: h, x, y } } diff --git a/src/renderer-lyric/useApp/useWindowSize.ts b/src/renderer-lyric/useApp/useWindowSize.ts index b9d3ee4a..f4807844 100644 --- a/src/renderer-lyric/useApp/useWindowSize.ts +++ b/src/renderer-lyric/useApp/useWindowSize.ts @@ -29,6 +29,7 @@ export default () => { let bounds: LX.DesktopLyric.NewBounds = { w: 0, h: 0, + x: 0, y: 0, } let temp