From f6081fa0d46652efff2879980596b25c2a52b132 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 19 Jul 2023 05:17:42 -0400 Subject: [PATCH] refactor: switch getBlockForBootloader to use a defer and be getAuthStatusDefer --- src/main/background/bridge.ts | 5 ++--- src/main/background/kernel.ts | 7 +++---- src/vars.ts | 12 +++--------- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/main/background/bridge.ts b/src/main/background/bridge.ts index 64d1f32..b40dc38 100644 --- a/src/main/background/bridge.ts +++ b/src/main/background/bridge.ts @@ -2,8 +2,7 @@ import { addQuery, deleteOpenPort, getAuthStatus, - getBlockForBootloader, - getBridgeLoadedResolve, + getAuthStatusDefer, getKernelIframe, getOpenPorts, getPortsNonce, @@ -58,7 +57,7 @@ export function bridgeListener(port: any) { handleBridgeMessage(port, portNonce, data, domain); }); - getBlockForBootloader().then(() => { + getAuthStatusDefer().promise.then(() => { port.postMessage({ method: "kernelAuthStatus", data: getAuthStatus(), diff --git a/src/main/background/kernel.ts b/src/main/background/kernel.ts index 07e0cee..e66b25f 100644 --- a/src/main/background/kernel.ts +++ b/src/main/background/kernel.ts @@ -3,9 +3,8 @@ import { clearOpenPorts, deleteQuery, getAuthStatus, + getAuthStatusDefer, getAuthStatusKnown, - getAuthStatusResolve, - getBlockForBootloader, getKernelIframe, getOpenPorts, getQueries, @@ -45,7 +44,7 @@ export function handleKernelMessage(event: MessageEvent) { if (event.data.method === "kernelAuthStatus") { setAuthStatus(data); if (!getAuthStatusKnown()) { - getAuthStatusResolve()(); + getAuthStatusDefer().resolve(); setAuthStatusKnown(true); console.log("bootloader is now initialized"); if (!getAuthStatus().loginComplete) { @@ -91,7 +90,7 @@ export function queryKernel(query: any): Promise { resolve(data.data); }; - getBlockForBootloader().then(() => { + getAuthStatusDefer().promise.then(() => { let nonce = getQueriesNonce(); increaseQueriesNonce(); query.nonce = nonce; diff --git a/src/vars.ts b/src/vars.ts index 9d800f3..7010b8a 100644 --- a/src/vars.ts +++ b/src/vars.ts @@ -9,10 +9,7 @@ export let timer = 20000; let authStatus: KernelAuthStatus; let authStatusKnown = false; -let authStatusResolve: DataFn; -let blockForBootloader = new Promise((resolve) => { - authStatusResolve = resolve; -}); +let authStatusDefer = defer(); let kernelFrame: HTMLIFrameElement; let blockForDnsSetup = defer(); let booted = defer(); @@ -97,12 +94,9 @@ export function setKernelIframe(iframe: HTMLIFrameElement) { export function getDnsSetupDefer(): DeferredPromise { return blockForDnsSetup; } -export function getAuthStatusResolve(): DataFn { - return authStatusResolve; -} -export function getBlockForBootloader(): Promise { - return blockForBootloader; +export function getAuthStatusDefer() { + return authStatusDefer; } export function getBooted(): Promise {