From: surya.kumar7 Date: Wed, 27 Mar 2019 09:44:35 +0000 (+0530) Subject: fixup! Implement app control handler X-Git-Tag: submit/tizen/20190412.025133~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ad5e83d0915f6b8e47e96b44c3a2ca37c207f99b;p=platform%2Fframework%2Fweb%2Fwrtjs.git fixup! Implement app control handler Modified certain code to prevent inadvertent app exit, wrong sequence and fixed an undefined object Change-Id: I190356693087650608d0bae356c8b95ce97d8a6d Signed-off-by: surya.kumar7 --- diff --git a/wrt_app/src/runtime.js b/wrt_app/src/runtime.js index 76a58e75..eb455922 100755 --- a/wrt_app/src/runtime.js +++ b/wrt_app/src/runtime.js @@ -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(); diff --git a/wrt_app/src/web_application.js b/wrt_app/src/web_application.js index 23d8cd85..b9c9e3a1 100755 --- a/wrt_app/src/web_application.js +++ b/wrt_app/src/web_application.js @@ -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;