import { type FC, useState } from 'react'; import { toast } from 'react-toastify'; import AccessTimeIcon from '@mui/icons-material/AccessTime'; import CancelIcon from '@mui/icons-material/Cancel'; import CastIcon from '@mui/icons-material/Cast'; import DeviceHubIcon from '@mui/icons-material/DeviceHub'; import ImportExportIcon from '@mui/icons-material/ImportExport'; import LockIcon from '@mui/icons-material/Lock'; import MemoryIcon from '@mui/icons-material/Memory'; import PowerSettingsNewIcon from '@mui/icons-material/PowerSettingsNew'; import SettingsBackupRestoreIcon from '@mui/icons-material/SettingsBackupRestore'; import SettingsEthernetIcon from '@mui/icons-material/SettingsEthernet'; import SettingsInputAntennaIcon from '@mui/icons-material/SettingsInputAntenna'; import TuneIcon from '@mui/icons-material/Tune'; import { Box, Button, Dialog, DialogActions, DialogContent, DialogTitle, List } from '@mui/material'; import * as SystemApi from 'api/system'; import { dialogStyle } from 'CustomTheme'; import { useRequest } from 'alova'; import { ButtonRow, SectionContent, useLayoutTitle } from 'components'; import ListMenuItem from 'components/layout/ListMenuItem'; import { useI18nContext } from 'i18n/i18n-react'; import RestartMonitor from './system/RestartMonitor'; const Settings: FC = () => { const { LL } = useI18nContext(); useLayoutTitle(LL.SETTINGS(0)); const [confirmRestart, setConfirmRestart] = useState(false); const [confirmFactoryReset, setConfirmFactoryReset] = useState(false); const [processing, setProcessing] = useState(false); const [restarting, setRestarting] = useState(); const { send: restartCommand } = useRequest(SystemApi.restart(), { immediate: false }); const { send: factoryResetCommand } = useRequest(SystemApi.factoryReset(), { immediate: false }); const { send: partitionCommand } = useRequest(SystemApi.partition(), { immediate: false }); const restart = async () => { setProcessing(true); await restartCommand() .then(() => { setRestarting(true); }) .catch((error: Error) => { toast.error(error.message); }) .finally(() => { setConfirmRestart(false); setProcessing(false); }); }; const factoryReset = async () => { setProcessing(true); await factoryResetCommand() .then(() => { setRestarting(true); }) .catch((error: Error) => { toast.error(error.message); }) .finally(() => { setConfirmFactoryReset(false); setProcessing(false); }); }; const partition = async () => { setProcessing(true); await partitionCommand() .then(() => { setRestarting(true); }) .catch((error: Error) => { toast.error(error.message); }) .finally(() => { setConfirmRestart(false); setProcessing(false); }); }; const renderRestartDialog = () => ( setConfirmRestart(false)} > {LL.RESTART()} {LL.RESTART_CONFIRM()} ); const renderFactoryResetDialog = () => ( setConfirmFactoryReset(false)} > {LL.FACTORY_RESET()} {LL.SYSTEM_FACTORY_TEXT_DIALOG()} ); const content = () => ( <> {renderRestartDialog()} {renderFactoryResetDialog()} ); return ( {restarting ? : content()} ); }; export default Settings;