import { useCallback, useEffect, useRef, useState } from 'react'; import { AlertDialog, AlertDialogBody, AlertDialogContent, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, Button, IconButton, Tooltip, } from '@chakra-ui/react'; import { FiPower } from '@react-icons/all-files/fi/FiPower'; import { Size } from '../../models/Util.type'; import { useEmitLog } from '../../stores/logger'; interface QuitIconBtnProps { clickHandler: () => void; size?: Size; disabled?: boolean; } const quitBtnStyle = { color: '#D20300', // $red-700 borderColor: '#D20300', // $red-700 _focus: { boxShadow: 'none' }, _hover: { background: '#D20300', // $red-700 color: 'white', _disabled: { color: '#D20300', // $red-700 background: 'none', }, }, _active: { background: '#9A0000', // $red-1000 color: 'white', }, variant: 'outline', isRound: true, }; export default function QuitIconBtn(props: QuitIconBtnProps) { const { clickHandler, size = 'lg', disabled, ...rest } = props; const [isOpen, setIsOpen] = useState(false); const { emitInfo } = useEmitLog(); const onClose = () => setIsOpen(false); const cancelRef = useRef(null); useEffect(() => { if (window.process?.type === 'renderer') { window.ipcRenderer.on('user-request-shutdown', () => { emitInfo('Shutdown request'); setIsOpen(true); }); } }, [emitInfo]); const handleShutdown = useCallback(() => { onClose(); clickHandler(); }, [clickHandler]); return ( <> } onClick={() => setIsOpen(true)} isDisabled={disabled} {...quitBtnStyle} {...rest} /> Ontime Shutdown This will shutdown the program and all running servers. Are you sure? ); }