Skip to content

Instantly share code, notes, and snippets.

@dowmeister
Last active March 1, 2022 12:33
Show Gist options
  • Select an option

  • Save dowmeister/cb1f8cb9ec99b211a9e0a3f8829e211a to your computer and use it in GitHub Desktop.

Select an option

Save dowmeister/cb1f8cb9ec99b211a9e0a3f8829e211a to your computer and use it in GitHub Desktop.
Overwolf - EventBus example with trigger to close the app from the main visible window
// event-bus.js
let _listeners = [];
function addListener(eventName, eventHandler) {
_listeners.push({ eventName: eventName, handler: eventHandler });
}
function trigger(eventName, data, log = false) {
for (let listener of _listeners) {
if (listener.eventName == eventName)
{
listener.handler(data);
}
}
}
export default {
addListener,
trigger
}
// background.js
import EventBus from "../../common/services/event-bus";
window.eventBus = EventBus;
window.eventBus.addListener(Events.CLOSE_APP, this.onCloseApp.bind(this));
onCloseApp() {
window.close();
}
// mainwindow.js
let background = overwolf.windows.getMainWindow();
background.eventBus.trigger(Events.CLOSE_APP);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment