From 0eb3209aa2d5d10b6fc8753fb624132d30e50ed4 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 20 Jul 2023 12:44:31 -0400 Subject: [PATCH] refactor: change bootup process to setup all modules when authStatus is emitted and loginComplete is true --- src/main/background/boot.ts | 60 +++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/src/main/background/boot.ts b/src/main/background/boot.ts index e14358a..cc50619 100644 --- a/src/main/background/boot.ts +++ b/src/main/background/boot.ts @@ -6,29 +6,65 @@ import WebEngine from "../../webEngine.js"; import InternalProvider from "../../contentProviders/internalProvider.js"; import IpfsProvider from "../../contentProviders/ipfsProvider.js"; import ServerProvider from "../../contentProviders/serverProvider.js"; -import { getKernelIframe, setKernelIframe, weAreBooted } from "../../vars.js"; +import { events, getKernelIframe, setKernelIframe } from "../../vars.js"; import { init } from "@lumeweb/libkernel/kernel"; +import { + dnsClient, + ethClient, + handshakeClient, + ipfsClient, + networkRegistryClient, + peerDiscoveryClient, + swarmClient, +} from "../../clients.js"; +import { KernelAuthStatus } from "@lumeweb/libweb"; + +let engine: WebEngine; export async function boot() { tldEnum.list.push("localhost"); window.addEventListener("message", handleKernelMessage); browser.runtime.onConnect.addListener(bridgeListener); - const engine = new WebEngine(); + engine = new WebEngine(); engine.registerContentProvider(new InternalProvider(engine)); - engine.registerContentProvider(new IpfsProvider(engine)); - engine.registerContentProvider(new ServerProvider(engine)); - setKernelIframe(document.createElement("iframe")); getKernelIframe().src = "http://kernel.lume"; - await new Promise((resolve) => { - getKernelIframe().onload = () => { - init().then(resolve); - }; - document.body.appendChild(getKernelIframe()); + getKernelIframe().onload = init; + document.body.appendChild(getKernelIframe()); + events.on("authStatus", async (changes: KernelAuthStatus) => { + if (changes.loginComplete) { + await doInit(); + } }); - - weAreBooted(); +} + +export async function doInit() { + engine.registerContentProvider(new IpfsProvider(engine)); + engine.registerContentProvider(new ServerProvider(engine)); + + await swarmClient.addRelay( + "2d7ae1517caf4aae4de73c6d6f400765d2dd00b69d65277a29151437ef1c7d1d", + ); + // IRC + await peerDiscoveryClient.register( + "zduL5de7GC5DVpf92FkShUZZrTpUi6hki2BaTaVwjs9cnmCmKWNywBWyHR", + ); + + await networkRegistryClient.registerType("content"); + await networkRegistryClient.registerType("blockchain"); + await handshakeClient.register(); + await ethClient.register(); + await ipfsClient.register(); + + const resolvers = [ + "zduR2MPhx4qMxNwmM2GzFBdbgr1gvA33iM9Ve8RxL4SF4msWAy9RwiDGjq", // ENS + "zduMGDuZ1juBTn6sNS4J1eT81wb8RMswacXEVGmgWKm8snY7viketDsYsZ", // HNS + ]; + + for (const resolver of resolvers) { + await dnsClient.registerResolver(resolver); + } }