import React, { useCallback, useEffect, useState } from 'react';
import FocusTrap from 'focus-trap-react';
import {
Box,
Button,
Checkbox,
Dialog,
Header,
Overlay,
OverlayBackdrop,
OverlayCenter,
Text,
config,
} from 'folds';
import { invokeTauri, isTauri, tauriInvoke, useTauriEvent } from '../hooks/useTauri';
import { useModalStyle } from '../hooks/useModalStyle';
/**
* cinny-desktop #5: the first time the window is closed, ask whether Lotus Chat
* should keep running in the tray (calls, messages, notifications) or quit —
* and, in the same moment, whether it should start when you sign in. Asked
* once; changeable in Settings → General. The native side sends
* `lotus-close-requested` only while the choice is still "ask", and never
* during a call (a call always goes to the tray).
*/
export function CloseBehaviorPrompt() {
const [open, setOpen] = useState(false);
const [launchOnLogin, setLaunchOnLogin] = useState(false);
const modalStyle = useModalStyle(420);
// Tells the native side we're listening (see get_close_behavior).
useEffect(() => {
if (!isTauri()) return;
tauriInvoke()?.('get_close_behavior').catch(() => undefined);
}, []);
useTauriEvent('lotus-close-requested', () => setOpen(true));
const choose = useCallback(
(value: 'tray' | 'quit') => {
if (launchOnLogin) invokeTauri('plugin:autostart|enable');
setOpen(false);
invokeTauri('resolve_close_request', { value });
},
[launchOnLogin],
);
if (!open) return null;
return (
}>
setOpen(false),
clickOutsideDeactivates: true,
}}
>
);
}