okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
b6a38b328
main
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 }) { 10const [ state , setState ] = useState < 'ask' | 'stopping' | 'stopped' | 'failed' >( 'ask' ); 11useEffect (() => { if ( open ) setState ( 'ask' ); }, [ open ]); 12async function quit () { 13setState ( 'stopping' ); 14try { 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 16const response = await fetch ( '/api/app/quit' , { method :'POST' , headers :{ 'x-strata-client' :'ui' } }); 17setState ( response . ok ?'stopped' :'failed' ); 18} catch { setState ( 'failed' ); } 19} 20const stopped = state === 'stopped' ; 21return < Dialog open = { open } compact title = { tr ( stopped ?"Strata has stopped" :"Quit Strata?" )} onClose = { state === 'stopping' ?() => {} :onClose } 22actions = { 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}