Files
Netcatty/electron/plugins/runtime/browserPreload.cjs
T
ryan-wong-coder 7a47187e37 feat(plugins): add isolated plugin host runtime (#2303)
* feat(plugins): add isolated plugin host runtime

* test(plugins): build runtime dependencies before tests

* fix(plugins): harden runtime lifecycle and recovery

* fix(plugins): harden runtime extension boundaries

* fix(plugins): enforce runtime integrity boundaries

* fix(plugins): await utility process exit

* fix(plugins): harden utility process containment

* fix(plugins): close runtime recovery gaps

* fix(plugins): harden runtime lifecycle boundaries
2026-07-19 08:22:17 +08:00

33 lines
877 B
JavaScript

"use strict";
const { ipcRenderer } = require("electron");
let hostPort;
let runtimeReady = false;
function connectRuntime() {
if (!hostPort || !runtimeReady) return;
const port = hostPort;
hostPort = undefined;
window.postMessage({
type: "netcatty-plugin:connect",
runtimeToken: window.location.hostname,
}, "*", [port]);
}
window.addEventListener("message", (event) => {
if (event.data?.runtimeToken !== window.location.hostname) return;
if (event.data?.type === "netcatty-plugin:runtime-ready") {
runtimeReady = true;
connectRuntime();
} else if (event.data?.type === "netcatty-plugin:runtime-connected") {
ipcRenderer.send("netcatty-plugin:runtime-connected");
}
});
ipcRenderer.once("netcatty-plugin:connect", (event) => {
hostPort = event.ports?.[0];
connectRuntime();
});
ipcRenderer.send("netcatty-plugin:preload-ready");