okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
e59e64ec5
main
1import type { UpdateCheckResult } from './types' ; 2 3/** 4* The last update check, kept on this computer so Settings can show it without touching the network. A check runs only when the 5* person presses "Check for updates" (or "Update engine" / "Update Strata"). The result is kept together with the versions it was 6* for, and it is ignored once the installed version changes (an update, a roll back), so an old "Update available" never lingers. 7*/ 8const KEY = 'strata.update-check.v1' ; 9 10interface Stored { result :UpdateCheckResult ; appVersion :string | null ; engineVersion :string | null ; controlVersion ?:string | null } 11export interface InstalledVersions { appVersion ?:string | null ; engineVersion ?:string | null ; controlVersion ?:string | null } 12 13const same = ( a :string | null | undefined , b :string | null | undefined ) => ( a ?? null ) === ( b ?? null ); 14 15export function readUpdateCache ( now :InstalledVersions ) :UpdateCheckResult | null { 16try { 17const stored = JSON . parse ( localStorage . getItem ( KEY ) ?? 'null' ) as Stored | null ; 18if ( ! stored ?. result ?. strata ?. status || ! stored . result . engine ?. status || ! stored . result . checkedAt ) return null ; 19// Still loading (no app version yet): show nothing rather than a result that may belong to the version before an update. 20if ( ! now . appVersion ) return null ; 21if ( ! same ( stored . appVersion , now . appVersion ) || ! same ( stored . engineVersion , now . engineVersion ) || ! same ( stored . controlVersion , now . controlVersion )) return null ; 22return stored . result ; 23} catch { return null ; } 24} 25 26export function saveUpdateCache ( result :UpdateCheckResult , now :InstalledVersions ) { 27try { localStorage . setItem ( KEY , JSON . stringify ({ result, appVersion :now . appVersion ?? null , engineVersion :now . engineVersion ?? null , controlVersion :now . controlVersion ?? null } satisfies Stored )); } catch { /* Not remembering a result is harmless. */ } 28} 29 30export function clearUpdateCache () { 31try { localStorage . removeItem ( KEY ); } catch { /* Nothing to clear. */ } 32}