From 7477437c6d28e50ce382c9ed7e9e30c634a3b7ff Mon Sep 17 00:00:00 2001 From: Lynn Date: Tue, 18 Apr 2017 13:40:26 -0700 Subject: [PATCH] use correct event when browserWin finally closes (#60) --- js/windowMgr.js | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/js/windowMgr.js b/js/windowMgr.js index 11d58f1d..53cbe586 100644 --- a/js/windowMgr.js +++ b/js/windowMgr.js @@ -114,7 +114,7 @@ function createMainWindow(initialUrl) { }); function destroyAllWindows() { - var keys = Object.keys(windows); + let keys = Object.keys(windows); for(var i = 0, len = keys.length; i < len; i++) { let winKey = keys[i]; removeWindowKey(winKey); @@ -143,8 +143,9 @@ function createMainWindow(initialUrl) { // abort - no frame name provided. return; } + // reposition new window - var mainWinPos = mainWindow.getPosition(); + let mainWinPos = mainWindow.getPosition(); if (mainWinPos && mainWinPos.length === 2) { let newWinKey = getGuid(); @@ -155,18 +156,20 @@ function createMainWindow(initialUrl) { newWinOptions.winKey = newWinKey; /* eslint-enable no-param-reassign */ - // note: will use code below later for saved layout impl. - var webContents = newWinOptions.webContents; + let webContents = newWinOptions.webContents; + webContents.once('did-finish-load', function() { + let browserWin = electron.BrowserWindow.fromWebContents(webContents); - var browserWin = electron.BrowserWindow.fromWebContents(webContents); - browserWin.winName = frameName; + if (browserWin) { + browserWin.winName = frameName; - addWindowKey(newWinKey, browserWin); + browserWin.once('closed', function() { + removeWindowKey(newWinKey); + }); - browserWin.once('close', function() { - removeWindowKey(newWinKey); - }); + addWindowKey(newWinKey, browserWin); + } // note: will use later for save-layout feature // browserWin.on('move', function() { @@ -215,10 +218,11 @@ function setIsOnline(status) { } function activate(windowName) { - var keys = Object.keys(windows); - for(var i = 0, len = keys.length; i < len; i++) { - var window = windows[keys[i]]; - if (window.winName === windowName) { + let keys = Object.keys(windows); + for(let i = 0, len = keys.length; i < len; i++) { + let window = windows[keys[i]]; + if (window && !window.isDestroyed() && + window.winName === windowName) { window.show(); return; }