Suspend the app if app has gone behind 64/205164/19
authorDongHyun Song <dh81.song@samsung.com>
Fri, 31 May 2019 02:18:16 +0000 (11:18 +0900)
committerDongHyun Song <dh81.song@samsung.com>
Mon, 3 Jun 2019 10:55:03 +0000 (19:55 +0900)
When an app's visibility is changed as background even the app
had not been get foreground event, this app should be suspended
to avoid running in background mode.
If the app has backgroundSupport mode, when suspeding, it will be
skipped.

This feature only can work with TV profile due to "wrt.getAppState"

This patch is depend on https://review.tizen.org/gerrit/204707

Change-Id: I3c05f4c4f61b23c5b510e3ec058d60253a94e8a7

wrt_app/src/web_application.js

index 16ab876..3f242e9 100755 (executable)
@@ -41,6 +41,8 @@ class WebApplication {
         this.accessiblePath = wrt.getAccessiblePath();
         this.isTerminating = false;
         this.suspended = true;
+        this.loadFinished = false;
+        this.runningStatus = 'none';
 
         let self = this;
         app.on('browser-window-created', function(event, window) {
@@ -157,6 +159,13 @@ class WebApplication {
                 self.pendingCallbacks.delete(id);
             }
         });
+        wrt.on('app-status-changed', function(event, status) {
+            console.log(`runningStatus: ${status}, ${self.loadFinished}`);
+            self.runningStatus = status;
+            if (self.loadFinished && self.runningStatus == 'behind') {
+                self.suspend();
+            }
+        });
     }
     getBrowserWindowOption(options) {
         return {
@@ -206,15 +215,18 @@ class WebApplication {
         });
         this.mainWindow.webContents.on('did-start-loading', function() {
             console.log('webContents did-start-loading');
+            self.loadFinished = false;
         });
         this.mainWindow.webContents.on('did-finish-load', function() {
-            console.log(`webContents did-finish-load preloadState: ${self.preloadState}`);
+            console.log(`webContents did-finish-load preloadState: ${self.preloadState}, status: ${self.runningStatus}`);
+            self.loadFinished = true;
             wrt.hideSplashScreen(2);
             if (wrt.isIMEWebApp())
                 self.activateIMEWebHelperClient();
-            if (self.preloadState === 'readyToShow' || self.preloadState === 'preload') {
+            if (self.preloadState === 'readyToShow' || self.preloadState === 'preload' || self.runningStatus === 'behind') {
                 self.suspend();
-                wrt.notifyAppStatus('preload');
+                if (self.runningStatus !== 'behind')
+                    wrt.notifyAppStatus('preload');
             }
         });
     }