mirror of
https://github.com/ankitects/anki.git
synced 2025-11-06 12:47:11 -05:00
pycmd relay example
This commit is contained in:
parent
69097ebb50
commit
b6e07f5780
2 changed files with 20 additions and 9 deletions
|
|
@ -34,3 +34,8 @@ addEventListener("message", (e) => {
|
|||
const base = document.createElement("base");
|
||||
base.href = "/";
|
||||
document.head.appendChild(base);
|
||||
|
||||
function pycmd(cmd: string) {
|
||||
window.parent.postMessage({ type: "pycmd", value: cmd }, "*");
|
||||
}
|
||||
globalThis.pycmd = pycmd;
|
||||
|
|
|
|||
|
|
@ -19,26 +19,32 @@ export function setupReviewer(iframe: HTMLIFrameElement) {
|
|||
}
|
||||
|
||||
function onReady() {
|
||||
// TODO This should probably be a "ready" command now that it is part of the actual reviewer,
|
||||
// Currently this depends on the reviewer component mounting after the bottom-reviewer which it should but seems hacky.
|
||||
// Maybe use a counter with a counter.subscribe($counter == 2 then call("ready"))
|
||||
bridgeCommand("bottomReady");
|
||||
iframe.contentWindow?.postMessage({ type: "nightMode", value: true }, "*");
|
||||
}
|
||||
|
||||
iframe?.addEventListener("load", onReady);
|
||||
|
||||
/* addEventListener("message", (e) => {
|
||||
addEventListener("message", (e) => {
|
||||
switch (e.data.type) {
|
||||
case "ready":
|
||||
// TODO This should probably be a "ready" command now that it is part of the actual reviewer,
|
||||
// Currently this depends on the reviewer component mounting after the bottom-reviewer which it should but seems hacky.
|
||||
// Maybe use a counter with a counter.subscribe($counter == 2 then call("ready"))
|
||||
bridgeCommand("bottomReady");
|
||||
iframe.contentWindow?.postMessage({ type: "nightMode", value: true });
|
||||
case "pycmd": {
|
||||
const cmd = e.data.value as string;
|
||||
if (cmd.startsWith("play:")) {
|
||||
bridgeCommand(e.data.value);
|
||||
} else {
|
||||
console.error("pycmd command is either invalid or forbidden:", cmd);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
default: {
|
||||
console.warn(`Unknown message type: ${e.data.type}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}); */
|
||||
});
|
||||
|
||||
globalThis._showAnswer = updateHtml;
|
||||
globalThis._showQuestion = showQuestion;
|
||||
|
|
|
|||
Loading…
Reference in a new issue