okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
261145baa
main
1import { tr } from '../lib/i18n' ; 2import { useCallback , useEffect , useState } from 'react' ; 3import { api } from '../lib/client' ; 4import { Btn , ErrorNotice } from './ui' ; 5import { issueText , type SettingsFileInfo } from '../lib/run-config-issues' ; 6 7/** 8* Expert settings: the model's settings live in one text file (its run configuration). A power user opens it in the system 9* text editor and changes any engine option; the change applies the next time the model starts. The file is checked here and 10* again before the model starts, and a mistake is shown in plain words with its line. 11*/ 12export function NativeSettingsFile ({ model} :{ model :string }) { 13const [ info , setInfo ] = useState < SettingsFileInfo | null >( null ), [ pending , setPending ] = useState ( false ), [ error , setError ] = useState ( '' ); 14const check = useCallback (() => api . get < SettingsFileInfo >( `/api/native/models/ ${ model } /settings-file` ). then ( value => { setInfo ( value ); setError ( '' ); }). catch (() => setInfo ( null )), [ model ]); 15useEffect (() => { 16void check (); 17// Back from the editor: look at the file again. 18const again = () => void check (); 19window . addEventListener ( 'focus' , again ); 20return () => window . removeEventListener ( 'focus' , again ); 21}, [ check ]); 22async function open () { 23setPending ( true ); 24setError ( '' ); 25try { 26setInfo ( await api . post < SettingsFileInfo >( `/api/native/models/ ${ model } /settings-file` , {})); 27} 28catch ( e ) { 29setError (( e as Error ). message ); 30} 31finally { 32setPending ( false ); 33} 34} 35const errors = info ?. issues . filter ( i => i . level === 'error' ) ?? [], warnings = info ?. issues . filter ( i => i . level === 'warning' ) ?? []; 36return < div className = "native-settings-file" > 37< h3 className = "small strong" >{ tr ( "Settings file" )}</ h3 > 38< div className = "row" >< Btn size = "sm" disabled = { pending || ! info } onClick = {() => void open ()}>{ tr ( "Open settings file" )}</ Btn >< span className = "small muted" >{ tr ( "Changes you make in the file apply the next time the model starts." )}</ span ></ div > 39{ tr ( error ?< ErrorNotice message = { error } next = { tr ( "Open the file from its folder instead, or try again." )}/> :null )} 40{ tr ( errors . length ?<>< ErrorNotice message = { tr ( "Your settings file has a mistake, so the model will not start until it is fixed." )} next = { tr ( "Open the settings file, fix the lines below, and load the model again." )}/>{ tr ( errors . map (( issue , i ) => < p className = "small" key = { `e ${ i } ` }>{ tr ( issueText ( issue ))}</ p >))}</> :null )} 41{ tr ( warnings . map (( issue , i ) => < p className = "small muted" key = { `w ${ i } ` }>{ tr ( issueText ( issue ))}</ p >))} 42</ div >; 43}