Save state when quitting on OSX

This commit is contained in:
DC
2016-04-03 23:49:51 -07:00
parent ee5b6ea472
commit fb42b84245

View File

@@ -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 */