_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');
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);
}
this.firstRendered = false;
this.backgroundSupport = wrt.getBackgroundSupport();
}
- close() {
- this.mainWindow.close();
- }
getBrowserWindowOption() {
return {
fullscreen: false,
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) => {
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;