From 9186cca9bb3fdf846b66e56aa14615abe41389f5 Mon Sep 17 00:00:00 2001 From: Surya Kumar Date: Thu, 4 May 2023 18:07:41 +0530 Subject: [PATCH] Avoid "Object has been destroyed" JS error It's possible mainWindow would be destroyed during suspend, but addonManager tries to access it without checking it leading to JS crash. This change fixes it. Change-Id: Ifbb65e13e290474b7628bc02ccac36a51f8bb367 Signed-off-by: Surya Kumar --- wrt_app/src/web_application.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/wrt_app/src/web_application.ts b/wrt_app/src/web_application.ts index 9695eeb8..24bfff40 100644 --- a/wrt_app/src/web_application.ts +++ b/wrt_app/src/web_application.ts @@ -345,10 +345,11 @@ Then you can get profile log from the initial loading.`; if (this.suspended || this.inQuit) return; console.log('WebApplication : suspend'); - addonManager.emit('lcSuspend', this.mainWindow.id); this.suspended = true; - if (this.windowList.length > 0) + if (this.windowList.length > 0) { + addonManager.emit('lcSuspend', this.mainWindow.id); this.windowList[this.windowList.length - 1].hide(); + } this.flushData(); if (!this.backgroundRunnable()) { if (!this.multitaskingSupport) { @@ -376,7 +377,10 @@ Then you can get profile log from the initial loading.`; finalize() { console.log('WebApplication : finalize'); this.flushData(); - this.windowList.forEach((window) => window.removeAllListeners()); + this.windowList.forEach((window) => { + window.removeAllListeners(); + window.setEnabled(false); + }); this.inQuit = false; if (!this.suspended) this.suspend(); @@ -384,7 +388,8 @@ Then you can get profile log from the initial loading.`; quit() { console.log('WebApplication : quit'); - addonManager.emit('lcQuit', this.mainWindow.id); + if (this.windowList.length > 0) + addonManager.emit('lcQuit', this.mainWindow.id); if (wrt.tv) { this.inspectorSrc = ''; wrt.tv.cancelDialogs(this.mainWindow.webContents); -- 2.34.1