From 803db72fe6334140f617f2751322189fbc64f95d Mon Sep 17 00:00:00 2001 From: Jessica Lord Date: Wed, 16 Dec 2015 11:10:38 -0800 Subject: [PATCH 1/4] Restore window on activate event --- main.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 0189f64..1e64f18 100644 --- a/main.js +++ b/main.js @@ -8,7 +8,7 @@ const BrowserWindow = electron.BrowserWindow; // Module to create native browse let mainWindow; // Quit when all windows are closed. -app.on('window-all-closed', function() { +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') { @@ -16,6 +16,14 @@ app.on('window-all-closed', function() { } }); +app.on('activate', function () { + // On OS X it's common to re-create a window in the app when the + // dock icon is clicked and there are no other windows open. + if (mainWindow === null) { + app.emit('ready'); + } +}); + // This method will be called when Electron has finished // initialization and is ready to create browser windows. app.on('ready', function() { From 3f26258efd9dcb99e701ab8a7bea8cabbd233e17 Mon Sep 17 00:00:00 2001 From: Jessica Lord Date: Wed, 16 Dec 2015 11:11:29 -0800 Subject: [PATCH 2/4] Use stricter platform check --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index 1e64f18..14011f7 100644 --- a/main.js +++ b/main.js @@ -11,7 +11,7 @@ let mainWindow; 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') { + if (process.platform !== 'darwin') { app.quit(); } }); From 49228fc51042b80985b6d65f94f04ca5f089b62b Mon Sep 17 00:00:00 2001 From: Jessica Lord Date: Wed, 16 Dec 2015 11:13:32 -0800 Subject: [PATCH 3/4] Clean up --- main.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index 14011f7..7a0ffbc 100644 --- a/main.js +++ b/main.js @@ -1,7 +1,10 @@ 'use strict'; + const electron = require('electron'); -const app = electron.app; // Module to control application life. -const BrowserWindow = electron.BrowserWindow; // Module to create native browser window. +// Module to control application life. +const app = electron.app; +// Module to create native browser window. +const BrowserWindow = electron.BrowserWindow; // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. From d709bb0885d732c443507191aa6a3cf89c65b379 Mon Sep 17 00:00:00 2001 From: Jessica Lord Date: Wed, 16 Dec 2015 11:19:56 -0800 Subject: [PATCH 4/4] Extract createWindow helper, re org --- main.js | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/main.js b/main.js index 7a0ffbc..a9b3175 100644 --- a/main.js +++ b/main.js @@ -10,26 +10,7 @@ const BrowserWindow = electron.BrowserWindow; // be closed automatically when the JavaScript object is garbage collected. let mainWindow; -// 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(); - } -}); - -app.on('activate', function () { - // On OS X it's common to re-create a window in the app when the - // dock icon is clicked and there are no other windows open. - if (mainWindow === null) { - app.emit('ready'); - } -}); - -// This method will be called when Electron has finished -// initialization and is ready to create browser windows. -app.on('ready', function() { +function createWindow () { // Create the browser window. mainWindow = new BrowserWindow({width: 800, height: 600}); @@ -46,4 +27,25 @@ app.on('ready', function() { // when you should delete the corresponding element. mainWindow = null; }); +} + +// This method will be called when Electron has finished +// initialization and is ready to create browser windows. +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(); + } +}); + +app.on('activate', function () { + // On OS X it's common to re-create a window in the app when the + // dock icon is clicked and there are no other windows open. + if (mainWindow === null) { + createWindow(); + } });