diff --git a/src/main/modules/appMenu.js b/src/main/modules/appMenu.js index 89bfd837..2af38e4a 100644 --- a/src/main/modules/appMenu.js +++ b/src/main/modules/appMenu.js @@ -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() + }, + }, ], }, { diff --git a/src/main/modules/tray.js b/src/main/modules/tray.js index 8a8305da..ab825258 100644 --- a/src/main/modules/tray.js +++ b/src/main/modules/tray.js @@ -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('洛雪音乐助手') diff --git a/src/main/rendererEvents/winEvent.js b/src/main/rendererEvents/winEvent.js index 30a28744..7e87064a 100644 --- a/src/main/rendererEvents/winEvent.js +++ b/src/main/rendererEvents/winEvent.js @@ -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