diff --git a/interface/src/app/settings/DownloadUpload.tsx b/interface/src/app/settings/DownloadUpload.tsx index a195049d2..e955f9280 100644 --- a/interface/src/app/settings/DownloadUpload.tsx +++ b/interface/src/app/settings/DownloadUpload.tsx @@ -4,7 +4,6 @@ import { toast } from 'react-toastify'; import CancelIcon from '@mui/icons-material/Cancel'; import DownloadIcon from '@mui/icons-material/GetApp'; import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined'; -import PowerSettingsNewIcon from '@mui/icons-material/PowerSettingsNew'; import WarningIcon from '@mui/icons-material/Warning'; import { Box, @@ -25,7 +24,13 @@ import { getSchedule, getSettings } from 'api/app'; -import { checkUpgrade, getDevVersion, getStableVersion } from 'api/system'; +import { + checkUpgrade, + getDevVersion, + getStableVersion, + restart, + uploadURL +} from 'api/system'; import { dialogStyle } from 'CustomTheme'; import { useRequest } from 'alova/client'; @@ -33,7 +38,6 @@ import type { APIcall } from 'app/main/types'; import RestartMonitor from 'app/status/RestartMonitor'; import { FormLoader, - MessageBox, SectionContent, SingleUpload, useLayoutTitle @@ -44,7 +48,6 @@ const DownloadUpload = () => { const { LL } = useI18nContext(); const [restarting, setRestarting] = useState(false); - const [restartNeeded, setRestartNeeded] = useState(false); const [openDialog, setOpenDialog] = useState(false); const [useDev, setUseDev] = useState(false); const [upgradeAvailable, setUpgradeAvailable] = useState(false); @@ -89,24 +92,21 @@ const DownloadUpload = () => { } = useRequest(SystemApi.readHardwareStatus); const { send: sendUploadURL } = useRequest( - (data: { url: string }) => SystemApi.uploadURL(data), + (data: { url: string }) => uploadURL(data), { immediate: false } ); - const { send: restartCommand } = useRequest(SystemApi.restart(), { + const { send: restartCommand } = useRequest(restart(), { immediate: false }); - const restart = async () => { - await restartCommand() - .then(() => { - setRestarting(true); - }) - .catch((error: Error) => { - toast.error(error.message); - }); + const callRestart = async () => { + setRestarting(true); + await restartCommand().catch((error: Error) => { + toast.error(error.message); + }); }; const { send: sendCheckUpgrade } = useRequest(checkUpgrade, { @@ -387,10 +387,11 @@ const DownloadUpload = () => { )} - {upgradeAvailable ? ( - - -   {LL.UPGRADE_AVAILABLE()} + + +    + {upgradeAvailable ? LL.UPGRADE_AVAILABLE() : LL.LATEST_VERSION()} + {upgradeAvailable && ( - - ) : ( - {LL.LATEST_VERSION()} - )} + )} + + {renderUploadDialog()} @@ -411,24 +411,11 @@ const DownloadUpload = () => { {LL.UPLOAD()} - + {LL.UPLOAD_TEXT()} - {restartNeeded ? ( - - - - ) : ( - - )} + ); }; diff --git a/interface/src/app/status/RestartMonitor.tsx b/interface/src/app/status/RestartMonitor.tsx index 685cac3e8..4b1f32daf 100644 --- a/interface/src/app/status/RestartMonitor.tsx +++ b/interface/src/app/status/RestartMonitor.tsx @@ -1,13 +1,13 @@ import { type FC, useEffect, useRef, useState } from 'react'; -import * as SystemApi from 'api/system'; +import { readHardwareStatus } from 'api/system'; import { useRequest } from 'alova/client'; import { FormLoader } from 'components'; import { useI18nContext } from 'i18n/i18n-react'; const RESTART_TIMEOUT = 2 * 60 * 1000; // 2 minutes -const POLL_INTERVAL = 1000; // every 1 second +const POLL_INTERVAL = 2000; // every 2 seconds export interface RestartMonitorProps { message?: string; @@ -16,10 +16,12 @@ export interface RestartMonitorProps { const RestartMonitor: FC = ({ message }) => { const [failed, setFailed] = useState(false); const [timeoutId, setTimeoutId] = useState(); + const { LL } = useI18nContext(); + const timeoutAt = useRef(new Date().getTime() + RESTART_TIMEOUT); - const { send } = useRequest(SystemApi.readSystemStatus); + const { send } = useRequest(readHardwareStatus, { immediate: false }); const poll = useRef(async () => { try { @@ -35,7 +37,7 @@ const RestartMonitor: FC = ({ message }) => { }); useEffect(() => { - void poll.current(); + setTimeoutId(setTimeout(poll.current, POLL_INTERVAL)); }, []); useEffect(() => () => timeoutId && clearTimeout(timeoutId), [timeoutId]); diff --git a/interface/src/app/status/Status.tsx b/interface/src/app/status/Status.tsx index cca48dbee..95b880fa0 100644 --- a/interface/src/app/status/Status.tsx +++ b/interface/src/app/status/Status.tsx @@ -52,24 +52,12 @@ const SystemStatus = () => { const { me } = useContext(AuthenticatedContext); const [confirmRestart, setConfirmRestart] = useState(false); - const [processing, setProcessing] = useState(false); const [restarting, setRestarting] = useState(); const { send: restartCommand } = useRequest(SystemApi.restart(), { immediate: false }); - const { send: partitionCommand } = useRequest(SystemApi.partition(), { - immediate: false - }); - - const { send: factoryPartitionCommand } = useRequest( - SystemApi.factoryPartition(), - { - immediate: false - } - ); - const { data: data, send: loadData, @@ -208,7 +196,6 @@ const SystemStatus = () => { value ? theme.palette.success.main : theme.palette.info.main; const restart = async () => { - setProcessing(true); await restartCommand() .then(() => { setRestarting(true); @@ -218,37 +205,6 @@ const SystemStatus = () => { }) .finally(() => { setConfirmRestart(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 factoryPartition = async () => { - setProcessing(true); - await factoryPartitionCommand() - .then(() => { - setRestarting(true); - }) - .catch((error: Error) => { - toast.error(error.message); - }) - .finally(() => { - setConfirmRestart(false); - setProcessing(false); }); }; @@ -265,38 +221,14 @@ const SystemStatus = () => { startIcon={} variant="outlined" onClick={() => setConfirmRestart(false)} - disabled={processing} color="secondary" > {LL.CANCEL()} - {data.has_loader && ( - - )} - {data.has_partition && ( - - )}