okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
7c4b3d743
main
1import { tr } from '../lib/i18n' ; 2import { useCallback , useEffect , useState } from 'react' ; 3import { Btn , Icon } from './ui' ; 4import { answerNotice , tunePresetAction , tuneOff , tuneStatus , type TuneStatus } from '../lib/native-tune' ; 5import { useNative } from '../lib/native' ; 6 7/** 8* 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. 9* 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 10* 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. 11*/ 12export function NativeTuneBadge ({ model, resourceProfile, vision} :{ model :string ; resourceProfile :'work' | 'performance' ; vision :string }) { 13const native = useNative (); 14const [ status , setStatus ] = useState < TuneStatus | null >( null ), [ busy , setBusy ] = useState ( false ), [ error , setError ] = useState ( '' ); 15const jobs = native ?. jobs . filter ( j => j . state === 'running' ). length ?? 0 ; 16const read = useCallback ( async () => { 17try { setStatus ( await tuneStatus ( model , resourceProfile , vision )); setError ( '' ); } 18catch { setStatus ( null ); } 19}, [ model , resourceProfile , vision ]); 20useEffect (() => { void read (); }, [ read , jobs , native ?. instances . length ]); 21async function flip ( fn :() => Promise < unknown >) { 22setBusy ( true ); setError ( '' ); 23try { await fn (); await read (); } 24catch ( e ) { setError ( e instanceof Error ?e . message :String ( e )); } 25finally { setBusy ( false ); } 26} 27if ( ! status || ( ! status . active && ! status . last_active )) return null ; 28const active = status . active ; 29return < p className = "native-tune-line" data-tuning-active = { !! active } role = "status" >< Icon name = "gauge" size = { 15 }/>< span > 30{ 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 } 31{ active . answers && active . answers . class !== 'exact' ?<> { '·' } { tr ( answerNotice ( active . answers . class , active . answers . default_repeatable ))}</> :null }{ ' ' } 32< Btn size = "sm" variant = "ghost" disabled = { busy } onClick = {() => void flip (() => tuneOff ( model , resourceProfile , vision ))}>{ tr ( "Switch off" )}</ Btn ></> 33 :<>{ tr ( "Your tuning is off. The standard settings are used." )}{ ' ' } 34< Btn size = "sm" variant = "ghost" disabled = { busy } onClick = {() => void flip (() => tunePresetAction ( status . last_active ! . id , 'apply' ))}>{ tr ( "Switch on" )}</ Btn ></>} 35{ error ?< span className = "inline-error" role = "alert" > { error }</ span > :null } 36</ span ></ p >; 37}