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