托盘菜单新增显示、隐藏主界面选项,为Linux、MAC版添加托盘菜单
parent
ac162103a7
commit
b00de4d976
|
@ -1,3 +1,7 @@
|
||||||
|
### 新增
|
||||||
|
|
||||||
|
- 托盘菜单新增显示、隐藏主界面选项,为Linux、MAC版添加托盘菜单
|
||||||
|
|
||||||
### 优化
|
### 优化
|
||||||
|
|
||||||
- 移除kg源的歌词文件开头的空白字符串
|
- 移除kg源的歌词文件开头的空白字符串
|
||||||
|
|
|
@ -17,6 +17,18 @@ class MainWindow extends EventEmitter {
|
||||||
toggleHide() {
|
toggleHide() {
|
||||||
this.emit(MAIN_WINDOW_EVENT_NAME.toggle_hide)
|
this.emit(MAIN_WINDOW_EVENT_NAME.toggle_hide)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
readyToShow() {
|
||||||
|
this.emit(MAIN_WINDOW_EVENT_NAME.ready_to_show)
|
||||||
|
}
|
||||||
|
|
||||||
|
show() {
|
||||||
|
this.emit(MAIN_WINDOW_EVENT_NAME.show)
|
||||||
|
}
|
||||||
|
|
||||||
|
hide() {
|
||||||
|
this.emit(MAIN_WINDOW_EVENT_NAME.hide)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = MainWindow
|
module.exports = MainWindow
|
||||||
|
|
|
@ -10,6 +10,9 @@ exports.mainWindow = {
|
||||||
quit: 'quit',
|
quit: 'quit',
|
||||||
toggle_minimize: 'toggle_minimize',
|
toggle_minimize: 'toggle_minimize',
|
||||||
toggle_hide: 'toggle_hide',
|
toggle_hide: 'toggle_hide',
|
||||||
|
ready_to_show: 'ready_to_show',
|
||||||
|
show: 'show',
|
||||||
|
hide: 'hide',
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.tray = {
|
exports.tray = {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const { app, Tray, Menu } = require('electron')
|
const { app, Tray, Menu } = require('electron')
|
||||||
const { isWin } = require('../../common/utils')
|
const { isWin } = require('../../common/utils')
|
||||||
const { tray: TRAY_EVENT_NAME, common: COMMON_EVENT_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
|
||||||
let themeId = null
|
let themeId = null
|
||||||
|
@ -29,6 +29,16 @@ global.lx_event.common.on(COMMON_EVENT_NAME.config, sourceName => {
|
||||||
createMenu(global.modules.tray)
|
createMenu(global.modules.tray)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
global.lx_event.mainWindow.on(MAIN_WINDOW_NAME.ready_to_show, () => {
|
||||||
|
createMenu(global.modules.tray)
|
||||||
|
})
|
||||||
|
global.lx_event.mainWindow.on(MAIN_WINDOW_NAME.show, () => {
|
||||||
|
createMenu(global.modules.tray)
|
||||||
|
})
|
||||||
|
global.lx_event.mainWindow.on(MAIN_WINDOW_NAME.hide, () => {
|
||||||
|
createMenu(global.modules.tray)
|
||||||
|
})
|
||||||
|
|
||||||
const createTray = () => {
|
const createTray = () => {
|
||||||
if ((global.modules.tray && !global.modules.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
|
||||||
|
|
||||||
|
@ -58,8 +68,24 @@ const destroyTray = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const createMenu = tray => {
|
const createMenu = tray => {
|
||||||
if (!global.modules.tray || !isWin) return
|
if (!global.modules.tray) return
|
||||||
let menu = []
|
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()
|
||||||
|
},
|
||||||
|
})
|
||||||
menu.push(global.appSetting.desktopLyric.enable ? {
|
menu.push(global.appSetting.desktopLyric.enable ? {
|
||||||
label: '关闭桌面歌词',
|
label: '关闭桌面歌词',
|
||||||
click() {
|
click() {
|
||||||
|
|
|
@ -29,5 +29,13 @@ module.exports = mainWindow => {
|
||||||
|
|
||||||
mainWindow.once('ready-to-show', () => {
|
mainWindow.once('ready-to-show', () => {
|
||||||
mainWindow.show()
|
mainWindow.show()
|
||||||
|
global.lx_event.mainWindow.readyToShow()
|
||||||
|
})
|
||||||
|
|
||||||
|
mainWindow.on('show', () => {
|
||||||
|
global.lx_event.mainWindow.show()
|
||||||
|
})
|
||||||
|
mainWindow.on('hide', () => {
|
||||||
|
global.lx_event.mainWindow.hide()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue