okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-ds-out ac306afb2 into f-own-intaff3a132f

main
1.9 KiB40 linesraw
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) => {
10  const offer = native?.engine?.updateAvailable;
11  return !!(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 }) {
16  const [pending, setPending] = useState(false);
17  const [error, setError] = useState('');
18  if (!engineUpdateOffered(native)) return null;
19  const running = (native?.instances.length ?? 0) > 0;
20  async function update() {
21    setPending(true);
22    setError('');
23    try {
24      await nativeAction('operations', { kind: 'update-engine' });
25    } catch (e) {
26      setError(e instanceof Error ? e.message : String(e));
27    } finally {
28      setPending(false);
29    }
30  }
31  return <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}