import { tr } from '../lib/i18n'; import { useCallback, useEffect, useState } from 'react'; import { Btn, Icon } from './ui'; import { answerNotice, tunePresetAction, tuneOff, tuneStatus, type TuneStatus } from '../lib/native-tune'; import { useNative } from '../lib/native'; /** * Which saved tuning a start will use, in plain words, and a way to switch it off (back to the standard settings) or on again. * Shown on the Models screen so nobody has to guess what runs after an unload or a restart. The tuning is applied by Strata at every * start (see strata_control/presets.py); this only reads it and flips it. Layout is the UI worker's: it is one line of text and one button. */ export function NativeTuneBadge({ model, resourceProfile, vision }: { model: string; resourceProfile: 'work' | 'performance'; vision: string }) { const native = useNative(); const [status, setStatus] = useState(null), [busy, setBusy] = useState(false), [error, setError] = useState(''); const jobs = native?.jobs.filter(j => j.state === 'running').length ?? 0; const read = useCallback(async () => { try { setStatus(await tuneStatus(model, resourceProfile, vision)); setError(''); } catch { setStatus(null); } }, [model, resourceProfile, vision]); useEffect(() => { void read(); }, [read, jobs, native?.instances.length]); async function flip(fn: () => Promise) { setBusy(true); setError(''); try { await fn(); await read(); } catch (e) { setError(e instanceof Error ? e.message : String(e)); } finally { setBusy(false); } } if (!status || (!status.active && !status.last_active)) return null; const active = status.active; return

{active ? <>{tr("Using your tuning '{0}'", [active.name])}{status.state === 'hard' ? <> {'·'} {tr("This PC changed since it was tuned, so these settings are not used until you tune again.")} : null} {active.answers && active.answers.class !== 'exact' ? <> {'·'} {tr(answerNotice(active.answers.class, active.answers.default_repeatable))} : null}{' '} void flip(() => tuneOff(model, resourceProfile, vision))}>{tr("Switch off")} : <>{tr("Your tuning is off. The standard settings are used.")}{' '} void flip(() => tunePresetAction(status.last_active!.id, 'apply'))}>{tr("Switch on")}} {error ? {error} : null}

; }