Minor refactor logic of quit for non-multitasking app 97/255197/3
authorliwei <wei90727.li@samsung.com>
Mon, 15 Mar 2021 05:58:07 +0000 (13:58 +0800)
committerliwei <wei90727.li@samsung.com>
Wed, 17 Mar 2021 00:47:06 +0000 (08:47 +0800)
1.If app run in background and not support multitasking,
app will quit immediatly, window will be desotried,
then exception will happen, so ahead timing of addon
event to avid window is null, ahead timing of addon event
contentDidFinishLoad.
2.Set timeout to 0 for app.quit(), then it will be a little
delay, it can avoid crash.

Change-Id: I8c0cc11f13c48384e5a3e1965a1fc27353e81a3a
Signed-off-by: liwei <wei90727.li@samsung.com>
wrt_app/src/web_application.ts

index 6afc4ac..9d782c7 100644 (file)
@@ -278,6 +278,7 @@ export class WebApplication {
       console.log('webContents did-finish-load');
       this.loadFinished = true;
       wrt.hideSplashScreen(1);
+      addonManager.emit('contentDidFinishLoad', this.mainWindow.id);
       if (wrt.isIMEWebApp()) {
         this.activateIMEWebHelperClient();
       } else if (wrt.tv) {
@@ -286,7 +287,6 @@ export class WebApplication {
         else
           this.suspendByStatus();
       }
-      addonManager.emit('contentDidFinishLoad', this.mainWindow.id);
     });
   }
 
@@ -411,13 +411,12 @@ Then you can get profile log from the initial loading.`;
     this.suspended = true;
     this.windowList[this.windowList.length - 1].hide();
     this.flushData();
-    if (!this.backgroundRunnable()) {
-      if (!this.multitaskingSupport) {
+    this.windowList.forEach((window) => window.setEnabled(false));
+    if (!this.backgroundRunnable() && !this.multitaskingSupport) {
+      setTimeout(() => {
         console.log('multitasking is not supported; quitting app')
         app.quit();
-      } else {
-        this.windowList.forEach((window) => window.setEnabled(false));
-      }
+      }, 0);
     }
   }