desktop: one read registry for every read button: single-flight per canonical key, broad reads cover narrow keys, overlapping buttons all busy and disabled (useReadState), 20 s 'read just now' memo, quota pause on the buttons, every read through the scheduler (Check again, Import apps, account Test, Read the stores, Dependencies), writes invalidate only the reads they change; tests/read-registry.test.ts; fixtures ?blocked and window.__fakeCalls

This commit is contained in:
CRTkafa 2026-10-23 11:09:51 +08:00
parent 7345de2f7c
commit c03938f9dc
14 changed files with 861 additions and 164 deletions

View file

@ -6,12 +6,15 @@ import { type AndroidSdkLookup, api, type DownloadInfo, errorText, type LocalToo
import { t } from '../i18n';
import { bytes } from '../lib/format';
import { shortPath } from '../paths';
import { useData } from '../store';
import { useData, useReadState } from '../store';
import { Icon, type IconName } from '../ui/icons';
import { Chip, Notice, Skeleton } from '../ui/kit';
import { PageHeader, Section, StatTile, StatusPill } from '../ui/ds';
import '../styles/deps.css';
/** The local tools check (system.tools): one registry key. */
const TOOLS_KEY = '*\u001fsystem.tools';
const TOOL_ICON: Record<string, IconName> = { ffmpeg: 'image', ffprobe: 'search', chrome: 'globe', xcode: 'terminal', simctl: 'phone', adb: 'phone', git: 'layers' };
/** Status chip of one tool. */
@ -29,16 +32,18 @@ export function Dependencies() {
const [sdk, setSdk] = useState<AndroidSdkLookup | null>(d.sidecar?.tools?.androidSdk ?? null);
const [info, setInfo] = useState<DownloadInfo[]>([]);
const [error, setError] = useState<string | null>(null);
const [busy, setBusy] = useState(false);
// local tools check: one registry key, so a second click (or a remount) joins the check in flight
const busy = useReadState(TOOLS_KEY).busy;
const [dl, setDl] = useState<Record<string, Dl>>({});
const reg = d.registry;
const refresh = useCallback(async () => {
setBusy(true); setError(null);
setError(null);
try {
const [s, i] = await Promise.all([api.call<LocalTools>('system.tools'), api.toolsInfo()]);
const [s, i] = await reg.read({ key: TOOLS_KEY, lanes: ['local'], accounts: [], priority: 0, run: () => Promise.all([api.call<LocalTools>('system.tools'), api.toolsInfo()]) }, { force: true });
setTools(s.tools); setInfo(i); setSdk(s.androidSdk ?? null);
} catch (e) { setError(errorText(e)); } finally { setBusy(false); }
}, []);
} catch (e) { setError(errorText(e)); }
}, [reg]);
useEffect(() => { refresh(); }, [refresh]);
useEffect(() => {
const un = onDownload(e => setDl(m => {