fixup! Implement app control handler 10/201310/4
authorsurya.kumar7 <surya.kumar7@samsung.com>
Tue, 12 Mar 2019 08:52:07 +0000 (14:22 +0530)
committersurya.kumar7 <surya.kumar7@samsung.com>
Tue, 26 Mar 2019 07:55:50 +0000 (13:25 +0530)
Modified certain code to prevent inadvertent app exit, wrong
sequence and fixed an undefined object

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

index 8017068a0b398c8b9d9272c2c2ac02a4ec9ab39a..d73db46c9621240c1f12ee0cf64d5221c65b9e5b 100755 (executable)
@@ -81,7 +81,17 @@ class Runtime {
             let loadInfo = appControl.getLoadInfo();
             let src = loadInfo.getSrc();
 
-            if (_this.webApplication) {
+            if (wrt.isElectronApp()) {
+                console.log("Electron App launch");
+                let filePath = src;
+                let pkgJson = require(filePath.substr(7, filePath.length - 12));
+                let mainJsPath = filePath.substr(7, filePath.length - 19) +
+                                                (pkgJson.main || 'index.js');
+
+                const Module = require('module');
+                Module._load(mainJsPath, Module, true);
+                app.emit('ready');
+            } else if (_this.webApplication) {
                 if (_this.webApplication.preloadState == 'readyToShow') {
                     _this.webApplication.show();
                 }
@@ -90,7 +100,6 @@ class Runtime {
                 if (launchMode != 'backgroundAtStartup') {
                     _this.webApplication.preloadState = 'none';
                 }
-
                 let skipReload = appControl.getData('SkipReload');
                 if (skipReload == 'Yes') {
                     console.log('skipping reload');
@@ -109,25 +118,11 @@ class Runtime {
                 if (reload && appControl.getOperation() == 'http://tizen.org/appcontrol/operation/main')
                     reload = false;
                 if (reload) {
-                    _this.webApplication.mainWindow.destroy();
-                    _this.webApplication = nullptr;
+                    _this.webApplication.closeWindows();
+                    _this.webApplication.mainWindow.loadURL(src);
                 } else {
                     _this.webApplication.sendAppControlEvent();
                 }
-            }
-
-            if (wrt.isElectronApp()) {
-                console.log("Electron App launch");
-                require('module').globalPaths.push(wrt.getAppPath());
-                let filePath = src[7] === '/' ? src.substr(8) : src.substr(7); // strip "file://"
-                let pkgJson = require(filePath);
-                let pos = filePath.lastIndexOf('/');
-                let mainJsPath = (pos !== -1 ? filePath.substr(0, pos + 1) : '') +
-                                 (pkgJson.main || 'index.js');
-
-                const Module = require('module');
-                Module._load(mainJsPath, Module, true);
-                app.emit('ready');
             } else {
                 _this.webApplication = new WebApplication(options);
                 let launchMode = appControl.getData('http://samsung.com/appcontrol/data/launch_mode');
index ade5d7d28ac29562ab23f580e1a1a3e376d9c375..730f3078ed675a32e6951abee105ed8a001a3fd9 100755 (executable)
@@ -91,7 +91,7 @@ class WebApplication {
     }
     resume() {
         console.log('WebApplication : resume');
-        if (!this.firstRendered) {
+        if (this.preloadState != 'none') {
             return;
         }
         BrowserWindow.getAllWindows().forEach((window) => {
@@ -117,6 +117,11 @@ class WebApplication {
             console.log('show browserWindow');
             this.mainWindow.show();
         }
+    closeWindows() {
+        BrowserWindow.getAllWindows().forEach((window) => {
+            if (window != this.mainWindow)
+                window.destroy();
+        });
     }
 }
 module.exports = WebApplication;