Refactor termination sequence 45/206145/5
authorsurya.kumar7 <surya.kumar7@samsung.com>
Wed, 15 May 2019 17:09:09 +0000 (22:39 +0530)
committersurya.kumar7 <surya.kumar7@samsung.com>
Wed, 15 May 2019 17:09:49 +0000 (22:39 +0530)
1. Termination logic has been altered to navigate toward one sink
for different termination requests
2. UI/Watch app loop cycle is destroyed before electron app's
quit is called

Linked to: https://review.tizen.org/gerrit/205432

Change-Id: I471cf5896e7045a395ebe4a85fcb97962444721b
Signed-off-by: surya.kumar7 <surya.kumar7@samsung.com>
wrt_app/src/runtime.js
wrt_app/src/web_application.js

index cafec8f8df077c5c9b8d76e78da19886c2a5aac0..33596bab5b88c3422cf2d63cc69f2ce5ff764d1d 100755 (executable)
@@ -37,6 +37,7 @@ class Runtime {
         });
         app.on('before-quit', function(event) {
             console.log('before-quit');
+            wrt.exit();
         });
         app.on('will-quit', function(event) {
             console.log('will-quit');
@@ -45,7 +46,6 @@ class Runtime {
         });
         app.on('quit', function(event) {
             console.log('quit');
-            wrt.exit();
         });
         app.on('browser-window-blur', function() {
             console.log('browser-window-blur');
@@ -65,7 +65,9 @@ class Runtime {
         });
         app.on('window-all-closed', function(event) {
             console.log('window-all-closed');
-            app.quit();
+            // For Tizen Apps, quit will be called from web_application.js
+            if (!_this.webApplication)
+                app.quit();
         });
         app.on('will-finish-launching', function(event) {
             console.log('will-finish-launching');
@@ -152,15 +154,19 @@ class Runtime {
         });
         wrt.on('suspend', function() {
             console.log('suspend');
-            _this.webApplication.suspend();
+            if (_this.webApplication)
+                _this.webApplication.suspend();
         });
         wrt.on('resume', function() {
             console.log('resume');
-            _this.webApplication.resume();
+            if (_this.webApplication)
+                _this.webApplication.resume();
         });
         wrt.on('terminate', function() {
             console.log('terminate');
-            _this.webApplication.terminate();
+            if (_this.webApplication)
+                _this.webApplication.terminate();
+            else app.quit();
         });
     }
     onLanguageChanged() {}
index 81e3b4d5d72761c9ea8bc33403be73b0de862561..fd9b5e468a51b417ccd225bd7b520e1f4beff639 100755 (executable)
@@ -53,14 +53,16 @@ class WebApplication {
                 console.log(`window closed : #${self.windowList.length}`);
                 let index = self.windowList.indexOf(window);
                 self.windowList.splice(index, 1);
-                if (!self.isTerminating && index === self.windowList.length && self.windowList.length > 0)
+                if (!self.windowList.length)
+                    self.terminate();
+                else if (index === self.windowList.length)
                     self.windowList[self.windowList.length - 1].show();
             });
         });
         app.on('web-contents-created', function(event, webContents) {
             webContents.on('crashed', function() {
                 console.error('webContents crashed');
-                app.exit(100);
+                self.terminate();
             });
             webContents.session.setPermissionRequestHandler(function(webContents, permission, callback) {
                 console.log(`handlePermissionRequests for ${permission}`);
@@ -225,7 +227,7 @@ class WebApplication {
         let windows = BrowserWindow.getAllWindows();
         if (!this.multitaskingSupport) {
             console.log('multitasking is not supported; quitting app')
-            app.quit();
+            this.terminate();
         } else if (!this.backgroundSupport) {
             windows.forEach((window) => window.setEnabled(false));
         }
@@ -245,7 +247,12 @@ class WebApplication {
         this.windowList[this.windowList.length - 1].show();
     }
     terminate() {
-        this.isTerminating = true;
+        console.log('WebApplication : terminate');
+        if (!this.isTerminating) {
+            console.log('terminating app');
+            this.isTerminating = true;
+            app.quit();
+        } else console.log('termination is already in progress');
     }
     sendAppControlEvent() {
         const kAppControlEventScript =