fix(startup): reduce initial loading and unblock app restoration

This commit is contained in:
t8y2 committed 2026-09-25 09:03:15 +08:00
1 parent 55c07f5852
commit 48d66d04d0
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);
}