const ADDONS_PATH = path.join(__dirname, '..', 'addon', 'browser', 'addonapi.js');
// A set of predefined events for addons
-let EventList = [
+const EventList = [
'newListener', // A listener is added via on() or addListener()
'removeListener', // A listener is removed via off() or removeListener()
'lcPrelaunch', // An app is at just before launching
class AddonManager {
constructor() {
+ this.registerAPIModule();
this.addons_list_ = null;
this.addons_ = null;
this.evt_emitter_ = null;
- this.registerAPIModule();
}
registerAPIModule() {
console.log('activate: ' + addon_path + ' name:' + name);
try {
let Addon = require(addon_path);
- addon = new Addon(this.evt_emitter_);
+ addon = new Addon(this.wrappedEventEmitter);
} catch (e) {
console.error('activate - error on require() : ' + e);
return;
console.log('deactivate: path:' + addon_path);
try {
let Addon = require(addon_path);
- addon = new Addon(this.evt_emitter_);
+ addon = new Addon(this.wrappedEventEmitter);
} catch (e) {
console.error('deactivate - error on require() : ' + e);
}
for (var name in this.addons_) {
this.activate(app, name);
}
- this.removeInvalidListener();
}
deactivateAll(app) {
initEventListener() {
this.evt_emitter_ = new EventEmitter();
- this.evt_emitter_.on('newListener', function(event, listener) {
- if (EventList.indexOf(event) != -1)
- console.log('Valid Event:' + event);
- else {
- console.log('Invalid Event:' + event);
+ this.wrappedEventEmitter = {
+ on: (eventName, listener) => {
+ if (EventList.indexOf(eventName) !== -1)
+ this.evt_emitter_.on(eventName, listener);
+ else console.log('Invalid Event: ' + eventName);
+ },
+ off: (eventName, listener) => {
+ if (EventList.indexOf(eventName) !== -1)
+ this.evt_emitter_.off(eventName, listener);
+ else console.log('Invalid Event: ' + eventName);
}
+ }
+
+ this.evt_emitter_.on('newListener', function(event, listener) {
+ console.log('A listener for ' + event + ' has been added');
});
this.evt_emitter_.on('removeListener', function(event, listener) {
});
}
- removeInvalidListener() {
- let activeEvents = this.evt_emitter_.eventNames();
- for (var i in activeEvents) {
- let item = activeEvents[i];
- if (EventList.indexOf(item) == -1) {
- console.log('Found invalid event(' + item + ')');
- if (this.evt_emitter_)
- this.evt_emitter_.removeAllListeners(item);
- else
- console.log('event listener is NOT valid');
- }
- }
- activeEvents = this.evt_emitter_.eventNames();
- console.log('Remained active events : ' + activeEvents);
- }
- existEventListeners(event) {
- let activeEvents = this.evt_emitter_.eventNames();
- if (activeEvents.indexOf(event) == -1)
- return false;
- else return true;
- }
-
static getManifestFile() {
return MANIFEST_FILE;
}
app.on('before-quit', function(event) {
console.log('before-quit');
if (!wrt.isElectronApp()) {
- _this.webApplication.quit(_this.addonManager.evt_emitter_);
+ _this.webApplication.quit();
_this.webApplication.finalize();
_this.webApplication = null;
}
src = "about:blank";
}
_this.webApplication.mainWindow.loadURL(src);
- _this.webApplication.prelaunch(_this.addonManager.evt_emitter_, src);
+ _this.webApplication.prelaunch(src);
} else {
console.log('Handling app-control event');
if (_this.webApplication.preloadStatus == 'readyToShow') {
wrt.on('suspend', function() {
console.log('suspend');
if (_this.webApplication)
- _this.webApplication.suspend(_this.addonManager.evt_emitter_);
+ _this.webApplication.suspend();
});
wrt.on('resume', function() {
console.log('resume');
if (_this.webApplication)
- _this.webApplication.resume(_this.addonManager.evt_emitter_);
+ _this.webApplication.resume();
});
wrt.on('low-memory', function() {
console.log('low-memory');
}
if (valid) {
- _this.webApplication.keyEvent(_this.addonManager.evt_emitter_, key);
+ _this.webApplication.keyEvent(key);
}
}
}
"profile log from the initial loading."
wrt.showDialog(this.mainWindow.webContents, message);
}
- suspend(evtEmitter) {
+ suspend() {
console.log('WebApplication : suspend');
- if (evtEmitter) {
+ if (this.addonEmitter) {
console.log('WebApplication : suspend - Found event emitter');
- evtEmitter.emit('lcSuspend', this.mainWindow.id);
+ this.addonEmitter.emit('lcSuspend', this.mainWindow.id);
} else {
console.log('WebApplication : suspend - Invalid event emitter');
}
}
this.windowList[this.windowList.length - 1].hide();
}
- resume(evtEmitter) {
+ resume() {
console.log('WebApplication : resume');
this.suspended = false;
- if (evtEmitter) {
+ if (this.addonEmitter) {
console.log('WebApplication : resume - Found event emitter');
- evtEmitter.emit('lcResume', this.mainWindow.id);
+ this.addonEmitter.emit('lcResume', this.mainWindow.id);
} else {
console.log('WebApplication : resume - Invalid event emitter');
}
window.removeAllListeners();
});
}
- quit(evtEmitter) {
+ quit() {
console.log('WebApplication : quit');
- if (evtEmitter) {
+ if (this.addonEmitter) {
console.log('WebApplication : quit - Found event emitter');
- evtEmitter.emit('lcQuit', this.mainWindow.id);
+ this.addonEmitter.emit('lcQuit', this.mainWindow.id);
} else {
console.log('WebApplication : quit - Invalid event emitter');
}
window.destroy();
});
}
- keyEvent(evtEmitter, key) {
+ keyEvent(key) {
console.log('WebApplication : keyEvent');
- if (!evtEmitter) {
+ if (!this.addonEmitter) {
console.log('Invalid event emitter for key hook');
return;
}
switch(key) {
case "ArrowUp":
case "Up":
- evtEmitter.emit('hwUpkey', this.mainWindow.id);
+ this.addonEmitter.emit('hwUpkey', this.mainWindow.id);
break;
case "ArrowDown":
case "Down":
- evtEmitter.emit('hwDownkey', this.mainWindow.id);
+ this.addonEmitter.emit('hwDownkey', this.mainWindow.id);
break;
default:
console.log('No handler for ' + key);
break;
}
}
- prelaunch(evtEmitter, origURL) {
+ prelaunch(origURL) {
console.log('WebApplication : prelaunch');
- if (evtEmitter) {
+ if (this.addonEmitter) {
console.log('WebApplication : prelaunch - Found event emitter');
- evtEmitter.emit('lcPrelaunch', this.mainWindow.id, origURL);
+ this.addonEmitter.emit('lcPrelaunch', this.mainWindow.id, origURL);
} else {
console.log('WebApplication : prelaunch - Invalid event emitter');
}