From 7f0762115756fdeccfe4eecabfe7143f20df4f32 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 3 Aug 2023 10:38:01 -0400 Subject: [PATCH] fix: add detection to see if we are logged in before starting the onboarding screen with the onInstalled trigger. --- src/main/background.ts | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/background.ts b/src/main/background.ts index 6f2b1f3..62a9c7d 100644 --- a/src/main/background.ts +++ b/src/main/background.ts @@ -1,17 +1,34 @@ -import { awaitBooted, getTimer } from "../vars.js"; +import { awaitBooted, events, getTimer } from "../vars.js"; import browser from "webextension-polyfill"; import { logLargeObjects } from "./background/util.js"; import { queryKernel } from "./background/kernel.js"; import { boot } from "./background/boot.js"; import * as kernel from "@lumeweb/libkernel"; +import type { KernelAuthStatus } from "@lumeweb/libweb"; +import defer from "p-defer"; setTimeout(logLargeObjects, getTimer()); -browser.runtime.onInstalled.addListener(() => { - browser.tabs.create({ - url: browser.runtime.getURL("onboarding.html"), - active: true, +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({ + url: browser.runtime.getURL("onboarding.html"), + active: true, + }); + } }); browser.runtime.onMessage.addListener(async (request, sender) => {