From 3f8e7075a1805e03352ba72cb17389bba41fb99f Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 22 Aug 2022 01:52:10 -0400 Subject: [PATCH] *Consolidate all dns setup into 1 function and store the promise *await on the dns setup promise on the cached resolve function --- src/dns.ts | 3 ++- src/main/background.ts | 7 ++++--- src/main/vars.ts | 7 +++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/dns.ts b/src/dns.ts index 3a20ff4..0ddf0fb 100644 --- a/src/dns.ts +++ b/src/dns.ts @@ -10,6 +10,7 @@ import { ResolverOptions, } from "@lumeweb/libresolver"; import { blake2b, bufToHex, Err } from "libskynet/dist"; +import { getDnsSetupPromise } from "./main/vars.js"; const cache = new NodeCache({ stdTTL: 60 }); @@ -27,7 +28,7 @@ export async function resolve( return cache.get(cacheId) as DNSResult; } - await dnsReady(); + await getDnsSetupPromise(); let res; try { diff --git a/src/main/background.ts b/src/main/background.ts index 7d8b5a2..ac20fe8 100644 --- a/src/main/background.ts +++ b/src/main/background.ts @@ -216,11 +216,10 @@ async function boot() { document.body.appendChild(getKernelIframe()); setupContextMenus(engine); - await registerResolvers(); - await dnsReady(); + setDnsSetupPromise(dnsSetup()); } -async function registerResolvers() { +async function dnsSetup() { const resolvers = [ "AQBXtVkPDbZ5Qmjl8dzJ0siSYaFcS3XbDZHapxmZCLfwfg", // icann "AQAI3TbarrXRxWtrb_5XO-gMYg-UsjVAChue5JEoqywbAw", // eip137 @@ -234,6 +233,8 @@ async function registerResolvers() { for (const resolver of resolvers) { await callModule(resolver, "register"); } + + await dnsReady(); } boot(); diff --git a/src/main/vars.ts b/src/main/vars.ts index fa1f625..2200ac6 100644 --- a/src/main/vars.ts +++ b/src/main/vars.ts @@ -17,6 +17,7 @@ let blockForBridge = new Promise((resolve) => { bridgeLoadedResolve = resolve; }); let kernelFrame: HTMLIFrameElement; +let blockForDnsSetup: Promise; export function getAuthStatusKnown() { return authStatusKnown; @@ -94,6 +95,12 @@ export function setKernelIframe(iframe: HTMLIFrameElement) { kernelFrame = iframe; } +export function setDnsSetupPromise(p: Promise) { + blockForDnsSetup = p; +} +export function getDnsSetupPromise(): Promise { + return blockForDnsSetup; +} export function getAuthStatusResolve(): DataFn { return authStatusResolve; }