This commit is contained in:
lyswhut
2022-10-29 11:36:35 +08:00
parent 66b965d9f7
commit e45cee6596
715 changed files with 57096 additions and 31771 deletions
+70
View File
@@ -0,0 +1,70 @@
import { isLinux } from '@common/utils'
import { closeWindow, createWindow, getBounds, isExistWindow, alwaysOnTopTools, setBounds, setIgnoreMouseEvents } from './main'
import { sendConfigChange } from './rendererEvent'
import { buildLyricConfig, getLyricWindowBounds, watchConfigKeys } from './utils'
let isLock: boolean
let isEnable: boolean
let isAlwaysOnTop: boolean
let isAlwaysOnTopLoop: boolean
let isLockScreen: boolean
let isHoverHide: boolean
export const setLrcConfig = (keys: Array<keyof LX.AppSetting>, setting: Partial<LX.AppSetting>) => {
if (!watchConfigKeys.some(key => keys.includes(key))) return
if (isExistWindow()) {
sendConfigChange(buildLyricConfig(setting))
if (keys.includes('desktopLyric.isLock') && isLock != global.lx.appSetting['desktopLyric.isLock']) {
isLock = global.lx.appSetting['desktopLyric.isLock']
if (global.lx.appSetting['desktopLyric.isLock']) {
setIgnoreMouseEvents(true, { forward: !isLinux && global.lx.appSetting['desktopLyric.isHoverHide'] })
} else {
setIgnoreMouseEvents(false, { forward: !isLinux && global.lx.appSetting['desktopLyric.isHoverHide'] })
}
}
if (keys.includes('desktopLyric.isHoverHide') && isHoverHide != global.lx.appSetting['desktopLyric.isHoverHide']) {
isHoverHide = global.lx.appSetting['desktopLyric.isHoverHide']
if (!isLinux) {
setIgnoreMouseEvents(global.lx.appSetting['desktopLyric.isLock'], { forward: global.lx.appSetting['desktopLyric.isHoverHide'] })
}
}
if (keys.includes('desktopLyric.isAlwaysOnTop') && isAlwaysOnTop != global.lx.appSetting['desktopLyric.isAlwaysOnTop']) {
isAlwaysOnTop = global.lx.appSetting['desktopLyric.isAlwaysOnTop']
alwaysOnTopTools.setAlwaysOnTop(global.lx.appSetting['desktopLyric.isAlwaysOnTopLoop'])
if (isAlwaysOnTop && global.lx.appSetting['desktopLyric.isAlwaysOnTopLoop']) {
alwaysOnTopTools.startLoop()
} else alwaysOnTopTools.clearLoop()
}
if (keys.includes('desktopLyric.isAlwaysOnTopLoop') && isAlwaysOnTopLoop != global.lx.appSetting['desktopLyric.isAlwaysOnTopLoop']) {
isAlwaysOnTopLoop = global.lx.appSetting['desktopLyric.isAlwaysOnTopLoop']
if (!global.lx.appSetting['desktopLyric.isAlwaysOnTop']) return
if (isAlwaysOnTopLoop) {
alwaysOnTopTools.startLoop()
} else {
alwaysOnTopTools.clearLoop()
}
}
if (keys.includes('desktopLyric.isLockScreen') && isLockScreen != global.lx.appSetting['desktopLyric.isLockScreen']) {
isLockScreen = global.lx.appSetting['desktopLyric.isLockScreen']
if (global.lx.appSetting['desktopLyric.isLockScreen']) {
setBounds(getLyricWindowBounds(getBounds(), {
x: null,
y: 0,
w: global.lx.appSetting['desktopLyric.width'],
h: global.lx.appSetting['desktopLyric.height'],
}))
}
}
}
if (keys.includes('desktopLyric.enable') && isEnable != global.lx.appSetting['desktopLyric.enable']) {
isEnable = global.lx.appSetting['desktopLyric.enable']
if (global.lx.appSetting['desktopLyric.enable']) {
createWindow()
} else {
alwaysOnTopTools.clearLoop()
closeWindow()
}
}
}
-126
View File
@@ -1,126 +0,0 @@
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 { getLyricWindowBounds } = require('./utils')
const { isLinux } = require('@common/utils')
let isLock = null
let isEnable = null
let isAlwaysOnTop = null
let isAlwaysOnTopLoop = null
let isLockScreen = null
let isHoverHide = null
const alwaysOnTopTools = {
timeout: null,
alwaysOnTop: false,
setAlwaysOnTop(flag, isLoop) {
this.alwaysOnTop = flag
this.clearLoop()
global.modules.lyricWindow.setAlwaysOnTop(flag, 'screen-saver')
console.log(isLoop)
if (flag && isLoop) this.startLoop()
},
startLoop() {
if (!this.alwaysOnTop) return
this.timeout = setInterval(() => {
if (!global.modules.lyricWindow) return this.clearLoop()
global.modules.lyricWindow.setAlwaysOnTop(true, 'screen-saver')
}, 1000)
},
clearLoop() {
if (!this.timeout) return
clearInterval(this.timeout)
this.timeout = null
},
}
const setLrcConfig = () => {
let desktopLyric = global.appSetting.desktopLyric
if (global.modules.lyricWindow) {
mainSend(global.modules.lyricWindow, ipcWinLyricNames.set_lyric_config, {
config: desktopLyric,
languageId: global.appSetting.langId,
isShowLyricTranslation: global.appSetting.player.isShowLyricTranslation,
isShowLyricRoma: global.appSetting.player.isShowLyricRoma,
isPlayLxlrc: global.appSetting.player.isPlayLxlrc,
})
if (isLock != desktopLyric.isLock) {
isLock = desktopLyric.isLock
if (desktopLyric.isLock) {
global.modules.lyricWindow.setIgnoreMouseEvents(true, { forward: !isLinux && global.appSetting.desktopLyric.isHoverHide })
} else {
global.modules.lyricWindow.setIgnoreMouseEvents(false, { forward: !isLinux && global.appSetting.desktopLyric.isHoverHide })
}
}
if (isHoverHide != desktopLyric.isHoverHide) {
isHoverHide = desktopLyric.isHoverHide
if (!isLinux) {
global.modules.lyricWindow.setIgnoreMouseEvents(desktopLyric.isLock, { forward: global.appSetting.desktopLyric.isHoverHide })
}
}
if (isAlwaysOnTop != desktopLyric.isAlwaysOnTop) {
isAlwaysOnTop = desktopLyric.isAlwaysOnTop
alwaysOnTopTools.setAlwaysOnTop(desktopLyric.isAlwaysOnTop, desktopLyric.isAlwaysOnTopLoop)
}
if (isAlwaysOnTopLoop != desktopLyric.isAlwaysOnTopLoop) {
isAlwaysOnTopLoop = desktopLyric.isAlwaysOnTopLoop
if (isAlwaysOnTopLoop) {
alwaysOnTopTools.startLoop()
} else {
alwaysOnTopTools.clearLoop()
}
}
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
if (desktopLyric.enable) {
global.lx_event.winLyric.create()
} else {
alwaysOnTopTools.clearLoop()
global.lx_event.winLyric.close()
}
}
}
global.lx_event.common.on(COMMON_EVENT_NAME.configStatus, name => {
if (WIN_LYRIC_EVENT_NAME.name === name) return
setLrcConfig()
})
global.lx_event.mainWindow.on(MAIN_WINDOW_EVENT_NAME.setLyricInfo, info => {
if (!global.modules.lyricWindow) return
mainSend(global.modules.lyricWindow, ipcWinLyricNames.set_lyric_info, info)
})
global.lx_event.hotKey.on(HOT_KEY_EVENT_NAME.keyDown, ({ type, key }) => {
let info = global.appHotKey.config.global.keys[key]
if (!info || info.type != WIN_LYRIC_EVENT_NAME.name) return
let desktopLyricSetting = JSON.parse(JSON.stringify(global.appSetting.desktopLyric))
let settingKey
switch (info.action) {
case desktop_lyric.toggle_visible.action:
settingKey = 'enable'
break
case desktop_lyric.toggle_lock.action:
settingKey = 'isLock'
break
case desktop_lyric.toggle_always_top.action:
settingKey = 'isAlwaysOnTop'
break
}
desktopLyricSetting[settingKey] = !desktopLyricSetting[settingKey]
global.lx_core.setAppConfig({ desktopLyric: desktopLyricSetting }, null)
})
-132
View File
@@ -1,132 +0,0 @@
const path = require('path')
const { BrowserWindow } = require('electron')
const { winLyric: WIN_LYRIC_EVENT_NAME } = require('../../events/_name')
const { debounce, isLinux } = require('../../../common/utils')
const { getLyricWindowBounds } = require('./utils')
require('./event')
require('./rendererEvent')
global.lx_event.winLyric.on(WIN_LYRIC_EVENT_NAME.create, () => {
createWindow()
})
global.lx_event.winLyric.on(WIN_LYRIC_EVENT_NAME.close, () => {
closeWindow()
})
let winURL = global.isDev ? 'http://localhost:9081/lyric.html' : `file://${path.join(__dirname, 'lyric.html')}`
const setLyricsConfig = debounce(config => {
// if (x != null) bounds.x = x
// if (y != null) bounds.y = y
// if (width != null) bounds.width = width
// if (height != null) bounds.height = height
global.lx_core.setAppConfig({ desktopLyric: config }, WIN_LYRIC_EVENT_NAME.name)
}, 500)
const winEvent = lyricWindow => {
// let bounds
// lyricWindow.on('close', event => {
// if (global.isQuitting || !global.appSetting.tray.isShow || (!isWin && !global.isTrafficLightClose)) {
// lyricWindow.setProgressBar(-1)
// return
// }
// if (global.isTrafficLightClose) global.isTrafficLightClose = false
// event.preventDefault()
// lyricWindow.hide()
// })
lyricWindow.on('closed', () => {
lyricWindow = global.modules.lyricWindow = null
})
lyricWindow.on('move', event => {
// bounds = lyricWindow.getBounds()
// console.log(bounds)
setLyricsConfig(lyricWindow.getBounds())
})
lyricWindow.on('resize', event => {
// bounds = lyricWindow.getBounds()
// console.log(bounds)
setLyricsConfig(lyricWindow.getBounds())
})
// lyricWindow.on('restore', () => {
// lyricWindow.webContents.send('restore')
// })
// lyricWindow.on('focus', () => {
// lyricWindow.webContents.send('focus')
// })
lyricWindow.once('ready-to-show', () => {
lyricWindow.show()
if (global.appSetting.desktopLyric.isLock) {
global.modules.lyricWindow.setIgnoreMouseEvents(true, { forward: !isLinux && global.appSetting.desktopLyric.isHoverHide })
}
// linux下每次重开时貌似要重新设置置顶
if (isLinux && global.appSetting.desktopLyric.isAlwaysOnTop) {
global.modules.lyricWindow.setAlwaysOnTop(global.appSetting.desktopLyric.isAlwaysOnTop, 'screen-saver')
}
})
}
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
if (x == null) {
x = screenWidth - width
y = screenHeight - height
}
if (global.appSetting.desktopLyric.isLockScreen) {
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,
width,
x,
y,
minWidth: 380,
minHeight: 80,
useContentSize: true,
frame: false,
transparent: true,
enableRemoteModule: false,
// icon: path.join(global.__static, isWin ? 'icons/256x256.ico' : 'icons/512x512.png'),
resizable: false,
minimizable: false,
maximizable: false,
fullscreenable: false,
show: false,
alwaysOnTop: isAlwaysOnTop,
skipTaskbar: true,
webPreferences: {
contextIsolation: false,
webSecurity: !global.isDev,
nodeIntegration: true,
spellcheck: false, // 禁用拼写检查器
},
})
global.modules.lyricWindow.loadURL(winURL)
winEvent(global.modules.lyricWindow)
// mainWindow.webContents.openDevTools()
}
const closeWindow = () => {
if (!global.modules.lyricWindow) return
global.modules.lyricWindow.close()
}
+61
View File
@@ -0,0 +1,61 @@
import { APP_EVENT_NAMES } from '@common/constants'
import initRendererEvent, { sendMainWindowInitedEvent } from './rendererEvent'
import { setLrcConfig } from './config'
import { HOTKEY_DESKTOP_LYRIC } from '@common/hotKey'
import { closeWindow, createWindow, isExistWindow } from './main'
// import main from './main'
// import { Event, EVENT_NAMES } from './event'
export default () => {
initRendererEvent()
// global.lx.event_app.winLyric = new Event()
// global.app_event.winMain.
global.lx.event_app.on('main_window_inited', () => {
if (global.lx.appSetting['desktopLyric.enable']) {
if (isExistWindow()) sendMainWindowInitedEvent()
else createWindow()
}
})
global.lx.event_app.on('updated_config', (keys, setting) => {
setLrcConfig(keys, setting)
})
global.lx.event_app.on('main_window_close', () => {
closeWindow()
})
// global.lx_event.mainWindow.on(MAIN_WINDOW_EVENT_NAME.setLyricInfo, info => {
// if (!global.modules.lyricWindow) return
// mainSend(global.modules.lyricWindow, ipcWinLyricNames.set_lyric_info, info)
// })
global.lx.event_app.on('hot_key_down', ({ type, key }) => {
let info = global.lx.hotKey.config.global.keys[key]
if (!info || info.type != APP_EVENT_NAMES.winLyricName) return
let newSetting: Partial<LX.AppSetting> = {}
let settingKey: keyof LX.AppSetting
switch (info.action) {
case HOTKEY_DESKTOP_LYRIC.toggle_visible.action:
settingKey = 'desktopLyric.enable'
break
case HOTKEY_DESKTOP_LYRIC.toggle_lock.action:
settingKey = 'desktopLyric.isLock'
break
case HOTKEY_DESKTOP_LYRIC.toggle_always_top.action:
settingKey = 'desktopLyric.isAlwaysOnTop'
break
default: return
}
newSetting[settingKey] = !global.lx.appSetting[settingKey]
global.lx.event_app.update_config(newSetting)
})
}
export * from './main'
export * from './rendererEvent'
// export {
// EVENT_NAMES,
// }
+208
View File
@@ -0,0 +1,208 @@
import { join } from 'path'
import { BrowserWindow } from 'electron'
import { debounce, encodePath, isLinux, isWin } from '@common/utils'
import { getLyricWindowBounds } from './utils'
import { mainSend } from '@common/mainIpc'
// require('./event')
// require('./rendererEvent')
let browserWindow: Electron.BrowserWindow | null = null
const setLyricsConfig = debounce((config: Partial<LX.AppSetting>) => {
global.lx.event_app.update_config(config)
}, 500)
const winEvent = () => {
if (!browserWindow) return
// let bounds
// lyricWindow.on('close', event => {
// if (global.isQuitting || !global.appSetting.tray.enable || (!isWin && !global.isTrafficLightClose)) {
// lyricWindow.setProgressBar(-1)
// return
// }
// if (global.isTrafficLightClose) global.isTrafficLightClose = false
// event.preventDefault()
// lyricWindow.hide()
// })
browserWindow.on('closed', () => {
browserWindow = null
})
browserWindow.on('move', () => {
// bounds = browserWindow.getBounds()
// console.log(bounds)
const bounds = browserWindow!.getBounds()
setLyricsConfig({
'desktopLyric.x': bounds.x,
'desktopLyric.y': bounds.y,
'desktopLyric.width': bounds.width,
'desktopLyric.height': bounds.height,
})
})
browserWindow.on('resize', () => {
// bounds = browserWindow.getBounds()
// console.log(bounds)
const bounds = browserWindow!.getBounds()
setLyricsConfig({
'desktopLyric.x': bounds.x,
'desktopLyric.y': bounds.y,
'desktopLyric.width': bounds.width,
'desktopLyric.height': bounds.height,
})
})
// browserWindow.on('restore', () => {
// browserWindow.webContents.send('restore')
// })
// browserWindow.on('focus', () => {
// browserWindow.webContents.send('focus')
// })
browserWindow.once('ready-to-show', () => {
showWindow()
if (global.lx.appSetting['desktopLyric.isLock']) {
browserWindow!.setIgnoreMouseEvents(true, { forward: !isLinux && global.lx.appSetting['desktopLyric.isHoverHide'] })
}
// linux下每次重开时貌似要重新设置置顶
if (isLinux && global.lx.appSetting['desktopLyric.isAlwaysOnTop']) {
browserWindow!.setAlwaysOnTop(global.lx.appSetting['desktopLyric.isAlwaysOnTop'], 'screen-saver')
}
if (global.lx.appSetting['desktopLyric.isAlwaysOnTop'] && global.lx.appSetting['desktopLyric.isAlwaysOnTopLoop']) alwaysOnTopTools.startLoop()
})
}
export const createWindow = () => {
closeWindow()
if (!global.envParams.workAreaSize) return
let x = global.lx.appSetting['desktopLyric.x']
let y = global.lx.appSetting['desktopLyric.y']
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 { width: screenWidth, height: screenHeight } = global.envParams.workAreaSize
if (x == null || y == null) {
x = screenWidth - width
y = screenHeight - height
}
if (isLockScreen) {
let bounds = getLyricWindowBounds({ x, y, width, height }, { x: null, y: 0, w: width, h: height })
x = bounds.x
y = bounds.y
width = bounds.width
height = bounds.height
}
const { shouldUseDarkColors, theme } = global.lx.theme
/**
* Initial window options
*/
browserWindow = new BrowserWindow({
height,
width,
x,
y,
minWidth: 380,
minHeight: 80,
useContentSize: true,
frame: false,
transparent: true,
// enableRemoteModule: false,
// icon: join(global.__static, isWin ? 'icons/256x256.ico' : 'icons/512x512.png'),
resizable: false,
minimizable: false,
maximizable: false,
fullscreenable: false,
show: false,
alwaysOnTop: isAlwaysOnTop,
skipTaskbar: true,
webPreferences: {
contextIsolation: false,
webSecurity: !global.isDev,
nodeIntegration: true,
spellcheck: false, // 禁用拼写检查器
},
})
const winURL = global.isDev ? 'http://localhost:9081/lyric.html' : `file://${join(encodePath(isWin ? __dirname.replaceAll('\\', '/') : __dirname), 'lyric.html')}`
void browserWindow.loadURL(winURL + `?dark=${shouldUseDarkColors}&theme=${encodeURIComponent(JSON.stringify(theme))}`)
winEvent()
// browserWindow.webContents.openDevTools()
}
export const isExistWindow = (): boolean => !!browserWindow
export const closeWindow = () => {
if (!browserWindow) return
browserWindow.close()
}
export const showWindow = () => {
if (!browserWindow) return
browserWindow.show()
}
export const sendEvent = <T = any>(name: string, params?: T) => {
if (!browserWindow) return
mainSend(browserWindow, name, params)
}
export const getBounds = (): Electron.Rectangle => {
if (!browserWindow) throw new Error('window is not available')
return browserWindow.getBounds()
}
export const setBounds = (bounds: Electron.Rectangle) => {
if (!browserWindow) return
browserWindow.setBounds(bounds)
}
export const setIgnoreMouseEvents = (ignore: boolean, options?: Electron.IgnoreMouseEventsOptions) => {
if (!browserWindow) return
browserWindow.setIgnoreMouseEvents(ignore, options)
}
export const setAlwaysOnTop = (flag: boolean, level?: 'normal' | 'floating' | 'torn-off-menu' | 'modal-panel' | 'main-menu' | 'status' | 'pop-up-menu' | 'screen-saver' | undefined, relativeLevel?: number | undefined) => {
if (!browserWindow) return
browserWindow.setAlwaysOnTop(flag, level, relativeLevel)
}
export const getMainFrame = (): Electron.WebFrameMain | null => {
if (!browserWindow) return null
return browserWindow.webContents.mainFrame
}
interface AlwaysOnTopTools {
timeout: NodeJS.Timeout | null
setAlwaysOnTop: (isLoop: boolean) => void
startLoop: () => void
clearLoop: () => void
}
export const alwaysOnTopTools: AlwaysOnTopTools = {
timeout: null,
setAlwaysOnTop(isLoop) {
this.clearLoop()
setAlwaysOnTop(global.lx.appSetting['desktopLyric.isAlwaysOnTop'], 'screen-saver')
// console.log(isLoop)
if (isLoop) this.startLoop()
},
startLoop() {
this.clearLoop()
this.timeout = setInterval(() => {
if (!isExistWindow()) return this.clearLoop()
setAlwaysOnTop(true, 'screen-saver')
}, 1000)
},
clearLoop() {
if (!this.timeout) return
clearInterval(this.timeout)
this.timeout = null
},
}
@@ -1,38 +0,0 @@
const {
mainOn,
mainHandle,
mainSend,
NAMES: {
mainWindow: ipcMainWindowNames,
winLyric: ipcWinLyricNames,
},
} = require('../../../common/ipc')
const { winLyric: WIN_LYRIC_EVENT_NAME } = require('../../events/_name')
const { getLyricWindowBounds } = require('./utils')
mainOn(ipcWinLyricNames.get_lyric_info, (event, action) => {
if (!global.modules.mainWindow) return
mainSend(global.modules.mainWindow, ipcMainWindowNames.get_lyric_info, {
name: ipcWinLyricNames.set_lyric_info,
modal: 'lyricWindow',
action,
})
})
mainOn(ipcWinLyricNames.set_lyric_config, (event, config) => {
global.lx_core.setAppConfig({ desktopLyric: config }, WIN_LYRIC_EVENT_NAME.name)
})
mainHandle(ipcWinLyricNames.get_lyric_config, async() => {
return {
config: global.appSetting.desktopLyric,
languageId: global.appSetting.langId,
isShowLyricTranslation: global.appSetting.player.isShowLyricTranslation,
isShowLyricRoma: global.appSetting.player.isShowLyricRoma,
isPlayLxlrc: global.appSetting.player.isPlayLxlrc,
}
})
mainOn(ipcWinLyricNames.set_win_bounds, (event, options) => {
global.modules.lyricWindow.setBounds(getLyricWindowBounds(global.modules.lyricWindow.getBounds(), options))
})
@@ -0,0 +1,53 @@
import { registerRendererEvents as common } from '@main/modules/commonRenderers/common'
import { mainOn, mainHandle } from '@common/mainIpc'
import { WIN_LYRIC_RENDERER_EVENT_NAME } from '@common/ipcNames'
import { buildLyricConfig, getLyricWindowBounds } from './utils'
import { sendNewDesktopLyricClient } from '@main/modules/winMain'
import { getBounds, getMainFrame, sendEvent, setBounds } from './main'
import { MessageChannelMain } from 'electron'
export default () => {
// mainOn(WIN_LYRIC_RENDERER_EVENT_NAME.get_lyric_info, ({ params: action }) => {
// sendMainEvent(WIN_MAIN_RENDERER_EVENT_NAME.get_lyric_info, {
// name: WIN_LYRIC_RENDERER_EVENT_NAME.set_lyric_info,
// modal: 'lyricWindow',
// action,
// })
// })
common(sendEvent)
mainHandle<Partial<LX.AppSetting>>(WIN_LYRIC_RENDERER_EVENT_NAME.set_config, async({ params: config }) => {
global.lx.event_app.update_config(config)
})
mainHandle<LX.DesktopLyric.Config>(WIN_LYRIC_RENDERER_EVENT_NAME.get_config, async() => {
return buildLyricConfig(global.lx.appSetting) as LX.DesktopLyric.Config
})
mainOn<LX.DesktopLyric.NewBounds>(WIN_LYRIC_RENDERER_EVENT_NAME.set_win_bounds, ({ params: options }) => {
setBounds(getLyricWindowBounds(getBounds(), options))
})
mainOn(WIN_LYRIC_RENDERER_EVENT_NAME.request_main_window_channel, ({ event }) => {
if (event.senderFrame !== getMainFrame()) return
// Create a new channel ...
const { port1, port2 } = new MessageChannelMain()
// ... send one end to the worker ...
sendNewDesktopLyricClient(port1)
// ... and the other end to the main window.
event.senderFrame.postMessage(WIN_LYRIC_RENDERER_EVENT_NAME.provide_main_window_channel, null, [port2])
// Now the main window and the worker can communicate with each other
// without going through the main process!
console.log('request_main_window_channel')
})
}
export const sendConfigChange = (setting: Partial<LX.DesktopLyric.Config>) => {
sendEvent(WIN_LYRIC_RENDERER_EVENT_NAME.on_config_change, setting)
}
export const sendMainWindowInitedEvent = () => {
sendEvent(WIN_LYRIC_RENDERER_EVENT_NAME.main_window_inited)
}
-68
View File
@@ -1,68 +0,0 @@
// 设置窗口位置、大小
let winX
let winY
let wasW
let wasH
let offset = 8
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 (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 (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
bounds.x = x
bounds.y = y
// console.log('util bounds', bounds)
return bounds
}
+115
View File
@@ -0,0 +1,115 @@
// 设置窗口位置、大小
let winX
let winY
let wasW
let wasH
let offset = 8
let minWidth = 80
let minHeight = 50
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
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 (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 {
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
}
export const watchConfigKeys = [
'desktopLyric.enable',
'desktopLyric.isLock',
'desktopLyric.isAlwaysOnTop',
'desktopLyric.isAlwaysOnTopLoop',
'desktopLyric.audioVisualization',
'desktopLyric.width',
'desktopLyric.height',
'desktopLyric.x',
'desktopLyric.y',
'desktopLyric.isLockScreen',
'desktopLyric.isDelayScroll',
'desktopLyric.isHoverHide',
'desktopLyric.direction',
'desktopLyric.style.align',
'desktopLyric.style.lyricUnplayColor',
'desktopLyric.style.lyricPlayedColor',
'desktopLyric.style.lyricShadowColor',
'desktopLyric.style.font',
'desktopLyric.style.fontSize',
// 'desktopLyric.style.fontWeight',
'desktopLyric.style.opacity',
'desktopLyric.style.ellipsis',
'desktopLyric.style.isZoomActiveLrc',
'common.langId',
'player.isShowLyricTranslation',
'player.isShowLyricRoma',
'player.isPlayLxlrc',
] as const
export const buildLyricConfig = (appSetting: Partial<LX.AppSetting>): Partial<LX.DesktopLyric.Config> => {
const setting: Partial<LX.DesktopLyric.Config> = {}
for (const key of watchConfigKeys) {
// @ts-expect-error
if (key in appSetting) setting[key] = appSetting[key]
}
return setting
}