From e5c805ba75aa2c38adbaded7cf6084614b9be321 Mon Sep 17 00:00:00 2001 From: davideschiera Date: Tue, 3 Oct 2017 22:36:57 -0700 Subject: [PATCH 1/4] Make sure to setup listeners every time you create the window --- ember-electron/main.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ember-electron/main.js b/ember-electron/main.js index 46a92aa6..91d5e7e2 100644 --- a/ember-electron/main.js +++ b/ember-electron/main.js @@ -50,8 +50,10 @@ function createServer() { serverInstance = backendServer(absPath) serverInstance.start((serverPort) => { global.serverPort = serverPort; - createWindow(); - setupListeners(); + + if (mainWindow === null) { + createWindow(); + } }); } @@ -67,6 +69,8 @@ function createWindow() { // Load the ember application using our custom protocol/scheme mainWindow.loadURL(APP_URL); + + setupListeners(); } function setupListeners() { From 5fc4095489f016afda1cf82e97fe5ea735d2d26c Mon Sep 17 00:00:00 2001 From: davideschiera Date: Tue, 3 Oct 2017 22:37:29 -0700 Subject: [PATCH 2/4] Close server when all windows are closed --- ember-electron/main.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ember-electron/main.js b/ember-electron/main.js index 91d5e7e2..dfeee4c6 100644 --- a/ember-electron/main.js +++ b/ember-electron/main.js @@ -99,6 +99,9 @@ function setupListeners() { } app.on('window-all-closed', () => { + serverInstance.stop(); + serverInstance = null; + if (process.platform !== 'darwin') { // Using exit instead of quit for the time being // see: https://github.com/electron/electron/issues/8862#issuecomment-294303518 From 2ed86c95218fd107c53243b0115c002d79a974ca Mon Sep 17 00:00:00 2001 From: davideschiera Date: Tue, 3 Oct 2017 22:37:48 -0700 Subject: [PATCH 3/4] Unused parameter --- ember-electron/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ember-electron/main.js b/ember-electron/main.js index dfeee4c6..033b2a42 100644 --- a/ember-electron/main.js +++ b/ember-electron/main.js @@ -128,7 +128,7 @@ app.on('activate', () => { if (serverInstance === null) { createServer(); } else if (mainWindow === null) { - createWindow(serverPort); + createWindow(); } }); From bcb2c99e8b43b2f05f6422f2300e736cf9d13541 Mon Sep 17 00:00:00 2001 From: davideschiera Date: Tue, 3 Oct 2017 22:39:05 -0700 Subject: [PATCH 4/4] Remove unnecessary window close --- ember-electron/main.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/ember-electron/main.js b/ember-electron/main.js index 033b2a42..97cedde6 100644 --- a/ember-electron/main.js +++ b/ember-electron/main.js @@ -109,15 +109,6 @@ app.on('window-all-closed', () => { } }); -app.on('before-quit', () => { - if (window && !window.isDestroyed() && window.isVisible()) { - window.removeAllListeners(); - window.close(); - - setTimeout(() => app.exit(), 2000); - } -}); - app.on('ready', () => { createServer(); });