From: SangYong Park Date: Thu, 7 Mar 2019 09:55:04 +0000 (+0900) Subject: Implement app control handler X-Git-Tag: submit/tizen/20190314.082855~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9c35489bfb52fa68288286bae1357ce81d7c44b7;p=platform%2Fframework%2Fweb%2Fwrtjs.git Implement app control handler Change-Id: Ieeba1a9a77fcdaaa2da168b5f04f495859aa5e64 Signed-off-by: SangYong Park --- diff --git a/wrt_app/src/runtime.js b/wrt_app/src/runtime.js index 109341e8..2f58fd04 100755 --- a/wrt_app/src/runtime.js +++ b/wrt_app/src/runtime.js @@ -76,17 +76,32 @@ class Runtime { _this.extensionManager.build(); } }); - wrt.on('app-control', function() { + wrt.on('app-control', function(event, appControl) { console.log('app-control'); + let loadInfo = appControl.getLoadInfo(); + let src = loadInfo.getSrc(); if (_this.webApplication) { - // TODO: Reset application or emit appcontrol event - console.log("application is already created"); - 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"); - let filePath = wrt.getPath(); + let filePath = src; let pkgJson = require(filePath.substr(7, filePath.length - 12)); let mainJsPath = filePath.substr(7, filePath.length - 19) + (pkgJson.main || 'index.js'); @@ -96,7 +111,7 @@ class Runtime { app.emit('ready'); } else { _this.webApplication = new WebApplication(options); - _this.webApplication.loadURL(); + _this.webApplication.mainWindow.loadURL(src); if (wrt.appID !== 'NVPDzvckj9.RuntimeAddonSetting') { _this.extensionManager.activateAll(app); } diff --git a/wrt_app/src/web_application.js b/wrt_app/src/web_application.js index e3cf6dac..70a8afc3 100755 --- a/wrt_app/src/web_application.js +++ b/wrt_app/src/web_application.js @@ -35,9 +35,6 @@ class WebApplication { this.firstRendered = false; this.backgroundSupport = wrt.getBackgroundSupport(); } - close() { - this.mainWindow.close(); - } getBrowserWindowOption() { return { fullscreen: false, @@ -80,10 +77,6 @@ class WebApplication { console.log('webContents did-finish-load'); }); } - loadURL(url) { - console.log('loadURL'); - this.mainWindow.loadURL(url ? url : wrt.getPath()); - } suspend() { console.log('WebApplication : suspend'); BrowserWindow.getAllWindows().forEach((window) => { @@ -103,5 +96,16 @@ class WebApplication { window.setEnabled(true); }); } + sendAppControlEvent() { + const kAppControlEventScript = + '(function(){' + + 'var __event = document.createEvent("CustomEvent");' + + '__event.initCustomEvent("appcontrol", true, true, null);' + + 'document.dispatchEvent(__event);' + + 'for (var i=0; i < window.frames.length; i++)' + + 'window.frames[i].document.dispatchEvent(__event);' + + '})()'; + wrt.executeJS(this.mainWindow.webContents, kAppControlEventScript); + } } module.exports = WebApplication;