fix: add detection to see if we are logged in before starting the onboarding screen with the onInstalled trigger.

This commit is contained in:
Derrick Hammer 2023-08-03 10:38:01 -04:00
parent 884db93478
commit 7f07621157
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 22 additions and 5 deletions

View File

@ -1,17 +1,34 @@
import { awaitBooted, getTimer } from "../vars.js"; import { awaitBooted, events, getTimer } from "../vars.js";
import browser from "webextension-polyfill"; import browser from "webextension-polyfill";
import { logLargeObjects } from "./background/util.js"; import { logLargeObjects } from "./background/util.js";
import { queryKernel } from "./background/kernel.js"; import { queryKernel } from "./background/kernel.js";
import { boot } from "./background/boot.js"; import { boot } from "./background/boot.js";
import * as kernel from "@lumeweb/libkernel"; import * as kernel from "@lumeweb/libkernel";
import type { KernelAuthStatus } from "@lumeweb/libweb";
import defer from "p-defer";
setTimeout(logLargeObjects, getTimer()); setTimeout(logLargeObjects, getTimer());
browser.runtime.onInstalled.addListener(() => { browser.runtime.onInstalled.addListener(async () => {
let loggedIn = false;
events.on("authStatus", (update: KernelAuthStatus) => {
if (update.loginComplete) {
loggedIn = true;
}
});
const timerDefer = defer();
setTimeout(timerDefer.resolve, 1000);
await timerDefer.promise;
if (!loggedIn) {
browser.tabs.create({ browser.tabs.create({
url: browser.runtime.getURL("onboarding.html"), url: browser.runtime.getURL("onboarding.html"),
active: true, active: true,
}); });
}
}); });
browser.runtime.onMessage.addListener(async (request, sender) => { browser.runtime.onMessage.addListener(async (request, sender) => {