From: DongHyun Song Date: Fri, 31 May 2019 02:18:16 +0000 (+0900) Subject: Suspend the app if app has gone behind X-Git-Tag: submit/tizen/20190814.020427~19 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=515f5b8bb70a422e4684c64a66c3645f74840f6c;p=platform%2Fframework%2Fweb%2Fwrtjs.git Suspend the app if app has gone behind 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 --- diff --git a/wrt_app/src/web_application.js b/wrt_app/src/web_application.js index 16ab876c..3f242e98 100755 --- a/wrt_app/src/web_application.js +++ b/wrt_app/src/web_application.js @@ -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'); } }); }