Quellcode durchsuchen

Support upgrade alpha core

MystiPanda vor 1 Jahr
Ursprung
Commit
0c3f03680c

+ 25 - 5
src/components/setting/mods/clash-core-viewer.tsx

@@ -14,7 +14,7 @@ import {
   ListItemText,
 } from "@mui/material";
 import { changeClashCore, restartSidecar } from "@/services/cmds";
-import { closeAllConnections } from "@/services/api";
+import { closeAllConnections, upgradeCore } from "@/services/api";
 import { grantPermission } from "@/services/cmds";
 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 (
     <BaseDialog
       open={open}
       title={
         <Box display="flex" justifyContent="space-between">
           {t("Clash Core")}
-
-          <Button variant="contained" size="small" onClick={onRestart}>
-            {t("Restart")}
-          </Button>
+          <Box>
+            {clash_core !== "clash-meta" && (
+              <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>
       }
       contentSx={{

+ 1 - 5
src/components/setting/setting-clash.tsx

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

+ 1 - 0
src/locales/en.json

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

+ 1 - 0
src/locales/ru.json

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

+ 1 - 0
src/locales/zh.json

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

+ 6 - 0
src/services/api.ts

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