From efb5db4f4701c0bc1b3dec9309e2803717c91961 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 23 Jul 2018 10:37:02 +0200 Subject: [PATCH] MOBILE-2478 desktop: Prevent errors when calling close in closed windows --- desktop/electron.js | 9 +++++---- src/core/emulator/classes/inappbrowserobject.ts | 11 ++++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/desktop/electron.js b/desktop/electron.js index 557ae4cfe..51087a40d 100644 --- a/desktop/electron.js +++ b/desktop/electron.js @@ -184,10 +184,11 @@ ipcMain.on('openItem', (event, path) => { }); ipcMain.on('closeSecondaryWindows', () => { - var windows = BrowserWindow.getAllWindows(); - for (var i = 0; i < windows.length; i++) { - if (!mainWindow || windows[i].id != mainWindow.id) { - windows[i].close(); + const windows = BrowserWindow.getAllWindows(); + for (let i = 0; i < windows.length; i++) { + const win = windows[i]; + if (!win.isDestroyed() && (!mainWindow || win.id != mainWindow.id)) { + win.close(); } } }); diff --git a/src/core/emulator/classes/inappbrowserobject.ts b/src/core/emulator/classes/inappbrowserobject.ts index 0af54081a..95b23898f 100644 --- a/src/core/emulator/classes/inappbrowserobject.ts +++ b/src/core/emulator/classes/inappbrowserobject.ts @@ -94,7 +94,16 @@ export class InAppBrowserObjectMock { * Close the window. */ close(): void { - this.window.close(); + if (this.window.isDestroyed()) { + // Window already closed, nothing to do. + return; + } + + try { + this.window.close(); + } catch (ex) { + // Ignore errors. + } } /**