okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
ffb3d9b31
main
1/** 2* Plain words for the app. Whatever the updater says (HTTP codes, hash names, exit codes, file names) stays in `details`, which the UI 3* shows behind the existing "Details" disclosure; the main text says what happened and the one next step (`next`). The Terminal keeps 4* the precise messages: this module is only used on the app side. 5*/ 6 7export const PHASE_TEXT = { 8feed :'Looking for updates…' , 9download :'Downloading…' , 10verify :'Checking the download…' , 11test :'Making sure it works…' , 12switch :'Finishing up…' , 13done :'Done.' , 14}; 15 16/** The job line while an update waits for Control's update lock (another update or the app's own check holds it). Wording awaits the owner (lane APP-LIN item 4). */ 17export const UPDATE_WAITING_FOR_LOCK = 'Waiting for the update check to finish…' ; 18 19/** True when the failure looks like a computer with no internet (no DNS, no route, refused), not a slow or broken server. */ 20export function looksOffline ( error ) { 21const text = [ error ?. message , error ?. cause ?. message , error ?. cause ?. code , error ?. code , error ]. filter ( x => typeof x === 'string' ). join ( ' ' ); 22return / ENOTFOUND | EAI_AGAIN | ENETUNREACH | ENETDOWN | EHOSTUNREACH | ECONNREFUSED | getaddrinfo | fetch failed | network is unreachable | name or service not known | temporary failure in name resolution | nodename nor servname | No address associated | URLError / i . test ( text ); 23} 24export const OFFLINE_MESSAGE = "No internet connection. Try again when you're online." ; 25 26/** { message, details, next } for an error thrown by Control's update calls (or the shell bridge). `subject` is "engine" or "Strata". 27* `retry` names the button of a screen that has no Settings page yet (the first-run card's Continue): the next step then says that button. */ 28export function plainUpdateError ( error , subject = 'engine' , retry = undefined ) { 29const raw = String ( error ?. message ?? error ?? '' ); 30const code = error ?. code ?? '' ; 31const exit = error ?. exitCode ?? null ; 32const button = `Update ${ subject === 'engine' ? 'engine' : 'Strata' } ` ; 33const keep = 'Your current version still works.' ; 34let message = `The update didn't finish and nothing was changed. ${ keep } ` ; 35let next = `Press ${ button } in Settings to try again.` ; 36// Exit 7 is also the update lock (another update or a check holds it): told by its text, and checked first (QAGUI 0213 finding 3). 37if ( code === 'update_busy' || / another update is already running / i . test ( raw )) { 38message = 'An update is already running.' ; 39next = `Wait a moment, then press ${ button } in Settings.` ; 40} else if ( code === 'engine_serving' || exit === 7 || / is serving / i . test ( raw )) { 41message = 'A model is running, so nothing was changed.' ; 42next = `Unload the model in Models, then press ${ button } in Settings.` ; 43} else if ( / test start | did not start correctly | did not answer a one-token | did not become ready / i . test ( raw )) { 44message = `The new ${ subject } didn't start correctly, so nothing was changed. ${ keep } ` ; 45} else if ( looksOffline ( error ) || looksOffline ( raw )) { 46message = 'No internet connection.' ; 47next = "Try again when you're online." ; 48} else if ( / could not be read | interrupted | timed out | timeout | ECONN | ENOTFOUND | fetch failed | could not reach | server answered | not answer within / i . test ( raw )) { 49message = "Couldn't reach the update server." ; 50next = `Check your internet connection, then press ${ button } in Settings.` ; 51} else if ( / free space | not enough | no space left | disk is full / i . test ( raw )) { 52message = 'There is not enough free disk space for the update.' ; 53next = `Free some disk space, then press ${ button } in Settings.` ; 54} else if ( / could not be moved into place | could not be unpacked | not accepted after the switch / i . test ( raw )) { 55// The files were downloaded and checked; Windows or a virus scanner would not let Strata put them in place (#4853). Not a download problem. 56const long = / longer than Windows allows | path. * too long / i . test ( raw ); 57message = long 58 ?"The engine's folder is too deep for Windows, so it could not be put in place." 59 :'The engine was downloaded and checked, but Windows or a security program would not let Strata put it in place.' ; 60next = long 61 ?`Open Details, then follow the folder advice there, and press ${ button } in Settings.` 62 :`Wait a minute, then press ${ button } in Settings. If it happens again, pause your virus scanner's live scanning for a few minutes while it runs.` ; 63} else if ( / no engine for this PC | has no engine | no package / i . test ( raw )) { 64message = "There isn't an engine for this PC's graphics card yet." ; 65next = 'Check for updates again later.' ; 66} else if ( / trusts no update key / i . test ( raw )) { 67message = "Updates aren't available in this version of Strata yet." ; 68next = 'They will be after the next version.' ; 69} else if ( / signature | SHA-256 | does not match | not trusted | expired | older than | replayed | integrity | refused / i . test ( raw ) || exit === 5 ) { 70message = `The update didn't pass its safety check, so it was not installed. ${ keep } ` ; 71next = 'Try again later.' ; 72} 73if ( retry ) next = next . split ( ` ${ button } in Settings` ). join ( retry ). replace ( / in Settings / g , '' ). replace ( / { 2 ,} / g , ' ' ). replace ( / ([ ., ]) / g , '$1' ); 74return { message :` ${ message } ${ next } ` . trim (), headline :message , next, details :raw || undefined }; 75} 76 77/** Plain words for a switch or a delete in Settings > Engine: { message, details }. Control's own sentence for "the engine in use" is already plain and is kept. */ 78export function plainEngineError ( error , action = 'switch' ) { 79const raw = String ( error ?. message ?? error ?? '' ); 80const exit = error ?. exitCode ?? null ; 81let message = action === 'delete' ?"The engine wasn't deleted. Nothing else was changed." :"The engine wasn't switched. Nothing was changed." ; 82if ( / another update is already running / i . test ( raw )) message = 'An update is running. Wait for it to finish, then try again.' ; 83else if ( exit === 7 || / is serving | model is running / i . test ( raw )) message = 'A model is running, so nothing was changed. Unload the model in Models, then try again.' ; 84else if ( / engine in use / i . test ( raw )) message = 'This is the engine in use. Switch to another one first, then delete it.' ; 85else if ( / running program is using | something is using it / i . test ( raw )) message = 'A program is still using this engine, so it was not deleted. Unload your models and try again.' ; 86else if ( / not installed | already been deleted / i . test ( raw )) message = 'That engine is already gone. The list has been refreshed.' ; 87else if ( / another update is already running / i . test ( raw )) message = 'An update is running. Wait for it to finish, then try again.' ; 88else if ( exit === 5 || / can no longer be used | does not fit | cannot run / i . test ( raw )) message = "This engine can't run on this computer, so nothing was changed." ; 89return { message, details :raw || undefined }; 90} 91 92/** An Error carrying the plain message and, behind it, the technical reason. */ 93export function plainError ( error , subject , retry = undefined ) { 94const { message, details} = plainUpdateError ( error , subject , retry ); 95return Object . assign ( new Error ( message ), { details, code :error ?. code }); 96}