Fixes #522
This commit is contained in:
@@ -37,6 +37,7 @@ import { MessageQueue } from "../plugos/lib/mq.ts";
|
||||
import { languageSyscalls } from "../common/syscalls/language.ts";
|
||||
import { handlebarsSyscalls } from "../common/syscalls/handlebars.ts";
|
||||
import { codeWidgetSyscalls } from "./syscalls/code_widget.ts";
|
||||
import { clientCodeWidgetSyscalls } from "./syscalls/client_code_widget.ts";
|
||||
|
||||
export class ClientSystem {
|
||||
commandHook: CommandHook;
|
||||
@@ -144,6 +145,7 @@ export class ClientSystem {
|
||||
yamlSyscalls(),
|
||||
handlebarsSyscalls(),
|
||||
codeWidgetSyscalls(this.codeWidgetHook),
|
||||
clientCodeWidgetSyscalls(),
|
||||
languageSyscalls(),
|
||||
this.client.syncMode
|
||||
// In sync mode handle locally
|
||||
|
||||
@@ -77,13 +77,29 @@ function claimIFrame(): PreloadedIFrame {
|
||||
}
|
||||
}
|
||||
// Nothing available in the pool, let's spin up a new one and add it to the pool
|
||||
console.log("Yeah this shouldn't happen");
|
||||
console.warn("Had to create a new iframe on the fly, this shouldn't happen");
|
||||
const newPreloadedIFrame = prepareSandboxIFrame();
|
||||
newPreloadedIFrame.used = true;
|
||||
iframePool.add(newPreloadedIFrame);
|
||||
return newPreloadedIFrame;
|
||||
}
|
||||
|
||||
export function broadcastReload() {
|
||||
for (const preloadedIframe of iframePool) {
|
||||
if (preloadedIframe.used) {
|
||||
// Send a message to the global object, which the iframe is listening to
|
||||
globalThis.dispatchEvent(
|
||||
new MessageEvent("message", {
|
||||
source: preloadedIframe.iframe.contentWindow,
|
||||
data: {
|
||||
type: "reload",
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function mountIFrame(
|
||||
preloadedIFrame: PreloadedIFrame,
|
||||
client: Client,
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { CodeWidgetContent } from "$sb/types.ts";
|
||||
import { SysCallMapping } from "../../plugos/system.ts";
|
||||
import { broadcastReload } from "../components/widget_sandbox_iframe.ts";
|
||||
|
||||
export function clientCodeWidgetSyscalls(): SysCallMapping {
|
||||
return {
|
||||
"codeWidget.refreshAll": () => {
|
||||
broadcastReload();
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user