refactor: switch getBlockForBootloader to use a defer and be getAuthStatusDefer
This commit is contained in:
parent
25a1c5c454
commit
f6081fa0d4
|
@ -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(),
|
||||
|
|
|
@ -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<any> {
|
|||
resolve(data.data);
|
||||
};
|
||||
|
||||
getBlockForBootloader().then(() => {
|
||||
getAuthStatusDefer().promise.then(() => {
|
||||
let nonce = getQueriesNonce();
|
||||
increaseQueriesNonce();
|
||||
query.nonce = nonce;
|
||||
|
|
12
src/vars.ts
12
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<any> {
|
||||
return blockForDnsSetup;
|
||||
}
|
||||
export function getAuthStatusResolve(): DataFn {
|
||||
return authStatusResolve;
|
||||
}
|
||||
|
||||
export function getBlockForBootloader(): Promise<unknown> {
|
||||
return blockForBootloader;
|
||||
export function getAuthStatusDefer() {
|
||||
return authStatusDefer;
|
||||
}
|
||||
|
||||
export function getBooted(): Promise<unknown> {
|
||||
|
|
Reference in New Issue