refactor: switch getBlockForBootloader to use a defer and be getAuthStatusDefer

This commit is contained in:
Derrick Hammer 2023-07-19 05:17:42 -04:00
parent 25a1c5c454
commit f6081fa0d4
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 8 additions and 16 deletions

View File

@ -2,8 +2,7 @@ import {
addQuery, addQuery,
deleteOpenPort, deleteOpenPort,
getAuthStatus, getAuthStatus,
getBlockForBootloader, getAuthStatusDefer,
getBridgeLoadedResolve,
getKernelIframe, getKernelIframe,
getOpenPorts, getOpenPorts,
getPortsNonce, getPortsNonce,
@ -58,7 +57,7 @@ export function bridgeListener(port: any) {
handleBridgeMessage(port, portNonce, data, domain); handleBridgeMessage(port, portNonce, data, domain);
}); });
getBlockForBootloader().then(() => { getAuthStatusDefer().promise.then(() => {
port.postMessage({ port.postMessage({
method: "kernelAuthStatus", method: "kernelAuthStatus",
data: getAuthStatus(), data: getAuthStatus(),

View File

@ -3,9 +3,8 @@ import {
clearOpenPorts, clearOpenPorts,
deleteQuery, deleteQuery,
getAuthStatus, getAuthStatus,
getAuthStatusDefer,
getAuthStatusKnown, getAuthStatusKnown,
getAuthStatusResolve,
getBlockForBootloader,
getKernelIframe, getKernelIframe,
getOpenPorts, getOpenPorts,
getQueries, getQueries,
@ -45,7 +44,7 @@ export function handleKernelMessage(event: MessageEvent) {
if (event.data.method === "kernelAuthStatus") { if (event.data.method === "kernelAuthStatus") {
setAuthStatus(data); setAuthStatus(data);
if (!getAuthStatusKnown()) { if (!getAuthStatusKnown()) {
getAuthStatusResolve()(); getAuthStatusDefer().resolve();
setAuthStatusKnown(true); setAuthStatusKnown(true);
console.log("bootloader is now initialized"); console.log("bootloader is now initialized");
if (!getAuthStatus().loginComplete) { if (!getAuthStatus().loginComplete) {
@ -91,7 +90,7 @@ export function queryKernel(query: any): Promise<any> {
resolve(data.data); resolve(data.data);
}; };
getBlockForBootloader().then(() => { getAuthStatusDefer().promise.then(() => {
let nonce = getQueriesNonce(); let nonce = getQueriesNonce();
increaseQueriesNonce(); increaseQueriesNonce();
query.nonce = nonce; query.nonce = nonce;

View File

@ -9,10 +9,7 @@ export let timer = 20000;
let authStatus: KernelAuthStatus; let authStatus: KernelAuthStatus;
let authStatusKnown = false; let authStatusKnown = false;
let authStatusResolve: DataFn; let authStatusDefer = defer();
let blockForBootloader = new Promise((resolve) => {
authStatusResolve = resolve;
});
let kernelFrame: HTMLIFrameElement; let kernelFrame: HTMLIFrameElement;
let blockForDnsSetup = defer(); let blockForDnsSetup = defer();
let booted = defer(); let booted = defer();
@ -97,12 +94,9 @@ export function setKernelIframe(iframe: HTMLIFrameElement) {
export function getDnsSetupDefer(): DeferredPromise<any> { export function getDnsSetupDefer(): DeferredPromise<any> {
return blockForDnsSetup; return blockForDnsSetup;
} }
export function getAuthStatusResolve(): DataFn {
return authStatusResolve;
}
export function getBlockForBootloader(): Promise<unknown> { export function getAuthStatusDefer() {
return blockForBootloader; return authStatusDefer;
} }
export function getBooted(): Promise<unknown> { export function getBooted(): Promise<unknown> {