Last active
March 1, 2022 12:33
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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