refactor: change bootup process to setup all modules when authStatus is emitted and loginComplete is true

This commit is contained in:
Derrick Hammer 2023-07-20 12:44:31 -04:00
parent 501b208ade
commit 0eb3209aa2
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 48 additions and 12 deletions

View File

@ -6,29 +6,65 @@ import WebEngine from "../../webEngine.js";
import InternalProvider from "../../contentProviders/internalProvider.js"; import InternalProvider from "../../contentProviders/internalProvider.js";
import IpfsProvider from "../../contentProviders/ipfsProvider.js"; import IpfsProvider from "../../contentProviders/ipfsProvider.js";
import ServerProvider from "../../contentProviders/serverProvider.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 { 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() { export async function boot() {
tldEnum.list.push("localhost"); tldEnum.list.push("localhost");
window.addEventListener("message", handleKernelMessage); window.addEventListener("message", handleKernelMessage);
browser.runtime.onConnect.addListener(bridgeListener); browser.runtime.onConnect.addListener(bridgeListener);
const engine = new WebEngine(); engine = new WebEngine();
engine.registerContentProvider(new InternalProvider(engine)); engine.registerContentProvider(new InternalProvider(engine));
engine.registerContentProvider(new IpfsProvider(engine));
engine.registerContentProvider(new ServerProvider(engine));
setKernelIframe(document.createElement("iframe")); setKernelIframe(document.createElement("iframe"));
getKernelIframe().src = "http://kernel.lume"; getKernelIframe().src = "http://kernel.lume";
await new Promise((resolve) => { getKernelIframe().onload = init;
getKernelIframe().onload = () => {
init().then(resolve);
};
document.body.appendChild(getKernelIframe()); 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);
}
} }