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