Skip to content

Commit 497e2a9

Browse files
authored
Merge pull request #1992 from kenduguay1/push-input-through-postmessage
2 parents 7c8be12 + 85a3a18 commit 497e2a9

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-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

+17
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,23 @@ 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+
log.debug(e);
1668+
if ("data" in e && "id" in e.data && "value" in e.data) {
1669+
if (e.data.id === "setInput") {
1670+
this.setInput(e.data.value);
1671+
}
1672+
}
1673+
}
16571674
}
16581675

16591676
export default InputWaiter;

0 commit comments

Comments
 (0)