新增桌面歌词
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
const { common: COMMON_EVENT_NAME, winLyric: WIN_LYRIC_EVENT_NAME, mainWindow: MAIN_WINDOW_EVENT_NAME } = require('../../events/_name')
|
||||
const { mainSend, NAMES: { winLyric: ipcWinLyricNames } } = require('../../../common/ipc')
|
||||
|
||||
let isLock = null
|
||||
let isEnable = null
|
||||
let isAlwaysOnTop = null
|
||||
const setLrcConfig = isForceSet => {
|
||||
let desktopLyric = global.appSetting.desktopLyric
|
||||
if (isEnable != desktopLyric.enable) {
|
||||
isEnable = desktopLyric.enable
|
||||
if (desktopLyric.enable) {
|
||||
global.lx_event.winLyric.create()
|
||||
} else {
|
||||
global.lx_event.winLyric.close()
|
||||
}
|
||||
}
|
||||
if (global.modals.lyricWindow) {
|
||||
mainSend(global.modals.lyricWindow, ipcWinLyricNames.set_lyric_config, desktopLyric)
|
||||
if (isForceSet || isLock != desktopLyric.isLock) {
|
||||
isLock = desktopLyric.isLock
|
||||
if (desktopLyric.isLock) {
|
||||
global.modals.lyricWindow.setIgnoreMouseEvents(true, { forward: false })
|
||||
} else {
|
||||
global.modals.lyricWindow.setIgnoreMouseEvents(false)
|
||||
}
|
||||
}
|
||||
if (isForceSet || isAlwaysOnTop != desktopLyric.isAlwaysOnTop) {
|
||||
isAlwaysOnTop = desktopLyric.isAlwaysOnTop
|
||||
global.modals.lyricWindow.setAlwaysOnTop(desktopLyric.isAlwaysOnTop, 'screen-saver')
|
||||
}
|
||||
}
|
||||
}
|
||||
global.lx_event.common.on(COMMON_EVENT_NAME.config, name => {
|
||||
if (WIN_LYRIC_EVENT_NAME.name === name) return
|
||||
setLrcConfig(false)
|
||||
})
|
||||
global.lx_event.winLyric.on(WIN_LYRIC_EVENT_NAME.inited, () => setLrcConfig(true))
|
||||
|
||||
global.lx_event.mainWindow.on(MAIN_WINDOW_EVENT_NAME.setLyricInfo, info => {
|
||||
if (!global.modals.lyricWindow) return
|
||||
mainSend(global.modals.lyricWindow, ipcWinLyricNames.set_lyric_info, info)
|
||||
})
|
||||
@@ -0,0 +1,122 @@
|
||||
const { BrowserWindow } = require('electron')
|
||||
const { winLyric: WIN_LYRIC_EVENT_NAME } = require('../../events/_name')
|
||||
const { debounce } = require('../../../common/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://${__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_event.common.setAppConfig({ desktopLyric: config }, WIN_LYRIC_EVENT_NAME.name)
|
||||
}, 500)
|
||||
|
||||
const winEvent = lyricWindow => {
|
||||
// let bounds
|
||||
// lyricWindow.on('close', event => {
|
||||
// if (global.isQuitting || !global.appSetting.tray.isToTray || (!isWin && !global.isTrafficLightClose)) {
|
||||
// lyricWindow.setProgressBar(-1)
|
||||
// return
|
||||
// }
|
||||
|
||||
// if (global.isTrafficLightClose) global.isTrafficLightClose = false
|
||||
// event.preventDefault()
|
||||
// lyricWindow.hide()
|
||||
// })
|
||||
|
||||
lyricWindow.on('closed', () => {
|
||||
lyricWindow = global.modals.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()
|
||||
let config = global.appSetting.desktopLyric
|
||||
global.modals.lyricWindow.setBounds({
|
||||
height: config.height,
|
||||
width: config.width,
|
||||
y: config.y,
|
||||
x: config.x,
|
||||
})
|
||||
global.lx_event.winLyric.inited()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
const createWindow = () => {
|
||||
if (global.modals.lyricWindow) return
|
||||
if (!global.appSetting.desktopLyric.enable) return
|
||||
// const windowSizeInfo = getWindowSizeInfo(global.appSetting)
|
||||
const { x, y, width, height, isAlwaysOnTop } = global.appSetting.desktopLyric
|
||||
let { width: screenWidth, height: screenHeight } = global.envParams.workAreaSize
|
||||
screenWidth += 16
|
||||
screenHeight += 16
|
||||
/**
|
||||
* Initial window options
|
||||
*/
|
||||
global.modals.lyricWindow = new BrowserWindow({
|
||||
height: height > screenHeight ? screenHeight : height,
|
||||
width: width > screenWidth ? screenWidth : width,
|
||||
x: Math.max(-8, screenWidth < (width + x) ? screenWidth - width : x),
|
||||
y: Math.max(-8, screenHeight < (height + y) ? screenHeight - height : y),
|
||||
minWidth: 300,
|
||||
minHeight: 300,
|
||||
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: true,
|
||||
webSecurity: !global.isDev,
|
||||
nodeIntegration: true,
|
||||
},
|
||||
})
|
||||
|
||||
global.modals.lyricWindow.loadURL(winURL)
|
||||
|
||||
winEvent(global.modals.lyricWindow)
|
||||
// mainWindow.webContents.openDevTools()
|
||||
}
|
||||
|
||||
const closeWindow = () => {
|
||||
if (!global.modals.lyricWindow) return
|
||||
global.modals.lyricWindow.close()
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
const {
|
||||
mainOn,
|
||||
mainHandle,
|
||||
mainSend,
|
||||
NAMES: {
|
||||
mainWindow: ipcMainWindowNames,
|
||||
winLyric: ipcWinLyricNames,
|
||||
},
|
||||
} = require('../../../common/ipc')
|
||||
const { winLyric: WIN_LYRIC_EVENT_NAME } = require('../../events/_name')
|
||||
|
||||
mainOn(ipcWinLyricNames.get_lyric_info, (event, action) => {
|
||||
if (!global.modals.mainWindow) return
|
||||
mainSend(global.modals.mainWindow, ipcMainWindowNames.get_lyric_info, {
|
||||
name: ipcWinLyricNames.set_lyric_info,
|
||||
modal: 'lyricWindow',
|
||||
action,
|
||||
})
|
||||
})
|
||||
|
||||
mainOn(ipcWinLyricNames.set_lyric_config, (event, config) => {
|
||||
global.lx_event.common.setAppConfig({ desktopLyric: config }, WIN_LYRIC_EVENT_NAME.name)
|
||||
})
|
||||
|
||||
mainHandle(ipcWinLyricNames.get_lyric_config, async() => {
|
||||
return global.appSetting.desktopLyric
|
||||
})
|
||||
|
||||
let bounds
|
||||
let winX
|
||||
let winY
|
||||
let wasW
|
||||
let wasY
|
||||
mainOn(ipcWinLyricNames.set_win_bounds, (event, { x = 0, y = 0, w = 0, h = 0 }) => {
|
||||
if (!global.modals.lyricWindow) return
|
||||
bounds = global.modals.lyricWindow.getBounds()
|
||||
wasW = global.envParams.workAreaSize.width
|
||||
wasY = global.envParams.workAreaSize.height + 8
|
||||
|
||||
bounds.width = w + bounds.width
|
||||
bounds.height = h + bounds.height
|
||||
if (bounds.width > wasW - 8) {
|
||||
bounds.width = wasW - 8
|
||||
} else if (bounds.width < 300) {
|
||||
bounds.width = 300
|
||||
}
|
||||
if (bounds.height > wasY) {
|
||||
bounds.height = wasY + 8
|
||||
} else if (bounds.height < 120) {
|
||||
bounds.height = 120
|
||||
}
|
||||
|
||||
|
||||
if (x != 0) {
|
||||
winX = bounds.x + x
|
||||
if (winX > wasW - bounds.width + 8) {
|
||||
winX = wasW - bounds.width + 8
|
||||
} else if (winX < -8) {
|
||||
winX = -8
|
||||
}
|
||||
bounds.x = winX
|
||||
}
|
||||
if (y != 0) {
|
||||
winY = bounds.y + y
|
||||
if (winY > wasY - bounds.height) {
|
||||
winY = wasY - bounds.height
|
||||
} else if (winY < -8) {
|
||||
winY = -8
|
||||
}
|
||||
bounds.y = winY
|
||||
}
|
||||
|
||||
// console.log(bounds)
|
||||
global.modals.lyricWindow.setBounds(bounds)
|
||||
})
|
||||
Reference in New Issue
Block a user