fix(startup): reduce initial loading and unblock app restoration
This commit is contained in:
23 files changed
+745
-123
No files matched your search
@@ -0,0 +1,21 @@
|
||||
import { apiUrl } from "@/lib/common/webPath";
|
||||
|
||||
export interface StartupAuthentication {
|
||||
required: boolean;
|
||||
authenticated: boolean;
|
||||
setup_required: boolean;
|
||||
}
|
||||
|
||||
export async function checkStartupAuthentication(signal?: AbortSignal): Promise<StartupAuthentication> {
|
||||
const response = await fetch(apiUrl("/api/auth/check"), { credentials: "same-origin", signal });
|
||||
if (!response.ok) throw new Error("AUTH_CHECK_FAILED");
|
||||
const result: unknown = await response.json();
|
||||
if (!result || typeof result !== "object" || !("required" in result) || !("authenticated" in result) || typeof result.required !== "boolean" || typeof result.authenticated !== "boolean") {
|
||||
throw new Error("AUTH_CHECK_FAILED");
|
||||
}
|
||||
return {
|
||||
required: result.required,
|
||||
authenticated: result.authenticated,
|
||||
setup_required: "setup_required" in result && result.setup_required === true,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
export type StartupPhase = "bootstrap" | "gate-mounted" | "locale-ready" | "auth-ready" | "migration-ready" | "app-mounted" | "settings-ready" | "connections-ready" | "tabs-restored";
|
||||
|
||||
export function markStartupPhase(phase: StartupPhase): void {
|
||||
const name = `dbx:startup:${phase}`;
|
||||
const clock = globalThis.performance;
|
||||
if (typeof clock?.mark !== "function" || typeof clock.getEntriesByName !== "function") return;
|
||||
if (!clock.getEntriesByName(name, "mark").length) clock.mark(name);
|
||||
}
|
||||
Reference in new issue
Block a user