优化托盘菜单操作#686
parent
a338b7ef39
commit
0acfeff006
|
@ -26,6 +26,14 @@ class MainWindow extends EventEmitter {
|
|||
this.emit(MAIN_WINDOW_EVENT_NAME.show)
|
||||
}
|
||||
|
||||
focus() {
|
||||
this.emit(MAIN_WINDOW_EVENT_NAME.focus)
|
||||
}
|
||||
|
||||
blur() {
|
||||
this.emit(MAIN_WINDOW_EVENT_NAME.blur)
|
||||
}
|
||||
|
||||
hide() {
|
||||
this.emit(MAIN_WINDOW_EVENT_NAME.hide)
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ exports.mainWindow = {
|
|||
ready_to_show: 'ready_to_show',
|
||||
show: 'show',
|
||||
hide: 'hide',
|
||||
focus: 'focus',
|
||||
blur: 'blur',
|
||||
}
|
||||
|
||||
exports.tray = {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const { app, Tray, Menu, nativeImage } = require('electron')
|
||||
// const { isWin } = require('../../common/utils')
|
||||
const { isWin } = require('@common/utils')
|
||||
const { tray: TRAY_EVENT_NAME, common: COMMON_EVENT_NAME, mainWindow: MAIN_WINDOW_NAME } = require('../events/_name')
|
||||
const path = require('path')
|
||||
let isEnableTray = null
|
||||
|
@ -40,6 +40,14 @@ global.lx_event.mainWindow.on(MAIN_WINDOW_NAME.ready_to_show, () => {
|
|||
global.lx_event.mainWindow.on(MAIN_WINDOW_NAME.show, () => {
|
||||
createMenu(global.modules.tray)
|
||||
})
|
||||
if (!isWin) {
|
||||
global.lx_event.mainWindow.on(MAIN_WINDOW_NAME.focus, () => {
|
||||
createMenu(global.modules.tray)
|
||||
})
|
||||
global.lx_event.mainWindow.on(MAIN_WINDOW_NAME.blur, () => {
|
||||
createMenu(global.modules.tray)
|
||||
})
|
||||
}
|
||||
global.lx_event.mainWindow.on(MAIN_WINDOW_NAME.hide, () => {
|
||||
createMenu(global.modules.tray)
|
||||
})
|
||||
|
@ -75,24 +83,27 @@ const destroyTray = () => {
|
|||
const createMenu = tray => {
|
||||
if (!global.modules.tray) return
|
||||
let menu = []
|
||||
global.modules.mainWindow && menu.push(global.modules.mainWindow.isVisible()
|
||||
? {
|
||||
label: '隐藏主界面',
|
||||
click() {
|
||||
global.modules.mainWindow.hide()
|
||||
},
|
||||
}
|
||||
: {
|
||||
label: '显示主界面',
|
||||
click() {
|
||||
if (!global.modules.mainWindow) return
|
||||
if (!global.modules.mainWindow.isVisible()) {
|
||||
global.modules.mainWindow.show()
|
||||
}
|
||||
global.modules.mainWindow.restore()
|
||||
global.modules.mainWindow.focus()
|
||||
},
|
||||
})
|
||||
if (global.modules.mainWindow) {
|
||||
const isShow = global.modules.mainWindow.isVisible() && (isWin ? true : global.modules.mainWindow.isFocused())
|
||||
menu.push(isShow
|
||||
? {
|
||||
label: '隐藏主界面',
|
||||
click() {
|
||||
global.modules.mainWindow.hide()
|
||||
},
|
||||
}
|
||||
: {
|
||||
label: '显示主界面',
|
||||
click() {
|
||||
if (!global.modules.mainWindow) return
|
||||
if (!global.modules.mainWindow.isVisible()) {
|
||||
global.modules.mainWindow.show()
|
||||
}
|
||||
global.modules.mainWindow.restore()
|
||||
global.modules.mainWindow.focus()
|
||||
},
|
||||
})
|
||||
}
|
||||
menu.push(global.appSetting.desktopLyric.enable
|
||||
? {
|
||||
label: '关闭桌面歌词',
|
||||
|
|
|
@ -26,6 +26,11 @@ module.exports = mainWindow => {
|
|||
// })
|
||||
mainWindow.on('focus', () => {
|
||||
mainSend(mainWindow, ipcMainWindowNames.focus)
|
||||
global.lx_event.mainWindow.focus()
|
||||
})
|
||||
|
||||
mainWindow.on('blur', () => {
|
||||
global.lx_event.mainWindow.blur()
|
||||
})
|
||||
|
||||
mainWindow.once('ready-to-show', () => {
|
||||
|
|
Loading…
Reference in New Issue