修复启用托盘后无法退出程序的问题

pull/225/head
lyswhut 2020-04-03 21:30:48 +08:00
parent 2e84788d53
commit be84bd27d3
3 changed files with 16 additions and 4 deletions

View File

@ -12,7 +12,14 @@ if (isMac) {
{ label: '显示其他', role: 'hideothers' },
{ label: '显示全部', role: 'unhide' },
{ type: 'separator' },
{ label: '退出', accelerator: 'Command+Q', click: () => app.quit() },
{
label: '退出',
accelerator: 'Command+Q',
click() {
global.isQuitting = true
app.quit()
},
},
],
},
{

View File

@ -1,4 +1,4 @@
const { Tray, Menu } = require('electron')
const { app, Tray, Menu } = require('electron')
const { isMac, isWin } = require('../../common/utils')
const { tray: TRAY_EVENT_NAME } = require('../events/_name')
const path = require('path')
@ -21,7 +21,10 @@ function createTray() {
const contextMenu = Menu.buildFromTemplate([
{
label: '退出',
role: 'quit',
click() {
global.isQuitting = true
app.quit()
},
},
])
tray.setToolTip('洛雪音乐助手')

View File

@ -1,6 +1,8 @@
global.isQuitting = false
module.exports = mainWindow => {
mainWindow.on('close', event => {
if (global.appSetting.tray.isToTray) {
if (!global.isQuitting && global.appSetting.tray.isToTray) {
event.preventDefault()
mainWindow.hide()
return