From fb42b84245208b35764c8f631800b8bf982c5978 Mon Sep 17 00:00:00 2001 From: DC Date: Sun, 3 Apr 2016 23:49:51 -0700 Subject: [PATCH] Save state when quitting on OSX --- main/tray.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main/tray.js b/main/tray.js index 3c0b6a8b..da44de6e 100644 --- a/main/tray.js +++ b/main/tray.js @@ -10,7 +10,10 @@ var trayIcon function init () { // No tray icon on OSX - if (process.platform === 'darwin') return + if (process.platform === 'darwin') { + // Instead of relying on the tray icon quit button, listen for Cmd+Q + electron.app.once('before-quit', quitApp) + } trayIcon = new electron.Tray(path.join(__dirname, '..', 'static', 'WebTorrentSmall.png')) @@ -46,7 +49,8 @@ function hideApp () { windows.main.hide() } -function quitApp () { +function quitApp (e) { + e.preventDefault() windows.main.send('dispatch', 'saveState') /* try to save state on exit */ electron.ipcMain.once('savedState', () => electron.app.quit()) setTimeout(() => electron.app.quit(), 2000) /* exit after at most 2 secs */