Refactor suspend sequence
[platform/framework/web/wrtjs.git] / wrt_app / src / web_application.ts
index 61bbfd7..3e5a683 100644 (file)
@@ -44,6 +44,7 @@ export class WebApplication {
   runningStatus = 'none';
   suspended = false;
   windowList: Electron.BrowserWindow[] = [];
+  inQuit = false;
 
   constructor(options: RuntimeOption) {
     if (options.launchMode == 'backgroundAtStartup') {
@@ -344,12 +345,14 @@ Then you can get profile log from the initial loading.`;
   }
 
   suspend() {
+    if (this.suspended)
+      return;
     console.log('WebApplication : suspend');
     addonManager.emit('lcSuspend', this.mainWindow.id);
     this.suspended = true;
     this.windowList[this.windowList.length - 1].hide();
     this.flushData();
-    if (!this.backgroundRunnable()) {
+    if (!this.backgroundRunnable() || this.inQuit) {
       if (!this.multitaskingSupport) {
         // FIXME : terminate app after visibilitychange event handling
         setTimeout(() => {
@@ -394,6 +397,9 @@ Then you can get profile log from the initial loading.`;
   quit() {
     console.log('WebApplication : quit');
     addonManager.emit('lcQuit', this.mainWindow.id);
+    this.inQuit = true;
+    if (!this.suspended)
+      this.suspend();
   }
 
   private flushData() {