mirror of
https://github.com/ankitects/anki.git
synced 2025-11-06 20:57:13 -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");
|
const base = document.createElement("base");
|
||||||
base.href = "/";
|
base.href = "/";
|
||||||
document.head.appendChild(base);
|
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() {
|
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");
|
bridgeCommand("bottomReady");
|
||||||
iframe.contentWindow?.postMessage({ type: "nightMode", value: true }, "*");
|
iframe.contentWindow?.postMessage({ type: "nightMode", value: true }, "*");
|
||||||
}
|
}
|
||||||
|
|
||||||
iframe?.addEventListener("load", onReady);
|
iframe?.addEventListener("load", onReady);
|
||||||
|
|
||||||
/* addEventListener("message", (e) => {
|
addEventListener("message", (e) => {
|
||||||
switch (e.data.type) {
|
switch (e.data.type) {
|
||||||
case "ready":
|
case "pycmd": {
|
||||||
// TODO This should probably be a "ready" command now that it is part of the actual reviewer,
|
const cmd = e.data.value as string;
|
||||||
// Currently this depends on the reviewer component mounting after the bottom-reviewer which it should but seems hacky.
|
if (cmd.startsWith("play:")) {
|
||||||
// Maybe use a counter with a counter.subscribe($counter == 2 then call("ready"))
|
bridgeCommand(e.data.value);
|
||||||
bridgeCommand("bottomReady");
|
} else {
|
||||||
iframe.contentWindow?.postMessage({ type: "nightMode", value: true });
|
console.error("pycmd command is either invalid or forbidden:", cmd);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
}
|
||||||
|
default: {
|
||||||
console.warn(`Unknown message type: ${e.data.type}`);
|
console.warn(`Unknown message type: ${e.data.type}`);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}); */
|
});
|
||||||
|
|
||||||
globalThis._showAnswer = updateHtml;
|
globalThis._showAnswer = updateHtml;
|
||||||
globalThis._showQuestion = showQuestion;
|
globalThis._showQuestion = showQuestion;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue