Fix an error of 'Object has been destroyed' 71/260271/5
authorDongHyun Song <dh81.song@samsung.com>
Wed, 23 Jun 2021 02:21:55 +0000 (11:21 +0900)
committerDongHyun Song <dh81.song@samsung.com>
Wed, 23 Jun 2021 07:15:36 +0000 (16:15 +0900)
When app is terminate by SIGTERM or tizen.application...exit(),
There comes a TypeError 'Object has been destroyed'

suspend() will be called again on quit() for backgroun-runnable
apps, but since this.mainWindow can be already destroyed, below
code can throw exception with destroyed object 'this.mainWindow'
 - addonManager.emit('lcSuspend', this.mainWindow.id);

It is enough to call setEnable() for suspending (if window is alive)

Change-Id: Ie2e99cf74ca412902e4456901dc8350f038e3067
Signed-off-by: DongHyun Song <dh81.song@samsung.com>
wrt_app/src/web_application.ts

index 53e0899..84be283 100644 (file)
@@ -283,10 +283,11 @@ export class WebApplication {
     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.profileDelegate.canIgnoreSuspend())
       return;
@@ -318,10 +319,11 @@ export class WebApplication {
   quit() {
     console.log('WebApplication : quit');
     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();
   }
 
   beforeQuit() {