okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
ffb3d9b31
main
1import type { NativeJob } from './native' ; 2 3/** What the host says about a job a restart cut short. */ 4export const INTERRUPTED = 'The host restarted before completion. Check diagnostics, then retry; completed files are kept.' ; 5const updateKinds = new Set ([ 'update-strata' , 'update-engine' ]); 6 7/** 8* A later finished update of the same component settles the restart interruption of an earlier one (ported from #3578 by medking82). 9* The records are never changed: a running retry, another component or an ordinary failure stays a plain failure. 10*/ 11export function recoveredInterruptions ( jobs :readonly NativeJob []) :Set < string > { 12const time = ( job :NativeJob ) => Date . parse ( job . startedAt ); 13return new Set ( jobs . filter ( job => job . state === 'error' && updateKinds . has ( job . kind ) && job . error === INTERRUPTED && Number . isFinite ( time ( job )) 14&& jobs . some ( later => later . state === 'done' && later . kind === job . kind && Number . isFinite ( time ( later )) && time ( later ) > time ( job ))). map ( job => job . id )); 15} 16 17/** The text of a failed job's alert. The alert stays red; an interruption a later update has settled says so in plain words. */ 18export function jobErrorText ( job :NativeJob , jobs :readonly NativeJob []) :string { 19return recoveredInterruptions ( jobs ). has ( job . id ) 20 ?'This update was cut short when the app restarted. A later update finished, so nothing needs doing.' 21 :job . error ?? job . summary ; 22} 23 24/** 25* The failed update Settings > About shows under its buttons: per component, the last failed one, and only while no later update of the same 26* component has finished. A failure a later update made right (the first-run engine card’s “A model is running … then press Continue” 27* after Continue installed the engine, QAGUI-STRIX 11-09) is history: it stays in Diagnostics, not in About. Jobs are kept across restarts 28* (native-jobs.json), so without this the line stayed there for good. 29*/ 30export function currentUpdateFailure ( jobs :readonly NativeJob []) :NativeJob | undefined { 31const time = ( job :NativeJob ) => Date . parse ( job . startedAt ); 32const failures = jobs . filter ( job => job . state === 'error' && updateKinds . has ( job . kind ) 33&& ! jobs . some ( later => later . state === 'done' && later . kind === job . kind && Number . isFinite ( time ( later )) && ( ! Number . isFinite ( time ( job )) || time ( later ) > time ( job )))); 34return failures . at ( - 1 ); 35} 36 37/** 38* A Strata or engine update that finished after the update check shown was made: that check is out of date (it still says “Update available”, 39* and its cache is keyed to the Control version that runs until a restart). Settings > About then checks again. The job’s id, or undefined. 40*/ 41export function updateFinishedAfter ( jobs :readonly NativeJob [], checkedAt :string | undefined ) :string | undefined { 42const checked = Date . parse ( checkedAt ?? '' ); 43if ( ! Number . isFinite ( checked )) return undefined ; 44const ended = ( job :NativeJob ) => Date . parse (( job as NativeJob & { finishedAt ?:string }). finishedAt ?? job . startedAt ); 45return jobs . filter ( job => job . state === 'done' && updateKinds . has ( job . kind ) && ended ( job ) > checked ). at ( - 1 )?. id ; 46}