*Support calling modules from the background page
This commit is contained in:
parent
fa97cba286
commit
f394776a72
|
@ -55,6 +55,20 @@ function handleKernelMessage(event: MessageEvent) {
|
|||
}
|
||||
let data = event.data.data;
|
||||
|
||||
if (event.data.method === "kernelBridgeVersion") {
|
||||
for (let [, port] of Object.entries(openPorts)) {
|
||||
try {
|
||||
(port as any).postMessage(event.data);
|
||||
} catch {}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.origin !== "http://kernel.skynet") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.data.method === "log") {
|
||||
if (data.isErr === false) {
|
||||
console.log(data.message);
|
||||
|
@ -118,6 +132,11 @@ function handleBridgeMessage(
|
|||
return;
|
||||
}
|
||||
|
||||
if (data.method === "response") {
|
||||
window.postMessage(data);
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.method !== "queryUpdate") {
|
||||
queries[data.nonce] = (response: any) => {
|
||||
if (portNonce in openPorts) {
|
||||
|
|
|
@ -49,14 +49,17 @@ port.onMessage.addListener(handleBackgroundMessage);
|
|||
// appeared which will need the auth status of the kernel repeated.
|
||||
function handleVersion(data: any) {
|
||||
// Send a message indicating that the bridge is alive.
|
||||
window.postMessage({
|
||||
const message = {
|
||||
nonce: data.nonce,
|
||||
method: "response",
|
||||
err: null,
|
||||
data: {
|
||||
version: "v0.2.0",
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
window.postMessage(message);
|
||||
port.postMessage(message);
|
||||
|
||||
// Wait until the kernel auth status is known, then send a message with
|
||||
// the kernel auth status.
|
||||
|
|
Reference in New Issue