Refactor suspend sequence 15/246015/5
authorDongHyun Song <dh81.song@samsung.com>
Thu, 22 Oct 2020 05:15:08 +0000 (14:15 +0900)
committerDongHyun Song <dh81.song@samsung.com>
Thu, 22 Oct 2020 07:32:09 +0000 (07:32 +0000)
1) Bring forward suspend time when before-quit.
 ** When OnTerminate is coming first earlier than OnPause,
  'quit' makes this.webApplication as undefined, then
  wrt.on('suspend'...) will be skipped. This means that
  With normal termination sequence, suspending might be not
  handled.

2) Even though background runnable app, when app is in quitting,
 enable suspend sequence for right termination sequence.

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

index 61bbfd7474b556fee31cddb5138fc8021bd2565f..3e5a683d8a7d75b44f1b405c7385ad272c2817d4 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() {