okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
aff3a132f
main
1import { useState } from 'react' ; 2import { tr } from '../lib/i18n' ; 3import { Btn , Icon } from './ui' ; 4import { nativeAction , type NativeState } from '../lib/native' ; 5 6/** Strata Control's last check found a newer engine than the one installed: its numbers come from the 7* check kept on this PC (`update_available` of `strata components engine`), so showing the card reads no network. After an app or Control update this is how a 8* person with an older engine is told (#4848). */ 9export const engineUpdateOffered = ( native :NativeState | null | undefined ) => { 10const offer = native ?. engine ?. updateAvailable ; 11return !! ( offer && offer . engine ); 12}; 13 14/** One card, plain words, one button. The update itself is the existing "Update engine" job (its progress shows where every job's does); models are not touched. */ 15export function EngineUpdateCard ({ native, busy} :{ native :NativeState | null | undefined ; busy :boolean }) { 16const [ pending , setPending ] = useState ( false ); 17const [ error , setError ] = useState ( '' ); 18if ( ! engineUpdateOffered ( native )) return null ; 19const running = ( native ?. instances . length ?? 0 ) > 0 ; 20async function update () { 21setPending ( true ); 22setError ( '' ); 23try { 24await nativeAction ( 'operations' , { kind :'update-engine' }); 25} catch ( e ) { 26setError ( e instanceof Error ?e . message :String ( e )); 27} finally { 28setPending ( false ); 29} 30} 31return < div className = "engine-warning engine-update" role = "status" > 32< Icon name = "info" size = { 18 }/> 33< div > 34< p >{ tr ( "A newer engine is available for this computer. Your models and settings stay as they are." )}</ p > 35{ running ?< small >{ tr ( "Unload your running models first." )}</ small > :null } 36{ error ?< small className = "inline-error" role = "alert" >{ error }</ small > :null } 37</ div > 38< Btn size = "sm" variant = "primary" disabled = { busy || pending || running } onClick = {() => void update ()}>{ tr ( "Update engine" )}</ Btn > 39</ div >; 40}