diff --git a/plugs/core/debug.ts b/plugs/core/debug.ts index ccfa62c..0587793 100644 --- a/plugs/core/debug.ts +++ b/plugs/core/debug.ts @@ -60,7 +60,7 @@ export async function showLogsCommand() { serverDiv.scrollTop = serverDiv.scrollHeight; self.close = () => { - sendEvent("log:hide"); + syscall("event.dispatch", "log:hide"); }; syscall("system.getEnv").then((env) => { diff --git a/plugs/markdown/assets/handler.js b/plugs/markdown/assets/handler.js index 3114713..d685791 100644 --- a/plugs/markdown/assets/handler.js +++ b/plugs/markdown/assets/handler.js @@ -1,9 +1,15 @@ document.getElementById("root").addEventListener("click", (e) => { // console.log("Got click", e.target) const dataSet = e.target.dataset; - if(dataSet["onclick"]) { - sendEvent("preview:click", dataSet["onclick"]); - } else if(dataSet["pos"]) { - sendEvent("preview:click", JSON.stringify(["pos", dataSet["pos"]])); + if (dataSet["onclick"]) { + syscall("event.dispatch", "preview:click", dataSet["onclick"]).catch((e) => + console.log("Error", e) + ); + } else if (dataSet["pos"]) { + syscall( + "event.dispatch", + "preview:click", + JSON.stringify(["pos", dataSet["pos"]]) + ).catch((e) => console.log("Error", e)); } -}) \ No newline at end of file +}); diff --git a/web/components/panel.tsx b/web/components/panel.tsx index d494e05..1193256 100644 --- a/web/components/panel.tsx +++ b/web/components/panel.tsx @@ -62,6 +62,7 @@ window.addEventListener("message", (message) => { } }); +// DEPRECATED: Use syscall("event.dispatch", ...) instead function sendEvent(name, ...args) { window.parent.postMessage({ type: "event", name, args, }, "*"); } @@ -137,12 +138,20 @@ export function Panel({ case "syscall": { const { id, name, args } = data; editor.system.localSyscall("core", name, args).then((result) => { + if (!iFrameRef.current?.contentWindow) { + // iFrame already went away + return; + } iFrameRef.current!.contentWindow!.postMessage({ type: "syscall-response", id, result, }); }).catch((e: any) => { + if (!iFrameRef.current?.contentWindow) { + // iFrame already went away + return; + } iFrameRef.current!.contentWindow!.postMessage({ type: "syscall-response", id,