this.addons_list_ = null;
this.addons_ = null;
this.addons_API_ = null;
+ this.prelaunch_path = null;
+ this.resume_path = null;
+ this.suspend_path = null;
+ this.quit_path = null;
+ this.arrowup_path = null;
+ this.arrowdown_path = null;
}
printAPIs() {
return true;
}
+ registerLifecycles(lifecycles, path) {
+ if (!lifecycles) {
+ console.log('lifecycle is not declared');
+ return;
+ }
+ if (lifecycles.prelaunch) {
+ this.prelaunch_path = path;
+ console.log('prelaunch operation path :' + this.prelaunch_path);
+ }
+ if (lifecycles.resume) {
+ this.resume_path = path;
+ console.log('resume override path :' + this.resume_path);
+ }
+ if (lifecycles.suspend) {
+ this.suspend_path = path;
+ console.log('suspend override path :' + this.suspend_path);
+ }
+ if (lifecycles.quit) {
+ this.quit_path = path;
+ console.log('quit operation path :' + this.quit_path);
+ }
+ }
+
+ registerEvents(events, path) {
+ if (!events) {
+ console.log('event is not declared');
+ return;
+ }
+ if (events.arrowup) {
+ this.arrowup_path = path;
+ console.log('arrowup operation path :' + this.arrowup_path);
+ }
+ if (events.arrowdown) {
+ this.arrowdown_path = path;
+ console.log('arrowdown operation path :' + this.arrowdown_path);
+ }
+ }
+
build() {
// 0. load addons_list_ from JSON DB
this.loadJsonDB();
addons[type][manifest_obj.name] = addon.path;
}
}
+
+ let addon_path = path.join(addon.path, manifest_obj.name) + '.js';
+ this.registerLifecycles(manifest_obj.lifecycle, addon_path);
+ this.registerEvents(manifest_obj.event, addon_path);
+
console.log('addons[' + type + '][' + manifest_obj.name + '] = ' + addons[type][manifest_obj.name] + ' registered');
} catch (e) {
console.error('AddonManager.build error - ' + e);
this.isLaunched = false;
this.debug_mode = false;
this.need_inspector = false;
+ this.webContents = null;
+ this.allowQuit = false;
var _this = this;
app.on('before-quit', function(event) {
console.log('before-quit');
+ if (!wrt.isElectronApp()) {
+ if (_this.addonManager.quit_path && !_this.allowQuit) {
+ event.preventDefault();
+ let timeout = _this.webApplication.quit(_this.addonManager.quit_path);
+ _this.allowQuit = true;
+ if (timeout >= 0)
+ setTimeout(function() {
+ app.quit();
+ }, timeout, null);
+ }
+ }
});
app.on('will-quit', function(event) {
console.log('will-quit');
app.on('will-finish-launching', function(event) {
console.log('will-finish-launching');
});
+ app.on('web-contents-created', function(event, webContents) {
+ console.log('web-contents-created');
+ _this.webContents = webContents;
+ _this.webContents.on('before-input-event', function(event, input) {
+ if (_this.isLaunched && _this.webApplication) {
+ _this.handleKeyEvents(input.key);
+ }
+ });
+ });
app.once('ready', function(event) {
console.log('ready');
_this.addonManager = new AddonManager();
options.launchMode = appControl.getData('http://samsung.com/appcontrol/data/launch_mode');
_this.webApplication = new WebApplication(options);
_this.webApplication.mainWindow.loadURL(src);
+ _this.webApplication.prelaunch(_this.addonManager.prelaunch_path, src);
} else {
console.log('Handling app-control event');
if (_this.webApplication.preloadState == 'readyToShow') {
});
wrt.on('suspend', function() {
console.log('suspend');
- _this.webApplication.suspend();
+ _this.webApplication.suspend(_this.addonManager.suspend_path);
});
wrt.on('resume', function() {
console.log('resume');
- _this.webApplication.resume();
+ _this.webApplication.resume(_this.addonManager.resume_path);
});
wrt.on('terminate', function() {
console.log('terminate');
}
appControl.reply(data);
}
+ handleKeyEvents(key) {
+ let path = null;
+ let _this = this;
+
+ console.log(key + ' is pressed');
+ switch(key) {
+ case "ArrowUp":
+ case "Up":
+ path = _this.addonManager.arrowup_path;
+ break;
+ case "ArrowDown":
+ case "Down":
+ path = _this.addonManager.arrowdown_path;
+ break;
+ default:
+ console.log('No handler for the key ' + key);
+ break;
+ }
+ console.log('Path for ' + key + ' : ' + path);
+ if (path) {
+ _this.webApplication.keyEvent(key, path);
+ }
+ }
}
module.exports = Runtime;
}
});
}
- suspend() {
+ suspend(path) {
console.log('WebApplication : suspend');
+ if (path != null) {
+ let addon = require(path);
+ console.log('addon for suspend is ' + path);
+ if (addon.suspend) {
+ console.log('addon for suspend is found');
+ addon.suspend(this.mainWindow.id, path);
+ } else {
+ console.log('addon for suspend is NOT found');
+ }
+ }
this.suspended = true;
if (this.isTerminating) {
console.log('App has been terminated; return');
}
this.windowList[this.windowList.length - 1].hide();
}
- resume() {
+ resume(path) {
console.log('WebApplication : resume');
this.suspended = false;
if (!this.firstRendered) {
console.log('WebApplication : resume firstRendered is false');
+ if (path != null) {
+ let addon = require(path);
+ console.log('addon for resume is ' + path);
+ if (addon.resume) {
+ console.log('addon for resume is found');
+ addon.resume(this.mainWindow.id, path);
+ } else {
+ console.log('addon for resume is NOT found');
+ }
+ }
return;
}
WRTWindow.getAllWindows().forEach((window) => {
terminate() {
this.isTerminating = true;
}
+ quit(path) {
+ console.log('WebApplication : quit');
+ let timeout = -1;
+ if (path != null) {
+ let addon = require(path);
+ console.log('addon for quit is ' + path);
+ if (addon.quit) {
+ console.log('addon for quit is found');
+ timeout = addon.quit(this.mainWindow.id, path);
+ } else {
+ console.log('addon for quit is NOT found');
+ }
+ }
+ return timeout;
+ }
sendAppControlEvent() {
const kAppControlEventScript =
'(function(){' +
window.destroy();
});
}
+ keyEvent(key, path) {
+ console.log('WebApplication : keyEvent');
+ if (!path) {
+ console.log('no path for event hook exists');
+ return;
+ }
+ let addon = require(path);
+ console.log('event is hooked for ' + path);
+ switch(key) {
+ case "ArrowUp":
+ case "Up":
+ if (addon.arrowup) {
+ console.log('arrowup is found');
+ addon.arrowup(this.mainWindow.id);
+ } else {
+ console.log('arrowup is NOT found');
+ }
+ break;
+ case "ArrowDown":
+ case "Down":
+ if (addon.arrowdown) {
+ console.log('arrowdown is found');
+ addon.arrowdown(this.mainWindow.id);
+ } else {
+ console.log('arrowdown is NOT found');
+ }
+ break;
+ default:
+ console.log('No handler for ' + key);
+ break;
+ }
+ }
+ prelaunch(path, origURL) {
+ console.log('WebApplication : prelaunch');
+ if (path != null) {
+ let addon = require(path);
+ console.log('addon for additional runtime is ' + path);
+ console.log('prelaunch : org URL : ' + origURL);
+ if (addon.prelaunch) {
+ console.log('prelaunch is found');
+ addon.prelaunch(this.mainWindow.id, origURL);
+ } else {
+ console.log('prelaunch is NOT found');
+ }
+ }
+ }
}
module.exports = WebApplication;