mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-03 11:09:55 +08:00
01ae511879
Co-authored-by: AngusBell97 <124716116+AngusBell97@users.noreply.github.com>
51 lines
1.7 KiB
JavaScript
51 lines
1.7 KiB
JavaScript
const FILTER_KEY = "galaxy.modelManager.hardwareFilter";
|
|
const FILTERS = new Set(["both", "gpu", "comma"]);
|
|
|
|
export function readHardwareFilter() {
|
|
try {
|
|
const value = localStorage.getItem(FILTER_KEY);
|
|
return FILTERS.has(value) ? value : "both";
|
|
} catch {
|
|
return "both";
|
|
}
|
|
}
|
|
|
|
export function saveHardwareFilter(value) {
|
|
const filter = FILTERS.has(value) ? value : "both";
|
|
try { localStorage.setItem(FILTER_KEY, filter); } catch {}
|
|
return filter;
|
|
}
|
|
|
|
export function matchesHardware(model, filter) {
|
|
if (filter === "gpu") return model?.requiresGpu === true;
|
|
if (filter === "comma") return model?.requiresGpu === false;
|
|
return true;
|
|
}
|
|
|
|
export function hardwareLabel(model) {
|
|
if (model?.requiresGpu === true) return "GPU · External";
|
|
if (model?.requiresGpu === false) return "Comma · On-device";
|
|
return "Hardware unknown";
|
|
}
|
|
|
|
function bytes(value) {
|
|
return Number.isSafeInteger(value) && value > 0 ? value : null;
|
|
}
|
|
|
|
function formatBytes(value) {
|
|
return value >= 1e9 ? `${(value / 1e9).toFixed(2)} GB` : `${(value / 1e6).toFixed(1)} MB`;
|
|
}
|
|
|
|
export function fileSizeText(model) {
|
|
const installed = bytes(model?.fileSizeBytes);
|
|
const declared = bytes(model?.declaredSizeBytes);
|
|
const downloaded = bytes(model?.downloadedBytes);
|
|
if (model?.partial || model?.sizeStatus === "partial") {
|
|
return `Partial: ${downloaded ? formatBytes(downloaded) : "unknown"} / ${declared ? formatBytes(declared) : "unknown"}`;
|
|
}
|
|
if (installed && declared && installed !== declared) return `${formatBytes(installed)} · size mismatch`;
|
|
if (installed) return formatBytes(installed);
|
|
if (declared) return `${formatBytes(declared)} · declared`;
|
|
return "Unavailable";
|
|
}
|