feat: add configurable platform appearance (#385)

This commit is contained in:
likeraylee
2026-09-02 20:33:25 +08:00
committed by GitHub
parent a6504c0e00
commit 5dd515b8ab
31 changed files with 2795 additions and 153 deletions

View File

@@ -0,0 +1,20 @@
import { getPublicAppearance, type PublicAppearance } from "@/services/api/appearance";
import { commitPublicAppearance, DEFAULT_PUBLIC_APPEARANCE } from "@/stores/use-appearance-store";
const APPEARANCE_BOOTSTRAP_TIMEOUT_MS = 4_000;
export async function resolvePublicAppearance(fetchAppearance: (signal: AbortSignal) => Promise<PublicAppearance> = getPublicAppearance) {
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), APPEARANCE_BOOTSTRAP_TIMEOUT_MS);
try {
return await fetchAppearance(controller.signal);
} catch {
return DEFAULT_PUBLIC_APPEARANCE;
} finally {
clearTimeout(timer);
}
}
export async function bootstrapAppearance(fetchAppearance?: (signal: AbortSignal) => Promise<PublicAppearance>) {
return commitPublicAppearance(await resolvePublicAppearance(fetchAppearance));
}