From 25db9704ce432d00281efefafae6eaecd4500682 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 14 Aug 2022 08:21:09 -0400 Subject: [PATCH] *Refactor background to start everything up in a boot function *Preload the dns and rpc subsystem with the dns ready call --- src/main/background.ts | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/main/background.ts b/src/main/background.ts index fb2a5bd..645b26b 100644 --- a/src/main/background.ts +++ b/src/main/background.ts @@ -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 { return new Promise((resolve) => { @@ -132,7 +132,6 @@ function handleKernelMessage(event: MessageEvent) { receiveResult(event.data); } -window.addEventListener("message", handleKernelMessage); function handleBridgeMessage( port: any, @@ -186,16 +185,25 @@ function bridgeListener(port: any) { }); }); } -browser.runtime.onConnect.addListener(bridgeListener); -const engine = new WebEngine(); -engine.registerContentProvider(new InternalProvider(engine)); -engine.registerContentProvider(new ServerProvider(engine)); -engine.registerContentProvider(new SkynetProvider(engine)); -engine.registerContentProvider(new IpfsProvider(engine)); +async function boot() { + tldEnum.list.push("localhost"); + window.addEventListener("message", handleKernelMessage); + browser.runtime.onConnect.addListener(bridgeListener); -// @ts-ignore -let kernelFrame: HTMLIFrameElement = document.createElement("iframe"); -kernelFrame.src = "http://kernel.skynet"; -kernelFrame.onload = init; -document.body.appendChild(kernelFrame); + const engine = new WebEngine(); + engine.registerContentProvider(new InternalProvider(engine)); + engine.registerContentProvider(new ServerProvider(engine)); + engine.registerContentProvider(new SkynetProvider(engine)); + 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();