staging-tester / ocean-landing-serve / src/ lib/ live/ boot.ts

import type { Me } from '@sailfork/client';
import type { Profile } from '../profile-types.js';
import type { Account } from '../settings-types.js';
import type { Org } from './org.svelte.js';

// What the app section last rendered from. It lets a reload paint at once, and offline, from the previous session
// while the network revalidates it. Cleared on sign-out so the next person never sees it.
export type Boot = { me: Me; org: Org; profile: Profile; account: Account; privateRepos: string[] };

const key = 'sailfork-boot:v1';

export function readBoot(): Boot | null {
	try {
		const raw = localStorage.getItem(key);
		return raw ? (JSON.parse(raw) as Boot) : null;
	} catch {
		return null;
	}
}

export function writeBoot(boot: Boot): void {
	try {
		localStorage.setItem(key, JSON.stringify(boot));
	} catch {
		// Storage can be full or blocked; the app then boots from the network as before.
	}
}

export function clearBoot(): void {
	try {
		localStorage.removeItem(key);
	} catch {
		// Nothing was stored.
	}
}