From 00c5fd1cba03abb690fcd76f8613862cc5eea3f8 Mon Sep 17 00:00:00 2001 From: Johannes Millan Date: Tue, 17 Jan 2017 01:49:27 +0100 Subject: [PATCH] fix closing and restoring not working nicely on darwin --- electron/main.js | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/electron/main.js b/electron/main.js index 462937b15d..d89305b39f 100644 --- a/electron/main.js +++ b/electron/main.js @@ -27,10 +27,11 @@ const url = require('url'); // be closed automatically when the JavaScript object is garbage collected. let mainWindow; let lastIdleTime; +let darwinForceQuit = false; function createWindow() { // Create the browser window. - mainWindow = new BrowserWindow({ width: 800, height: 600 }); + mainWindow = new BrowserWindow({width: 800, height: 600}); // and load the index.html of the app. mainWindow.loadURL(url.format({ @@ -49,11 +50,18 @@ function createWindow() { }); mainWindow.on('close', function (event) { - if (!app.isQuiting) { - event.preventDefault(); - mainWindow.hide(); + // handle darwin + if (process.platform === 'darwin') { + if (!darwinForceQuit) { + event.preventDefault(); + mainWindow.hide(); + } + } else { + if (!app.isQuiting) { + event.preventDefault(); + mainWindow.hide(); + } } - return false; }); mainWindow.on('minimize', function (event) { @@ -68,14 +76,6 @@ function createWindow() { // Some APIs can only be used after this event occurs. app.on('ready', createWindow); -// Quit when all windows are closed. -app.on('window-all-closed', function () { - // On OS X it is common for applications and their menu bar - // to stay active until the user quits explicitly with Cmd + Q - //if (process.platform !== 'darwin') { - app.quit(); - //} -}); let tray = null; app.on('ready', () => { @@ -124,7 +124,10 @@ app.on('activate', function () { // dock icon is clicked and there are no other windows open. if (mainWindow === null) { createWindow(); + } else { + mainWindow.show(); } + }); app.on('ready', () => { @@ -135,6 +138,11 @@ app.on('before-quit', () => { if (tray) { tray.destroy(); } + + // handle darwin + if (process.platform === 'darwin') { + darwinForceQuit = true; + } }); // listen to events from frontend