chore: Optimize upgrade process

This commit is contained in:
MystiPanda 2023-12-14 11:24:16 +08:00
parent 90f4809b7c
commit 76f9db8516

View File

@ -4,7 +4,8 @@ import { BaseDialog, DialogRef, Notice } from "@/components/base";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useVerge } from "@/hooks/use-verge"; import { useVerge } from "@/hooks/use-verge";
import { useLockFn } from "ahooks"; import { useLockFn } from "ahooks";
import { Lock } from "@mui/icons-material"; import { LoadingButton } from "@mui/lab";
import { SwitchAccessShortcut, RestartAlt } from "@mui/icons-material";
import { import {
Box, Box,
Button, Button,
@ -31,6 +32,7 @@ export const ClashCoreViewer = forwardRef<DialogRef>((props, ref) => {
const { verge, mutateVerge } = useVerge(); const { verge, mutateVerge } = useVerge();
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [upgrading, setUpgrading] = useState(false);
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
open: () => setOpen(true), open: () => setOpen(true),
@ -78,9 +80,12 @@ export const ClashCoreViewer = forwardRef<DialogRef>((props, ref) => {
const onUpgrade = useLockFn(async () => { const onUpgrade = useLockFn(async () => {
try { try {
setUpgrading(true);
await upgradeCore(); await upgradeCore();
setUpgrading(false);
Notice.success(`Successfully upgrade core`, 1000); Notice.success(`Successfully upgrade core`, 1000);
} catch (err: any) { } catch (err: any) {
setUpgrading(false);
Notice.error(err?.response.data.message || err.toString()); Notice.error(err?.response.data.message || err.toString());
} }
}); });
@ -93,16 +98,24 @@ export const ClashCoreViewer = forwardRef<DialogRef>((props, ref) => {
{t("Clash Core")} {t("Clash Core")}
<Box> <Box>
{clash_core !== "clash-meta" && ( {clash_core !== "clash-meta" && (
<Button <LoadingButton
variant="contained" variant="contained"
size="small" size="small"
startIcon={<SwitchAccessShortcut />}
loadingPosition="start"
loading={upgrading}
sx={{ marginRight: "8px" }} sx={{ marginRight: "8px" }}
onClick={onUpgrade} onClick={onUpgrade}
> >
{t("Upgrade")} {t("Upgrade")}
</Button> </LoadingButton>
)} )}
<Button variant="contained" size="small" onClick={onRestart}> <Button
variant="contained"
size="small"
onClick={onRestart}
startIcon={<RestartAlt />}
>
{t("Restart")} {t("Restart")}
</Button> </Button>
</Box> </Box>
@ -110,7 +123,7 @@ export const ClashCoreViewer = forwardRef<DialogRef>((props, ref) => {
} }
contentSx={{ contentSx={{
pb: 0, pb: 0,
width: 320, width: 400,
height: 180, height: 180,
overflowY: "auto", overflowY: "auto",
userSelect: "text", userSelect: "text",