import { useCallback , useState } from "react"; import { useNavigate } from "react-router"; import { useJsonRpc } from "@hooks/useJsonRpc"; import { Button } from "@components/Button"; import { useFailsafeModeStore } from "@/hooks/stores"; import { sleep } from "@/utils"; import { m } from "@localizations/messages.js"; import LoadingSpinner from "../components/LoadingSpinner"; import { useDeviceUiNavigation } from "../hooks/useAppNavigation"; // Time to wait after initiating reboot before redirecting to home const REBOOT_REDIRECT_DELAY_MS = 5000; export default function SettingsGeneralRebootRoute() { const navigate = useNavigate(); const { send } = useJsonRpc(); const [isRebooting, setIsRebooting] = useState(false); const { navigateTo } = useDeviceUiNavigation(); const { setFailsafeMode } = useFailsafeModeStore(); const onClose = useCallback(async () => { navigate(".."); // back to the devices.$id.settings page // Add 1s delay between navigation and calling reload() to prevent reload from interrupting the navigation. await sleep(1000); window.location.reload(); // force a full reload to ensure the current device/cloud UI version is loaded }, [navigate]); const onConfirmUpdate = useCallback(async () => { setIsRebooting(true); send("reboot", { force: true }); await new Promise(resolve => setTimeout(resolve, REBOOT_REDIRECT_DELAY_MS)); setFailsafeMode(false, ""); navigateTo("/"); }, [navigateTo, send, setFailsafeMode]); return ; } export function Dialog({ isRebooting, onClose, onConfirmUpdate, }: Readonly<{ isRebooting: boolean; onClose: () => void; onConfirmUpdate: () => void; }>) { return (
{m.general_reboot_title()}
{m.general_reboot_description()}
{isRebooting ? (