From 1618cf0aa8978ba587f2c60714286810f10852af Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Mon, 15 Feb 2021 21:03:18 +0900 Subject: [PATCH] refs #2145 Divide quit application menu item to quit app in macOS --- src/main/index.ts | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 9504ce21..a30f6862 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -334,10 +334,6 @@ async function createWindow() { mainWindow.webContents.on('will-navigate', event => event.preventDefault()) - mainWindow.on('closed', () => { - mainWindow = null - }) - // Show tray icon only linux and windows. if (process.platform !== 'darwin') { // Show tray icon @@ -358,11 +354,15 @@ async function createWindow() { }) // Minimize to tray - mainWindow!.on('close', event => { + mainWindow.on('close', event => { mainWindow!.hide() mainWindow!.setSkipTaskbar(true) event.preventDefault() }) + } else { + mainWindow.on('closed', () => { + mainWindow = null + }) } } @@ -1163,6 +1163,25 @@ const ApplicationMenu = (accountsChange: Array, menu } ] + const applicationQuitMenu: Array = + process.platform === 'darwin' + ? [ + { + label: i18n.t('main_menu.application.quit'), + accelerator: 'CmdOrCtrl+Q', + role: 'quit' + } + ] + : [ + { + label: i18n.t('main_menu.application.quit'), + accelerator: 'CmdOrCtrl+Q', + click: () => { + mainWindow!.destroy() + } + } + ] + const template: Array = [ { label: i18n.t('main_menu.application.name'), @@ -1193,13 +1212,7 @@ const ApplicationMenu = (accountsChange: Array, menu { type: 'separator' }, - { - label: i18n.t('main_menu.application.quit'), - accelerator: 'CmdOrCtrl+Q', - click: () => { - mainWindow!.destroy() - } - } + ...applicationQuitMenu ] }, {