Support upgrade alpha core

This commit is contained in:
MystiPanda 2023-12-10 15:57:10 +08:00
parent bb985f826e
commit f048762fd9
6 changed files with 35 additions and 10 deletions

View File

@ -14,7 +14,7 @@ import {
ListItemText, ListItemText,
} from "@mui/material"; } from "@mui/material";
import { changeClashCore, restartSidecar } from "@/services/cmds"; import { changeClashCore, restartSidecar } from "@/services/cmds";
import { closeAllConnections } from "@/services/api"; import { closeAllConnections, upgradeCore } from "@/services/api";
import { grantPermission } from "@/services/cmds"; import { grantPermission } from "@/services/cmds";
import getSystem from "@/utils/get-system"; import getSystem from "@/utils/get-system";
@ -76,16 +76,36 @@ export const ClashCoreViewer = forwardRef<DialogRef>((props, ref) => {
} }
}); });
const onUpgrade = useLockFn(async () => {
try {
await upgradeCore();
Notice.success(`Successfully upgrade core`, 1000);
} catch (err: any) {
Notice.error(err?.response.data.message || err.toString());
}
});
return ( return (
<BaseDialog <BaseDialog
open={open} open={open}
title={ title={
<Box display="flex" justifyContent="space-between"> <Box display="flex" justifyContent="space-between">
{t("Clash Core")} {t("Clash Core")}
<Box>
<Button variant="contained" size="small" onClick={onRestart}> {clash_core !== "clash-meta" && (
{t("Restart")} <Button
</Button> variant="contained"
size="small"
sx={{ marginRight: "8px" }}
onClick={onUpgrade}
>
{t("Upgrade")}
</Button>
)}
<Button variant="contained" size="small" onClick={onRestart}>
{t("Restart")}
</Button>
</Box>
</Box> </Box>
} }
contentSx={{ contentSx={{

View File

@ -63,11 +63,7 @@ const SettingClash = ({ onError }: Props) => {
await updateGeoData(); await updateGeoData();
Notice.success("Start update geodata"); Notice.success("Start update geodata");
} catch (err: any) { } catch (err: any) {
if (err.response.status === 400) { Notice.error(err?.response.data.message || err.toString());
Notice.success("Updating geodata...");
} else {
Notice.error(err.message || err.toString());
}
} }
}); });

View File

@ -112,6 +112,7 @@
"Runtime Config": "Runtime Config", "Runtime Config": "Runtime Config",
"ReadOnly": "ReadOnly", "ReadOnly": "ReadOnly",
"Restart": "Restart", "Restart": "Restart",
"Upgrade": "Upgrade",
"Back": "Back", "Back": "Back",
"Save": "Save", "Save": "Save",

View File

@ -99,6 +99,7 @@
"Runtime Config": "Используемый конфиг", "Runtime Config": "Используемый конфиг",
"ReadOnly": "Только для чтения", "ReadOnly": "Только для чтения",
"Restart": "Перезапуск", "Restart": "Перезапуск",
"Upgrade": "Обновлять",
"Back": "Назад", "Back": "Назад",
"Save": "Сохранить", "Save": "Сохранить",

View File

@ -112,6 +112,7 @@
"Runtime Config": "当前配置", "Runtime Config": "当前配置",
"ReadOnly": "只读", "ReadOnly": "只读",
"Restart": "重启内核", "Restart": "重启内核",
"Upgrade": "升级内核",
"Back": "返回", "Back": "返回",
"Save": "保存", "Save": "保存",

View File

@ -61,6 +61,12 @@ export const updateGeoData = async () => {
return instance.post("/configs/geo"); return instance.post("/configs/geo");
}; };
/// Upgrade clash core
export const upgradeCore = async () => {
const instance = await getAxios();
return instance.post("/upgrade");
};
/// Get current rules /// Get current rules
export const getRules = async () => { export const getRules = async () => {
const instance = await getAxios(); const instance = await getAxios();