*Refactor background to start everything up in a boot function

*Preload the dns and rpc subsystem with the dns ready call
This commit is contained in:
Derrick Hammer 2022-08-14 08:21:09 -04:00
parent 5be2d72d48
commit 25db9704ce
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 22 additions and 14 deletions

View File

@ -6,6 +6,7 @@ import SkynetProvider from "../contentProviders/skynetProvider.js";
import ServerProvider from "../contentProviders/serverProvider.js";
import { init } from "libkernel";
import IpfsProvider from "../contentProviders/ipfsProvider.js";
import { ready as dnsReady } from "@lumeweb/kernel-dns-client";
declare var browser: any; // tsc
let queriesNonce = 1;
@ -38,8 +39,7 @@ let blockForBootloader = new Promise((resolve) => {
let blockForBridge = new Promise((resolve) => {
bridgeLoadedResolve = resolve;
});
tldEnum.list.push("localhost");
let kernelFrame: HTMLIFrameElement;
export function queryKernel(query: any): Promise<any> {
return new Promise((resolve) => {
@ -132,7 +132,6 @@ function handleKernelMessage(event: MessageEvent) {
receiveResult(event.data);
}
window.addEventListener("message", handleKernelMessage);
function handleBridgeMessage(
port: any,
@ -186,6 +185,10 @@ function bridgeListener(port: any) {
});
});
}
async function boot() {
tldEnum.list.push("localhost");
window.addEventListener("message", handleKernelMessage);
browser.runtime.onConnect.addListener(bridgeListener);
const engine = new WebEngine();
@ -195,7 +198,12 @@ engine.registerContentProvider(new SkynetProvider(engine));
engine.registerContentProvider(new IpfsProvider(engine));
// @ts-ignore
let kernelFrame: HTMLIFrameElement = document.createElement("iframe");
kernelFrame = document.createElement("iframe");
kernelFrame.src = "http://kernel.skynet";
kernelFrame.onload = init;
document.body.appendChild(kernelFrame);
await dnsReady();
}
boot();