新增快捷键设置
This commit is contained in:
+21
-2
@@ -1,9 +1,28 @@
|
||||
const { common: COMMON_EVENT_NAME, mainWindow: MAIN_WINDOW_EVENT_NAME } = require('./events/_name')
|
||||
const { mainSend, NAMES: { mainWindow: ipcMainWindowNames } } = require('./../common/ipc')
|
||||
|
||||
const { getAppHotKeyConfig } = require('./utils')
|
||||
|
||||
global.lx_event.common.on(COMMON_EVENT_NAME.config, name => {
|
||||
if (MAIN_WINDOW_EVENT_NAME.name === name) return
|
||||
if (global.modals.mainWindow) mainSend(global.modals.mainWindow, ipcMainWindowNames.set_config, global.appSetting)
|
||||
if (global.modules.mainWindow) mainSend(global.modules.mainWindow, ipcMainWindowNames.set_config, global.appSetting)
|
||||
})
|
||||
|
||||
global.lx_event.common.on(COMMON_EVENT_NAME.initHotKey, () => {
|
||||
global.appHotKey.config = getAppHotKeyConfig()
|
||||
})
|
||||
|
||||
global.lx_event.mainWindow.on(MAIN_WINDOW_EVENT_NAME.quit, () => {
|
||||
global.isTrafficLightClose = false
|
||||
global.isQuitting = true
|
||||
global.modules.mainWindow.close()
|
||||
})
|
||||
global.lx_event.mainWindow.on(MAIN_WINDOW_EVENT_NAME.toggle_minimize, () => {
|
||||
global.modules.mainWindow.isMinimized()
|
||||
? global.modules.mainWindow.restore()
|
||||
: global.modules.mainWindow.minimize()
|
||||
})
|
||||
global.lx_event.mainWindow.on(MAIN_WINDOW_EVENT_NAME.toggle_hide, () => {
|
||||
global.modules.mainWindow.isVisible()
|
||||
? global.modules.mainWindow.hide()
|
||||
: global.modules.mainWindow.show()
|
||||
})
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
const { EventEmitter } = require('events')
|
||||
const { hotKey: HOT_KEY_EVENT_NAME } = require('./_name')
|
||||
const { saveAppHotKeyConfig } = require('../utils')
|
||||
|
||||
class HotKey extends EventEmitter {
|
||||
init() {
|
||||
this.emit(HOT_KEY_EVENT_NAME.init)
|
||||
}
|
||||
|
||||
saveConfig(config, source) {
|
||||
if (config) saveAppHotKeyConfig(config)
|
||||
this.emit(HOT_KEY_EVENT_NAME.config, config, source)
|
||||
}
|
||||
|
||||
keyDown(info) {
|
||||
this.emit(HOT_KEY_EVENT_NAME.keyDown, info)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = HotKey
|
||||
|
||||
@@ -5,6 +5,18 @@ class MainWindow extends EventEmitter {
|
||||
setLyricInfo(info) {
|
||||
this.emit(MAIN_WINDOW_EVENT_NAME.setLyricInfo, info)
|
||||
}
|
||||
|
||||
quit() {
|
||||
this.emit(MAIN_WINDOW_EVENT_NAME.quit)
|
||||
}
|
||||
|
||||
toggleMinimize() {
|
||||
this.emit(MAIN_WINDOW_EVENT_NAME.toggle_minimize)
|
||||
}
|
||||
|
||||
toggleHide() {
|
||||
this.emit(MAIN_WINDOW_EVENT_NAME.toggle_hide)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MainWindow
|
||||
|
||||
@@ -7,6 +7,9 @@ exports.mainWindow = {
|
||||
name: 'mainWindow',
|
||||
setLyricInfo: 'setLyricInfo',
|
||||
destroy: 'destroy',
|
||||
quit: 'quit',
|
||||
toggle_minimize: 'toggle_minimize',
|
||||
toggle_hide: 'toggle_hide',
|
||||
}
|
||||
|
||||
exports.tray = {
|
||||
@@ -21,3 +24,10 @@ exports.winLyric = {
|
||||
close: 'close',
|
||||
inited: 'inited',
|
||||
}
|
||||
|
||||
exports.hotKey = {
|
||||
name: 'hotKey',
|
||||
init: 'init',
|
||||
config: 'config',
|
||||
keyDown: 'keyDown',
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ const Common = require('./Common')
|
||||
const MainWindow = require('./MainWindow')
|
||||
const Tray = require('./Tray')
|
||||
const WinLyric = require('./WinLyric')
|
||||
const HotKey = require('./HotKey')
|
||||
|
||||
if (!global.lx_event.common) global.lx_event.common = new Common()
|
||||
if (!global.lx_event.mainWindow) global.lx_event.mainWindow = new MainWindow()
|
||||
if (!global.lx_event.tray) global.lx_event.tray = new Tray()
|
||||
if (!global.lx_event.winLyric) global.lx_event.winLyric = new WinLyric()
|
||||
if (!global.lx_event.hotKey) global.lx_event.hotKey = new HotKey()
|
||||
|
||||
+20
-12
@@ -6,7 +6,7 @@ if (!app.requestSingleInstanceLock()) {
|
||||
app.quit()
|
||||
return
|
||||
}
|
||||
if (!global.modals) global.modals = {}
|
||||
if (!global.modules) global.modules = {}
|
||||
app.on('second-instance', (event, argv, cwd) => {
|
||||
if (global.modules.mainWindow) {
|
||||
if (global.modules.mainWindow.isMinimized()) {
|
||||
@@ -26,7 +26,7 @@ const isDev = global.isDev = process.env.NODE_ENV !== 'production'
|
||||
require('./env')
|
||||
const { navigationUrlWhiteList } = require('../common/config')
|
||||
const { getWindowSizeInfo } = require('./utils')
|
||||
const { isMac, isLinux, initSetting } = require('../common/utils')
|
||||
const { isMac, isLinux, initSetting, initHotKey } = require('../common/utils')
|
||||
|
||||
|
||||
// https://github.com/electron/electron/issues/22691
|
||||
@@ -90,7 +90,7 @@ function createWindow() {
|
||||
/**
|
||||
* Initial window options
|
||||
*/
|
||||
global.modals.mainWindow = new BrowserWindow({
|
||||
global.modules.mainWindow = new BrowserWindow({
|
||||
height: windowSizeInfo.height,
|
||||
useContentSize: true,
|
||||
width: windowSizeInfo.width,
|
||||
@@ -109,32 +109,40 @@ function createWindow() {
|
||||
},
|
||||
})
|
||||
|
||||
global.modals.mainWindow.loadURL(winURL)
|
||||
global.modules.mainWindow.loadURL(winURL)
|
||||
|
||||
winEvent(global.modals.mainWindow)
|
||||
winEvent(global.modules.mainWindow)
|
||||
// mainWindow.webContents.openDevTools()
|
||||
|
||||
if (!isDev) autoUpdate()
|
||||
}
|
||||
|
||||
global.appHotKey = {
|
||||
enable: true,
|
||||
config: {},
|
||||
state: null,
|
||||
}
|
||||
|
||||
function init() {
|
||||
global.appSetting = initSetting()
|
||||
global.appHotKey.config = initHotKey()
|
||||
global.lx_event.common.initSetting()
|
||||
global.lx_event.hotKey.init()
|
||||
createWindow()
|
||||
}
|
||||
|
||||
app.on('ready', init)
|
||||
|
||||
app.on('activate', () => {
|
||||
if (global.modals.mainWindow) {
|
||||
if (global.modals.mainWindow.isMinimized()) {
|
||||
global.modals.mainWindow.restore()
|
||||
} else if (global.modals.mainWindow.isVisible()) {
|
||||
global.modals.mainWindow.focus()
|
||||
if (global.modules.mainWindow) {
|
||||
if (global.modules.mainWindow.isMinimized()) {
|
||||
global.modules.mainWindow.restore()
|
||||
} else if (global.modules.mainWindow.isVisible()) {
|
||||
global.modules.mainWindow.focus()
|
||||
} else {
|
||||
global.modals.mainWindow.show()
|
||||
global.modules.mainWindow.show()
|
||||
}
|
||||
} else if (global.modals.mainWindow === null) {
|
||||
} else if (global.modules.mainWindow === null) {
|
||||
init()
|
||||
}
|
||||
})
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
const { app } = require('electron')
|
||||
const { init, unRegisterHotkeyAll } = require('./utils')
|
||||
const { hotKey: HOT_KEY_EVENT_NAME } = require('../../events/_name')
|
||||
|
||||
global.appHotKey.state = {}
|
||||
|
||||
app.on('will-quit', unRegisterHotkeyAll)
|
||||
|
||||
global.lx_event.hotKey.on(HOT_KEY_EVENT_NAME.init, init)
|
||||
|
||||
|
||||
require('./rendererEvent')
|
||||
@@ -0,0 +1,28 @@
|
||||
const {
|
||||
mainHandle,
|
||||
NAMES: {
|
||||
hotKey: ipcHotKeyNames,
|
||||
},
|
||||
} = require('../../../common/ipc')
|
||||
const { init, registerHotkey, unRegisterHotkey, unRegisterHotkeyAll } = require('./utils')
|
||||
|
||||
mainHandle(ipcHotKeyNames.set_config, async(event, { action, data, source }) => {
|
||||
switch (action) {
|
||||
case 'config':
|
||||
global.lx_event.hotKey.saveConfig(data, source)
|
||||
return true
|
||||
case 'enable':
|
||||
data ? init(true) : unRegisterHotkeyAll()
|
||||
return true
|
||||
case 'register':
|
||||
return registerHotkey(data)
|
||||
case 'unregister':
|
||||
return unRegisterHotkey(data)
|
||||
}
|
||||
})
|
||||
|
||||
mainHandle(ipcHotKeyNames.status, async() => global.appHotKey.state)
|
||||
|
||||
mainHandle(ipcHotKeyNames.enable, async(event, flag) => {
|
||||
flag ? init() : unRegisterHotkeyAll()
|
||||
})
|
||||
@@ -0,0 +1,61 @@
|
||||
const { globalShortcut } = require('electron')
|
||||
const { log } = require('../../../common/utils')
|
||||
|
||||
const handleKeyDown = key => {
|
||||
if (!global.appHotKey.enable) return
|
||||
global.lx_event.hotKey.keyDown({ type: 'global', key })
|
||||
}
|
||||
|
||||
const transformedKeyRxp = /(^|\+)[a-z]/g
|
||||
|
||||
const transformedKey = key => {
|
||||
if (key.includes('arrow')) key = key.replace(/arrow/g, '')
|
||||
return key.replace('mod', 'CommandOrControl').replace(transformedKeyRxp, l => l.toUpperCase())
|
||||
}
|
||||
exports.registerHotkey = ({ key, info }) => {
|
||||
if (global.appHotKey.state[key] && global.appHotKey.state[key].status) return true
|
||||
let transKey = transformedKey(key)
|
||||
// console.log('Register key:', transKey)
|
||||
if (!global.appHotKey.state[key]) {
|
||||
global.appHotKey.state[key] = {
|
||||
status: false,
|
||||
info: null,
|
||||
}
|
||||
}
|
||||
global.appHotKey.state[key].info = info
|
||||
let status = global.appHotKey.state[key].status = globalShortcut.isRegistered(transKey) ? false : globalShortcut.register(transKey, () => {
|
||||
handleKeyDown(key)
|
||||
})
|
||||
return status
|
||||
}
|
||||
|
||||
exports.unRegisterHotkey = key => {
|
||||
let transKey = transformedKey(key)
|
||||
// console.log('Unregister key:', transKey)
|
||||
globalShortcut.unregister(transKey)
|
||||
delete global.appHotKey.state[key]
|
||||
}
|
||||
|
||||
exports.unRegisterHotkeyAll = () => {
|
||||
global.appHotKey.state = {}
|
||||
globalShortcut.unregisterAll()
|
||||
}
|
||||
|
||||
exports.handleKeyDown = handleKeyDown
|
||||
exports.transformedKey = transformedKey
|
||||
|
||||
const handleRegisterHotkey = data => {
|
||||
let ret = exports.registerHotkey(data)
|
||||
if (!ret) log.info('Register hot key failed:', data.key)
|
||||
}
|
||||
|
||||
|
||||
exports.init = (isForce = false) => {
|
||||
exports.unRegisterHotkeyAll()
|
||||
if (!isForce && !global.appHotKey.config.global.enable) return
|
||||
global.appHotKey.state = {}
|
||||
// console.log(global.appHotKey.config.global.keys)
|
||||
for (const key of Object.keys(global.appHotKey.config.global.keys)) {
|
||||
handleRegisterHotkey({ key, info: global.appHotKey.config.global.keys[key] })
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
require('./appMenu')
|
||||
require('./winLyric')
|
||||
require('./tray')
|
||||
require('./hotKey')
|
||||
|
||||
+12
-12
@@ -9,22 +9,22 @@ global.lx_event.common.on(COMMON_EVENT_NAME.config, sourceName => {
|
||||
isEnableTray = global.appSetting.tray.isToTray
|
||||
global.appSetting.tray.isToTray ? createTray() : destroyTray()
|
||||
}
|
||||
createMenu(global.modals.tray)
|
||||
createMenu(global.modules.tray)
|
||||
})
|
||||
|
||||
const createTray = () => {
|
||||
if ((global.modals.tray && !global.modals.tray.isDestroyed()) || !global.appSetting.tray || !global.appSetting.tray.isShow) return
|
||||
if ((global.modules.tray && !global.modules.tray.isDestroyed()) || !global.appSetting.tray || !global.appSetting.tray.isShow) return
|
||||
|
||||
const iconPath = path.join(global.__static, 'images/tray', isWin ? 'trayTemplate@2x.ico' : 'trayTemplate.png')
|
||||
|
||||
// 托盘
|
||||
global.modals.tray = new Tray(iconPath)
|
||||
global.modules.tray = new Tray(iconPath)
|
||||
|
||||
global.modals.tray.setToolTip('洛雪音乐助手')
|
||||
createMenu(global.modals.tray)
|
||||
global.modals.tray.setIgnoreDoubleClickEvents(true)
|
||||
global.modals.tray.on('click', () => {
|
||||
const mainWindow = global.modals.mainWindow
|
||||
global.modules.tray.setToolTip('洛雪音乐助手')
|
||||
createMenu(global.modules.tray)
|
||||
global.modules.tray.setIgnoreDoubleClickEvents(true)
|
||||
global.modules.tray.on('click', () => {
|
||||
const mainWindow = global.modules.mainWindow
|
||||
if (!mainWindow) return
|
||||
mainWindow.isVisible()
|
||||
? mainWindow.focus()
|
||||
@@ -33,13 +33,13 @@ const createTray = () => {
|
||||
}
|
||||
|
||||
const destroyTray = () => {
|
||||
if (!global.modals.tray) return
|
||||
global.modals.tray.destroy()
|
||||
global.modals.tray = null
|
||||
if (!global.modules.tray) return
|
||||
global.modules.tray.destroy()
|
||||
global.modules.tray = null
|
||||
}
|
||||
|
||||
const createMenu = tray => {
|
||||
if (!global.modals.tray || !isWin) return
|
||||
if (!global.modules.tray || !isWin) return
|
||||
let menu = []
|
||||
menu.push(global.appSetting.desktopLyric.enable ? {
|
||||
label: '关闭桌面歌词',
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const { common: COMMON_EVENT_NAME, winLyric: WIN_LYRIC_EVENT_NAME, mainWindow: MAIN_WINDOW_EVENT_NAME } = require('../../events/_name')
|
||||
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')
|
||||
|
||||
let isLock = null
|
||||
let isEnable = null
|
||||
@@ -14,19 +15,19 @@ const setLrcConfig = isForceSet => {
|
||||
global.lx_event.winLyric.close()
|
||||
}
|
||||
}
|
||||
if (global.modals.lyricWindow) {
|
||||
mainSend(global.modals.lyricWindow, ipcWinLyricNames.set_lyric_config, desktopLyric)
|
||||
if (global.modules.lyricWindow) {
|
||||
mainSend(global.modules.lyricWindow, ipcWinLyricNames.set_lyric_config, desktopLyric)
|
||||
if (isForceSet || isLock != desktopLyric.isLock) {
|
||||
isLock = desktopLyric.isLock
|
||||
if (desktopLyric.isLock) {
|
||||
global.modals.lyricWindow.setIgnoreMouseEvents(true, { forward: false })
|
||||
global.modules.lyricWindow.setIgnoreMouseEvents(true, { forward: false })
|
||||
} else {
|
||||
global.modals.lyricWindow.setIgnoreMouseEvents(false)
|
||||
global.modules.lyricWindow.setIgnoreMouseEvents(false)
|
||||
}
|
||||
}
|
||||
if (isForceSet || isAlwaysOnTop != desktopLyric.isAlwaysOnTop) {
|
||||
isAlwaysOnTop = desktopLyric.isAlwaysOnTop
|
||||
global.modals.lyricWindow.setAlwaysOnTop(desktopLyric.isAlwaysOnTop, 'screen-saver')
|
||||
global.modules.lyricWindow.setAlwaysOnTop(desktopLyric.isAlwaysOnTop, 'screen-saver')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,6 +38,27 @@ global.lx_event.common.on(COMMON_EVENT_NAME.config, name => {
|
||||
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)
|
||||
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_event.common.setAppConfig({ desktopLyric: desktopLyricSetting }, null)
|
||||
})
|
||||
|
||||
@@ -36,7 +36,7 @@ const winEvent = lyricWindow => {
|
||||
// })
|
||||
|
||||
lyricWindow.on('closed', () => {
|
||||
lyricWindow = global.modals.lyricWindow = null
|
||||
lyricWindow = global.modules.lyricWindow = null
|
||||
})
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ const winEvent = lyricWindow => {
|
||||
lyricWindow.once('ready-to-show', () => {
|
||||
lyricWindow.show()
|
||||
let config = global.appSetting.desktopLyric
|
||||
global.modals.lyricWindow.setBounds({
|
||||
global.modules.lyricWindow.setBounds({
|
||||
height: config.height,
|
||||
width: config.width,
|
||||
y: config.y,
|
||||
@@ -74,7 +74,7 @@ const winEvent = lyricWindow => {
|
||||
|
||||
|
||||
const createWindow = () => {
|
||||
if (global.modals.lyricWindow) return
|
||||
if (global.modules.lyricWindow) return
|
||||
if (!global.appSetting.desktopLyric.enable) return
|
||||
// const windowSizeInfo = getWindowSizeInfo(global.appSetting)
|
||||
const { x, y, width, height, isAlwaysOnTop } = global.appSetting.desktopLyric
|
||||
@@ -84,7 +84,7 @@ const createWindow = () => {
|
||||
/**
|
||||
* Initial window options
|
||||
*/
|
||||
global.modals.lyricWindow = new BrowserWindow({
|
||||
global.modules.lyricWindow = new BrowserWindow({
|
||||
height: height > screenHeight ? screenHeight : height,
|
||||
width: width > screenWidth ? screenWidth : width,
|
||||
x: Math.max(-8, screenWidth < (width + x) ? screenWidth - width : x),
|
||||
@@ -110,13 +110,13 @@ const createWindow = () => {
|
||||
},
|
||||
})
|
||||
|
||||
global.modals.lyricWindow.loadURL(winURL)
|
||||
global.modules.lyricWindow.loadURL(winURL)
|
||||
|
||||
winEvent(global.modals.lyricWindow)
|
||||
winEvent(global.modules.lyricWindow)
|
||||
// mainWindow.webContents.openDevTools()
|
||||
}
|
||||
|
||||
const closeWindow = () => {
|
||||
if (!global.modals.lyricWindow) return
|
||||
global.modals.lyricWindow.close()
|
||||
if (!global.modules.lyricWindow) return
|
||||
global.modules.lyricWindow.close()
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ const {
|
||||
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, {
|
||||
if (!global.modules.mainWindow) return
|
||||
mainSend(global.modules.mainWindow, ipcMainWindowNames.get_lyric_info, {
|
||||
name: ipcWinLyricNames.set_lyric_info,
|
||||
modal: 'lyricWindow',
|
||||
action,
|
||||
@@ -32,8 +32,8 @@ 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()
|
||||
if (!global.modules.lyricWindow) return
|
||||
bounds = global.modules.lyricWindow.getBounds()
|
||||
wasW = global.envParams.workAreaSize.width
|
||||
wasY = global.envParams.workAreaSize.height + 8
|
||||
|
||||
@@ -71,5 +71,5 @@ mainOn(ipcWinLyricNames.set_win_bounds, (event, { x = 0, y = 0, w = 0, h = 0 })
|
||||
}
|
||||
|
||||
// console.log(bounds)
|
||||
global.modals.lyricWindow.setBounds(bounds)
|
||||
global.modules.lyricWindow.setBounds(bounds)
|
||||
})
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
const { mainHandle, NAMES: { mainWindow: ipcMainWindowNames } } = require('../../common/ipc')
|
||||
|
||||
mainHandle(ipcMainWindowNames.clear_cache, async(event, options) => {
|
||||
if (!global.modals.mainWindow) throw new Error('mainWindow is undefined')
|
||||
return global.modals.mainWindow.webContents.session.clearCache()
|
||||
if (!global.modules.mainWindow) throw new Error('mainWindow is undefined')
|
||||
return global.modules.mainWindow.webContents.session.clearCache()
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const { mainHandle, NAMES: { mainWindow: ipcMainWindowNames } } = require('../../common/ipc')
|
||||
|
||||
mainHandle(ipcMainWindowNames.get_cache_size, async(event, options) => {
|
||||
if (!global.modals.mainWindow) throw new Error('mainWindow is undefined')
|
||||
return global.modals.mainWindow.webContents.session.getCacheSize()
|
||||
if (!global.modules.mainWindow) throw new Error('mainWindow is undefined')
|
||||
return global.modules.mainWindow.webContents.session.getCacheSize()
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
const { mainSend, NAMES: { mainWindow: ipcMainWindowNames }, mainOn } = require('../../common/ipc')
|
||||
const { mainWindow: MAIN_WINDOW_EVENT_NAME, hotKey: HOT_KEY_EVENT_NAME } = require('../events/_name')
|
||||
// const { registerHotkey, unRegisterHotkey } = require('../modules/hotKey/utils')
|
||||
|
||||
// mainHandle(ipcMainWindowNames.set_hot_key_config, async(event, { action, data }) => {
|
||||
// switch (action) {
|
||||
// case 'config':
|
||||
// global.lx_event.hotKey.saveConfig(data.data, MAIN_WINDOW_EVENT_NAME.source)
|
||||
// return
|
||||
// case 'register':
|
||||
// return registerHotkey(data)
|
||||
// case 'unregister':
|
||||
// return unRegisterHotkey(data)
|
||||
// }
|
||||
// })
|
||||
|
||||
mainOn(ipcMainWindowNames.quit, () => global.lx_event.mainWindow.quit())
|
||||
mainOn(ipcMainWindowNames.min_toggle, () => global.lx_event.mainWindow.toggleMinimize())
|
||||
mainOn(ipcMainWindowNames.hide_toggle, () => global.lx_event.mainWindow.toggleHide())
|
||||
|
||||
|
||||
global.lx_event.hotKey.on(HOT_KEY_EVENT_NAME.config, (config, source) => {
|
||||
if (!global.modules.mainWindow || source === MAIN_WINDOW_EVENT_NAME.name) return
|
||||
mainSend(global.modules.mainWindow, ipcMainWindowNames.set_hot_key_config, { config, source })
|
||||
})
|
||||
|
||||
global.lx_event.hotKey.on(HOT_KEY_EVENT_NAME.keyDown, ({ type, key }) => {
|
||||
let info = global.appHotKey.config.global.keys[key]
|
||||
if (!info || info.type != MAIN_WINDOW_EVENT_NAME.name) return
|
||||
mainSend(global.modules.mainWindow, ipcMainWindowNames.key_down, { type, key })
|
||||
})
|
||||
@@ -13,6 +13,7 @@ require('./setIgnoreMouseEvent')
|
||||
require('./getEnvParams')
|
||||
require('./setAppSetting')
|
||||
require('./setLyricInfo')
|
||||
require('./hotKey')
|
||||
|
||||
require('./xm_verify')
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ const decodeLyric = async(buf, isGetLyricx) => {
|
||||
}
|
||||
|
||||
mainHandle(ipcMainWindowNames.handle_kw_decode_lyric, async(event, { lrcBase64, isGetLyricx }) => {
|
||||
if (!global.modals.mainWindow) throw new Error('mainWindow is undefined')
|
||||
if (!global.modules.mainWindow) throw new Error('mainWindow is undefined')
|
||||
const lrc = await decodeLyric(Buffer.from(lrcBase64, 'base64'), isGetLyricx)
|
||||
return Buffer.from(lrc).toString('base64')
|
||||
})
|
||||
|
||||
@@ -3,7 +3,7 @@ const { mainOn, NAMES: { mainWindow: ipcMainWindowNames } } = require('../../com
|
||||
|
||||
mainOn(ipcMainWindowNames.progress, (event, params) => {
|
||||
// console.log(params)
|
||||
global.modals.mainWindow && global.modals.mainWindow.setProgressBar(params.status, {
|
||||
global.modules.mainWindow && global.modules.mainWindow.setProgressBar(params.status, {
|
||||
mode: params.mode || 'normal',
|
||||
})
|
||||
})
|
||||
|
||||
@@ -2,7 +2,7 @@ const { mainHandle, NAMES: { mainWindow: ipcMainWindowNames } } = require('../..
|
||||
const { dialog } = require('electron')
|
||||
|
||||
mainHandle(ipcMainWindowNames.select_dir, async(event, options) => {
|
||||
if (!global.modals.mainWindow) throw new Error('mainWindow is undefined')
|
||||
return dialog.showOpenDialog(global.modals.mainWindow, options)
|
||||
if (!global.modules.mainWindow) throw new Error('mainWindow is undefined')
|
||||
return dialog.showOpenDialog(global.modules.mainWindow, options)
|
||||
})
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
const { mainOn, NAMES: { mainWindow: ipcMainWindowNames } } = require('../../common/ipc')
|
||||
|
||||
mainOn(ipcMainWindowNames.set_ignore_mouse_events, (event, isIgnored) => {
|
||||
if (!global.modals.mainWindow) return
|
||||
if (!global.modules.mainWindow) return
|
||||
isIgnored
|
||||
? global.modals.mainWindow.setIgnoreMouseEvents(true, { forward: true })
|
||||
: global.modals.mainWindow.setIgnoreMouseEvents(false)
|
||||
? global.modules.mainWindow.setIgnoreMouseEvents(true, { forward: true })
|
||||
: global.modules.mainWindow.setIgnoreMouseEvents(false)
|
||||
})
|
||||
|
||||
@@ -6,5 +6,5 @@ mainOn(ipcMainWindowNames.set_lyric_info, (event, info) => {
|
||||
global.lx_event.mainWindow.setLyricInfo(info)
|
||||
return
|
||||
}
|
||||
mainSend(global.modals[info.info.modal], info.info.name, info)
|
||||
mainSend(global.modules[info.info.modal], info.info.name, info)
|
||||
})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const { mainOn, NAMES: { mainWindow: ipcMainWindowNames } } = require('../../common/ipc')
|
||||
|
||||
mainOn(ipcMainWindowNames.set_window_size, (event, options) => {
|
||||
if (!global.modals.mainWindow) return
|
||||
global.modals.mainWindow.setBounds(options)
|
||||
if (!global.modules.mainWindow) return
|
||||
global.modules.mainWindow.setBounds(options)
|
||||
})
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ const { mainHandle, NAMES: { mainWindow: ipcMainWindowNames } } = require('../..
|
||||
const { dialog } = require('electron')
|
||||
|
||||
mainHandle(ipcMainWindowNames.show_save_dialog, async(event, options) => {
|
||||
if (!global.modals.mainWindow) throw new Error('mainWindow is undefined')
|
||||
return dialog.showSaveDialog(global.modals.mainWindow, options)
|
||||
if (!global.modules.mainWindow) throw new Error('mainWindow is undefined')
|
||||
return dialog.showSaveDialog(global.modules.mainWindow, options)
|
||||
})
|
||||
|
||||
|
||||
@@ -2,17 +2,17 @@ const { app } = require('electron')
|
||||
const { mainOn, NAMES: { mainWindow: ipcMainWindowNames } } = require('../../common/ipc')
|
||||
|
||||
mainOn(ipcMainWindowNames.min, event => {
|
||||
if (global.modals.mainWindow) {
|
||||
global.modals.mainWindow.minimize()
|
||||
if (global.modules.mainWindow) {
|
||||
global.modules.mainWindow.minimize()
|
||||
}
|
||||
})
|
||||
mainOn(ipcMainWindowNames.max, event => {
|
||||
if (global.modals.mainWindow) {
|
||||
global.modals.mainWindow.maximize()
|
||||
if (global.modules.mainWindow) {
|
||||
global.modules.mainWindow.maximize()
|
||||
}
|
||||
})
|
||||
mainOn(ipcMainWindowNames.close, (event, isForce) => {
|
||||
if (isForce) return app.exit(0)
|
||||
global.isTrafficLightClose = true
|
||||
if (global.modals.mainWindow) global.modals.mainWindow.close()
|
||||
if (global.modules.mainWindow) global.modules.mainWindow.close()
|
||||
})
|
||||
|
||||
@@ -17,7 +17,7 @@ module.exports = mainWindow => {
|
||||
})
|
||||
|
||||
mainWindow.on('closed', () => {
|
||||
mainWindow = global.modals.mainWindow = null
|
||||
mainWindow = global.modules.mainWindow = null
|
||||
})
|
||||
|
||||
// mainWindow.on('restore', () => {
|
||||
|
||||
@@ -9,16 +9,16 @@ let rejectFn
|
||||
const closeView = async() => {
|
||||
if (!view) return
|
||||
// await view.webContents.session.clearCache()
|
||||
if (global.modals.mainWindow) global.modals.mainWindow.removeBrowserView(view)
|
||||
if (global.modules.mainWindow) global.modules.mainWindow.removeBrowserView(view)
|
||||
await view.webContents.session.clearStorageData()
|
||||
view.destroy()
|
||||
view = null
|
||||
}
|
||||
|
||||
mainHandle(ipcMainWindowNames.handle_xm_verify_open, (event, url) => new Promise((resolve, reject) => {
|
||||
if (!global.modals.mainWindow) return reject(new Error('mainWindow is undefined'))
|
||||
if (!global.modules.mainWindow) return reject(new Error('mainWindow is undefined'))
|
||||
if (view) {
|
||||
global.modals.mainWindow.removeBrowserView(view)
|
||||
global.modules.mainWindow.removeBrowserView(view)
|
||||
view.destroy()
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ mainHandle(ipcMainWindowNames.handle_xm_verify_open, (event, url) => new Promise
|
||||
})
|
||||
})
|
||||
|
||||
global.modals.mainWindow.setBrowserView(view)
|
||||
global.modules.mainWindow.setBrowserView(view)
|
||||
const windowSizeInfo = getWindowSizeInfo(global.appSetting)
|
||||
view.setBounds({ x: (windowSizeInfo.width - 380) / 2, y: ((windowSizeInfo.height - 320 + 52) / 2), width: 380, height: 320 })
|
||||
view.webContents.loadURL(url, {
|
||||
|
||||
@@ -7,7 +7,7 @@ let win
|
||||
const closeWin = async() => {
|
||||
if (!win) return
|
||||
// await win.webContents.session.clearCache()
|
||||
// if (global.modals.mainWindow) global.modals.mainWindow.removeBrowserView(win)
|
||||
// if (global.modules.mainWindow) global.modules.mainWindow.removeBrowserView(win)
|
||||
if (win.isDestroyed()) {
|
||||
win = null
|
||||
return
|
||||
@@ -18,15 +18,15 @@ const closeWin = async() => {
|
||||
}
|
||||
|
||||
mainHandle(ipcMainWindowNames.handle_xm_verify_open, (event, url) => new Promise((resolve, reject) => {
|
||||
if (!global.modals.mainWindow) return reject(new Error('mainWindow is undefined'))
|
||||
if (!global.modules.mainWindow) return reject(new Error('mainWindow is undefined'))
|
||||
if (win) win.destroy()
|
||||
|
||||
let isActioned = false
|
||||
|
||||
const mainWindowSizeInfo = global.modals.mainWindow.getBounds()
|
||||
const mainWindowSizeInfo = global.modules.mainWindow.getBounds()
|
||||
const windowSizeInfo = getWindowSizeInfo(global.appSetting)
|
||||
win = new BrowserWindow({
|
||||
parent: global.modals.mainWindow,
|
||||
parent: global.modules.mainWindow,
|
||||
width: 460,
|
||||
height: 370,
|
||||
resizable: false,
|
||||
|
||||
@@ -61,10 +61,10 @@ function sendStatusToWindow(text) {
|
||||
|
||||
let waitEvent = []
|
||||
const handleSendEvent = action => {
|
||||
if (global.modals.mainWindow) {
|
||||
if (global.modules.mainWindow) {
|
||||
setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还没启动完成
|
||||
if (!global.modals.mainWindow) return
|
||||
mainSend(global.modals.mainWindow, action.type, action.info)
|
||||
if (!global.modules.mainWindow) return
|
||||
mainSend(global.modules.mainWindow, action.type, action.info)
|
||||
}, 2000)
|
||||
} else {
|
||||
waitEvent.push(action)
|
||||
@@ -76,8 +76,8 @@ module.exports = () => {
|
||||
if (waitEvent.length) {
|
||||
waitEvent.forEach((event, index) => {
|
||||
setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还没启动完成
|
||||
if (!global.modals.mainWindow) return
|
||||
mainSend(global.modals.mainWindow, event.type, event.info)
|
||||
if (!global.modules.mainWindow) return
|
||||
mainSend(global.modules.mainWindow, event.type, event.info)
|
||||
}, 2000 * (index + 1))
|
||||
})
|
||||
waitEvent = []
|
||||
|
||||
+26
-4
@@ -1,19 +1,41 @@
|
||||
const Store = require('electron-store')
|
||||
const { windowSizeList } = require('../../common/config')
|
||||
const { objectDeepMerge } = require('../../common/utils')
|
||||
const { objectDeepMerge, throttle } = require('../../common/utils')
|
||||
|
||||
exports.getWindowSizeInfo = ({ windowSizeId = 1 } = {}) => {
|
||||
return windowSizeList.find(i => i.id === windowSizeId) || windowSizeList[0]
|
||||
}
|
||||
|
||||
const electronStore_config = new Store({
|
||||
name: 'config',
|
||||
})
|
||||
exports.getAppSetting = () => {
|
||||
const electronStore_config = new Store({
|
||||
name: 'config',
|
||||
})
|
||||
return electronStore_config.get('setting')
|
||||
}
|
||||
|
||||
const electronStore_hotKey = new Store({
|
||||
name: 'hotKey',
|
||||
})
|
||||
exports.getAppHotKeyConfig = () => {
|
||||
return {
|
||||
global: electronStore_hotKey.get('global'),
|
||||
local: electronStore_hotKey.get('local'),
|
||||
}
|
||||
}
|
||||
const saveHotKeyConfig = throttle(config => {
|
||||
for (const key of Object.keys(config)) {
|
||||
global.appHotKey.config[key] = config[key]
|
||||
electronStore_hotKey.set(key, config[key])
|
||||
}
|
||||
})
|
||||
exports.saveAppHotKeyConfig = config => {
|
||||
saveHotKeyConfig(config)
|
||||
}
|
||||
|
||||
const saveSetting = throttle(n => {
|
||||
electronStore_config.set('setting', n)
|
||||
})
|
||||
exports.updateSetting = settings => {
|
||||
objectDeepMerge(global.appSetting, settings)
|
||||
saveSetting(global.appSetting)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user