fixup! Implement app control handler 87/201387/6
authorsurya.kumar7 <surya.kumar7@samsung.com>
Wed, 27 Mar 2019 09:44:35 +0000 (15:14 +0530)
committersurya.kumar7 <surya.kumar7@samsung.com>
Fri, 29 Mar 2019 05:11:28 +0000 (10:41 +0530)
Modified certain code to prevent inadvertent app exit, wrong
sequence and fixed an undefined object

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

index 76a58e7548972d4e8ab46a0432d6c143c3da9019..eb4559226b859d0b1b13157a0e4d3b60985f49ef 100755 (executable)
@@ -82,61 +82,61 @@ class Runtime {
             let loadInfo = appControl.getLoadInfo();
             let src = loadInfo.getSrc();
 
-            if (_this.webApplication) {
-                if (_this.webApplication.preloadState == 'readyToShow') {
-                    _this.webApplication.show();
-                }
-
-                let launchMode = appControl.getData('http://samsung.com/appcontrol/data/launch_mode');
-                if (launchMode != 'backgroundAtStartup') {
-                    _this.webApplication.preloadState = 'none';
-                }
-
-                let skipReload = appControl.getData('SkipReload');
-                if (skipReload == 'Yes') {
-                    console.log('skipping reload');
-                    _this.webApplication.resume();
-                    return;
-                }
-
-                let reload = loadInfo.getReload();
-                if (!reload) {
-                    if (src != _this.webApplication.mainWindow.getURL())
-                        reload = true;
-                }
-                // handle http://tizen.org/appcontrol/operation/main operation specially.
-                // only menu-screen app can send launch request with main operation.
-                // in this case, web app should have to resume web app not reset.
-                if (reload && appControl.getOperation() == 'http://tizen.org/appcontrol/operation/main')
-                    reload = false;
-                if (reload) {
-                    _this.webApplication.mainWindow.destroy();
-                    _this.webApplication = nullptr;
-                } else {
-                    _this.webApplication.sendAppControlEvent();
-                }
-            }
-
             if (wrt.isElectronApp()) {
-                console.log("Electron App launch");
-                require('module').globalPaths.push(wrt.getAppPath());
+                console.log('Electron App launch');
+                const Module = require('module');
+                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');
+                console.log('loading path:', mainJsPath);
                 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');
-                if (launchMode == 'backgroundAtStartup') {
-                    console.log('backgroundAtStartup');
-                    _this.webApplication.preloadState = "preload";
+                console.log('Tizen Web App launch');
+                if (!_this.webApplication) {
+                    console.log('Creating WebApplication');
+                    options.launchMode = appControl.getData('http://samsung.com/appcontrol/data/launch_mode');
+                    _this.webApplication = new WebApplication(options);
+                    _this.webApplication.mainWindow.loadURL(src);
+                } else {
+                    console.log('Handling app-control event');
+                    if (_this.webApplication.preloadState == 'readyToShow') {
+                        _this.webApplication.show();
+                    } else {
+                        let launchMode = appControl.getData('http://samsung.com/appcontrol/data/launch_mode');
+                        if (launchMode != 'backgroundAtStartup') {
+                            _this.webApplication.preloadState = 'none';
+                        }
+                    }
+
+                    let skipReload = appControl.getData('SkipReload');
+                    if (skipReload == 'Yes') {
+                        console.log('skipping reload');
+                        _this.webApplication.resume();
+                        return;
+                    }
+
+                    let reload = loadInfo.getReload();
+                    if (!reload) {
+                        if (src != _this.webApplication.mainWindow.getURL())
+                            reload = true;
+                    }
+                    // handle http://tizen.org/appcontrol/operation/main operation specially.
+                    // only menu-screen app can send launch request with main operation.
+                    // in this case, web app should have to resume web app not reset.
+                    if (reload && appControl.getOperation() == 'http://tizen.org/appcontrol/operation/main')
+                        reload = false;
+                    if (reload) {
+                        _this.webApplication.closeWindows();
+                        _this.webApplication.mainWindow.loadURL(src);
+                    } else {
+                        _this.webApplication.sendAppControlEvent();
+                    }
                 }
-                _this.webApplication.mainWindow.loadURL(src);
             }
             // FIX ME : It must be supplemented to set a specific path
             wrt.setCookiePath();
index 23d8cd8540a37ca0e0d960781a0dbbacd071c021..b9c9e3a13fcb8c6be700c75c8dcc8ade2fc696df 100755 (executable)
@@ -33,9 +33,14 @@ class WebApplication {
         console.log('mainWindow id : ' + this.mainWindow.id);
         this.handleEvents(winopt);
         this.firstRendered = false;
-        this.preloadState = 'none';
         this.backgroundSupport = wrt.getBackgroundSupport();
         this.multitaskingSupport = wrt.getMultitaskingSupport();
+        if (options.launchMode == 'backgroundAtStartup') {
+            console.log('backgroundAtStartup');
+            this.preloadState = 'preload';
+        } else {
+            this.preloadState = 'none';
+        }
     }
     getBrowserWindowOption() {
         return {
@@ -125,5 +130,11 @@ class WebApplication {
             this.mainWindow.show();
         }
     }
+    closeWindows() {
+        BrowserWindow.getAllWindows().forEach((window) => {
+            if (window != this.mainWindow)
+                window.destroy();
+        });
+    }
 }
 module.exports = WebApplication;