This commit is contained in:
14K 2024-10-28 23:20:42 +08:00 committed by GitHub
commit 29df5ceb87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 39 additions and 25 deletions

View File

@ -49,7 +49,7 @@ declare namespace LX {
interface EnvParams {
deeplink?: string | null
cmdParams: CmdParams
workAreaSize?: Electron.Size
workArea?: Electron.Rectangle
}
interface HotKey {

View File

@ -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",

View File

@ -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": "重置窗口设置",

View File

@ -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": "重置視窗設定",

View File

@ -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)

View File

@ -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<keyof LX.AppSetting>, 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,

View File

@ -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,

View File

@ -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
}