From 329cbd1830f17d89e60ac7655b2c8299b3d77029 Mon Sep 17 00:00:00 2001 From: 14Kay <619113277@qq.com> Date: Sat, 12 Oct 2024 15:41:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=81=E8=AE=B8=E6=AD=8C=E8=AF=8D?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E4=B8=8D=E8=B6=85=E5=87=BA=E4=BB=BB=E6=84=8F?= =?UTF-8?q?=E5=B1=8F=E5=B9=95=E8=80=8C=E4=B8=8D=E4=BB=85=E6=98=AF=E4=B8=BB?= =?UTF-8?q?=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/types/common.d.ts | 2 +- src/lang/en-us.json | 2 +- src/lang/zh-cn.json | 2 +- src/lang/zh-tw.json | 2 +- src/main/app.ts | 2 +- src/main/modules/winLyric/config.ts | 15 ++++++++++++- src/main/modules/winLyric/main.ts | 4 ++-- src/main/modules/winLyric/utils.ts | 35 +++++++++++++++-------------- 8 files changed, 39 insertions(+), 25 deletions(-) diff --git a/src/common/types/common.d.ts b/src/common/types/common.d.ts index cfec34b0..f11630c8 100644 --- a/src/common/types/common.d.ts +++ b/src/common/types/common.d.ts @@ -49,7 +49,7 @@ declare namespace LX { interface EnvParams { deeplink?: string | null cmdParams: CmdParams - workAreaSize?: Electron.Size + workArea?: Electron.Rectangle } interface HotKey { diff --git a/src/lang/en-us.json b/src/lang/en-us.json index 3573fe80..a5379bec 100644 --- a/src/lang/en-us.json +++ b/src/lang/en-us.json @@ -382,7 +382,7 @@ "setting__desktop_lyric_line_gap_add": "Increase spacing", "setting__desktop_lyric_line_gap_dec": "Reduce spacing", "setting__desktop_lyric_lock": "Lock lyrics", - "setting__desktop_lyric_lock_screen": "It is not allowed to drag the lyrics window out of the main screen", + "setting__desktop_lyric_lock_screen": "It is not allowed to drag the lyrics window out of the current screen", "setting__desktop_lyric_played_color": "color played", "setting__desktop_lyric_reset": "Reset", "setting__desktop_lyric_reset_window": "Reset window settings", diff --git a/src/lang/zh-cn.json b/src/lang/zh-cn.json index 7fe6fd0b..534470ac 100644 --- a/src/lang/zh-cn.json +++ b/src/lang/zh-cn.json @@ -382,7 +382,7 @@ "setting__desktop_lyric_line_gap_add": "加大间距", "setting__desktop_lyric_line_gap_dec": "减小间距", "setting__desktop_lyric_lock": "锁定歌词", - "setting__desktop_lyric_lock_screen": "不允许歌词窗口拖出主屏幕之外", + "setting__desktop_lyric_lock_screen": "不允许歌词窗口拖出当前屏幕之外", "setting__desktop_lyric_played_color": "已播放颜色", "setting__desktop_lyric_reset": "重置", "setting__desktop_lyric_reset_window": "重置窗口设置", diff --git a/src/lang/zh-tw.json b/src/lang/zh-tw.json index b4be0c78..23169369 100644 --- a/src/lang/zh-tw.json +++ b/src/lang/zh-tw.json @@ -382,7 +382,7 @@ "setting__desktop_lyric_line_gap_add": "加大間距", "setting__desktop_lyric_line_gap_dec": "減小間距", "setting__desktop_lyric_lock": "鎖定歌詞", - "setting__desktop_lyric_lock_screen": "不允許歌詞視窗拖出主畫面之外", + "setting__desktop_lyric_lock_screen": "不允許歌詞視窗拖出目前畫面之外", "setting__desktop_lyric_played_color": "已播放顏色", "setting__desktop_lyric_reset": "重置", "setting__desktop_lyric_reset_window": "重置視窗設定", diff --git a/src/main/app.ts b/src/main/app.ts index 5be425b3..bfb4599e 100644 --- a/src/main/app.ts +++ b/src/main/app.ts @@ -215,7 +215,7 @@ export const listenerAppEvent = (startApp: () => void) => { }) const initScreenParams = () => { - global.envParams.workAreaSize = screen.getPrimaryDisplay().workAreaSize + global.envParams.workArea = screen.getPrimaryDisplay().workArea } app.on('ready', () => { screen.on('display-metrics-changed', initScreenParams) diff --git a/src/main/modules/winLyric/config.ts b/src/main/modules/winLyric/config.ts index 59c9e94d..4de976c1 100644 --- a/src/main/modules/winLyric/config.ts +++ b/src/main/modules/winLyric/config.ts @@ -1,7 +1,8 @@ import { isLinux } from '@common/utils' import { closeWindow, createWindow, getBounds, isExistWindow, alwaysOnTopTools, setBounds, setIgnoreMouseEvents, setSkipTaskbar } from './main' import { sendConfigChange } from './rendererEvent' -import { buildLyricConfig, getLyricWindowBounds, initWindowSize, watchConfigKeys } from './utils' +import { buildLyricConfig, getLyricWindowBounds, initWindowSize, watchConfigKeys, setWorkArea } from './utils' +import { screen } from 'electron' let isLock: boolean let isEnable: boolean @@ -53,6 +54,18 @@ export const setLrcConfig = (keys: Array, setting: Partial< } if (keys.includes('desktopLyric.isLockScreen') && isLockScreen != global.lx.appSetting['desktopLyric.isLockScreen']) { isLockScreen = global.lx.appSetting['desktopLyric.isLockScreen'] + const bounds = getBounds() + const displays = screen.getAllDisplays() + const displayOn = displays.find((display: Electron.Display) => { + const { x, y, width, height } = display.bounds + return ( + bounds.x >= x && + bounds.y >= y && + bounds.x < x + width && + bounds.y < y + height + ) + }) + setWorkArea(displayOn!.workArea || displays[0].workArea) if (global.lx.appSetting['desktopLyric.isLockScreen']) { setBounds(getLyricWindowBounds(getBounds(), { x: 0, diff --git a/src/main/modules/winLyric/main.ts b/src/main/modules/winLyric/main.ts index cc168395..6b997dcb 100644 --- a/src/main/modules/winLyric/main.ts +++ b/src/main/modules/winLyric/main.ts @@ -87,7 +87,7 @@ const winEvent = () => { export const createWindow = () => { closeWindow() - if (!global.envParams.workAreaSize) return + if (!global.envParams.workArea) return let x = global.lx.appSetting['desktopLyric.x'] let y = global.lx.appSetting['desktopLyric.y'] let width = global.lx.appSetting['desktopLyric.width'] @@ -95,7 +95,7 @@ export const createWindow = () => { let isAlwaysOnTop = global.lx.appSetting['desktopLyric.isAlwaysOnTop'] // 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.workArea const winSize = initWindowSize(x, y, width, height) global.lx.event_app.update_config({ 'desktopLyric.x': winSize.x, diff --git a/src/main/modules/winLyric/utils.ts b/src/main/modules/winLyric/utils.ts index 722e62eb..04ae3c06 100644 --- a/src/main/modules/winLyric/utils.ts +++ b/src/main/modules/winLyric/utils.ts @@ -8,6 +8,10 @@ export let minHeight = 50 // return bounds // } +export const setWorkArea = (workArea: Electron.Rectangle) => { + global.envParams.workArea = workArea +} + /** * * @param bounds 当前设置 @@ -19,24 +23,21 @@ export const getLyricWindowBounds = (bounds: Electron.Rectangle, { x = 0, y = 0, if (h < minHeight) h = minHeight if (global.lx.appSetting['desktopLyric.isLockScreen']) { - if (!global.envParams.workAreaSize) return bounds - const maxWinW = global.envParams.workAreaSize.width - const maxWinH = global.envParams.workAreaSize.height + const workArea = global.envParams.workArea + if (!workArea) return bounds - if (w > maxWinW) w = maxWinW - if (h > maxWinH) h = maxWinH + const maxWinW = workArea.width + const maxWinH = workArea.height - const maxX = global.envParams.workAreaSize.width - w - const maxY = global.envParams.workAreaSize.height - h + // 限制宽高不超过工作区域 + w = Math.min(w, maxWinW) + h = Math.min(h, maxWinH) - x += bounds.x - y += bounds.y + const maxX = workArea.x + maxWinW - w + const maxY = workArea.y + maxWinH - h - if (x > maxX) x = maxX - else if (x < 0) x = 0 - - if (y > maxY) y = maxY - else if (y < 0) y = 0 + x = Math.max(workArea.x, Math.min(x + bounds.x, maxX)) + y = Math.max(workArea.y, Math.min(y + bounds.y, maxY)) } else { y += bounds.y x += bounds.x @@ -97,9 +98,9 @@ export const initWindowSize = (x: LX.AppSetting['desktopLyric.x'], y: LX.AppSett if (x == null || y == null) { if (width < minWidth) width = minWidth if (height < minHeight) height = minHeight - if (global.envParams.workAreaSize) { - x = global.envParams.workAreaSize.width - width - y = global.envParams.workAreaSize.height - height + if (global.envParams.workArea) { + x = global.envParams.workArea.width - width + y = global.envParams.workArea.height - height } else { x = y = 0 }