Skip to content

Commit 7710c5e

Browse files
committed
Add event listener for message events
Add handler for message events
1 parent bf36fe8 commit 7710c5e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/web/Manager.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class Manager {
125125
window.addEventListener("focus", this.window.windowFocus.bind(this.window));
126126
window.addEventListener("statechange", this.app.stateChange.bind(this.app));
127127
window.addEventListener("popstate", this.app.popState.bind(this.app));
128+
window.addEventListener("message", this.input.handlePostMessage.bind(this.input));
128129

129130
// Controls
130131
document.getElementById("bake").addEventListener("click", this.controls.bakeClick.bind(this.controls));

src/web/waiters/InputWaiter.mjs

+16
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,22 @@ class InputWaiter {
16541654
this.changeTab(inputNum, this.app.options.syncTabs);
16551655
}
16561656

1657+
/**
1658+
* Handler for incoming postMessages
1659+
* If the events data has a `type` property set to `dataSubmit`
1660+
* the value property is set to the current input
1661+
* @param {event} e
1662+
* @param {object} e.data
1663+
* @param {string} e.data.type - the type of request, currently the only value is "dataSubmit"
1664+
* @param {string} e.data.value - the value of the message
1665+
*/
1666+
handlePostMessage(e) {
1667+
if ("data" in e && "type" in e.data && "value" in e.data) {
1668+
if (e.data.type === "dataSubmit") {
1669+
this.setInput(e.data.value);
1670+
}
1671+
}
1672+
}
16571673
}
16581674

16591675
export default InputWaiter;

0 commit comments

Comments
 (0)