okami.mom/strata

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

Niko1221Merge f-split-linuxui (83aa59fdc) into f-split-int2b6a38b328

main
1.9 KiB29 linesraw
1import { useEffect, useState } from 'react';
2import { tr } from '../lib/i18n';
3import { Btn, Dialog } from './ui';
4
5/**
6 * Browser mode only (the app window could not start, or the person asked for `--browser`): closing the tab does not stop Strata or
7 * its engine, so the menu has "Quit Strata". The host refuses the request in the app window, where closing the window quits.
8 */
9export function QuitStrataDialog({ open, onClose }: { open: boolean; onClose: () => void }) {
10  const [state, setState] = useState<'ask' | 'stopping' | 'stopped' | 'failed'>('ask');
11  useEffect(() => { if (open) setState('ask'); }, [open]);
12  async function quit() {
13    setState('stopping');
14    try {
15      // the header is what a web page on another site cannot send; the host also refuses any request that does not come from this computer
16      const response = await fetch('/api/app/quit', { method: 'POST', headers: { 'x-strata-client': 'ui' } });
17      setState(response.ok ? 'stopped' : 'failed');
18    } catch { setState('failed'); }
19  }
20  const stopped = state === 'stopped';
21  return <Dialog open={open} compact title={tr(stopped ? "Strata has stopped" : "Quit Strata?")} onClose={state === 'stopping' ? () => {} : onClose}
22    actions={stopped ? undefined : <><Btn onClick={onClose} disabled={state === 'stopping'}>{tr("Cancel")}</Btn><Btn variant="primary" disabled={state === 'stopping'} onClick={() => void quit()}>{tr(state === 'stopping' ? "Quitting…" : "Quit Strata")}</Btn></>}>
23    <p className="small" role="status">{tr(stopped
24      ? "Strata has stopped. You can close this tab. To use it again, start Strata from its icon."
25      : state === 'failed'
26        ? "Strata could not be stopped from here. Run the app with --quit in a terminal, or try again."
27        : "This stops the model and ends Strata. Your chats and files stay as they are. Closing the browser tab alone would leave Strata running.")}</p>
28  </Dialog>;
29}