diff --git a/src/components/setting/setting-clash.tsx b/src/components/setting/setting-clash.tsx index fed4fca6..92a18c81 100644 --- a/src/components/setting/setting-clash.tsx +++ b/src/components/setting/setting-clash.tsx @@ -1,5 +1,6 @@ import { useRef } from "react"; import { useTranslation } from "react-i18next"; +import { useLockFn } from "ahooks"; import { TextField, Switch, @@ -22,6 +23,7 @@ import { ClashCoreViewer } from "./mods/clash-core-viewer"; import { invoke_uwp_tool } from "@/services/cmds"; import getSystem from "@/utils/get-system"; import { useVerge } from "@/hooks/use-verge"; +import { updateGeoData } from "@/services/api"; const isWIN = getSystem() === "windows"; @@ -33,7 +35,6 @@ const SettingClash = ({ onError }: Props) => { const { t } = useTranslation(); const { clash, version, mutateClash, patchClash } = useClash(); - const { verge, mutateVerge, patchVerge } = useVerge(); const { ipv6, "allow-lan": allowLan, "log-level": logLevel } = clash ?? {}; @@ -57,6 +58,19 @@ const SettingClash = ({ onError }: Props) => { const onChangeVerge = (patch: Partial) => { mutateVerge({ ...verge, ...patch }, false); }; + const onUpdateGeo = useLockFn(async () => { + try { + 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()); + } + } + }); + return ( @@ -209,6 +223,17 @@ const SettingClash = ({ onError }: Props) => { )} + + + + + + ); }; diff --git a/src/locales/en.json b/src/locales/en.json index 0ded6bde..03734679 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -80,6 +80,7 @@ "System Proxy": "System Proxy", "System Proxy Setting": "System Proxy Setting", "Open UWP tool": "Open UWP tool", + "Update GeoData": "Update GeoData", "Proxy Guard": "Proxy Guard", "Guard Duration": "Guard Duration", "Proxy Bypass": "Proxy Bypass", diff --git a/src/locales/ru.json b/src/locales/ru.json index 724c3617..1e86e70d 100644 --- a/src/locales/ru.json +++ b/src/locales/ru.json @@ -74,6 +74,7 @@ "System Proxy": "Системный прокси", "System Proxy Setting": "Настройка системного прокси", "Open UWP tool": "Открыть UWP инструмент", + "Update GeoData": "Обновление GeoData", "Proxy Guard": "Защита прокси", "Guard Duration": "Период защиты", "Proxy Bypass": "Игнорирование прокси", diff --git a/src/locales/zh.json b/src/locales/zh.json index feff4b69..bd511742 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -80,6 +80,7 @@ "System Proxy": "系统代理", "System Proxy Setting": "系统代理设置", "Open UWP tool": "UWP工具", + "Update GeoData": "更新 GeoData", "Proxy Guard": "系统代理守卫", "Guard Duration": "代理守卫间隔", "Proxy Bypass": "代理绕过", diff --git a/src/services/api.ts b/src/services/api.ts index ab93f4ad..902994d1 100644 --- a/src/services/api.ts +++ b/src/services/api.ts @@ -55,6 +55,12 @@ export const updateConfigs = async (config: Partial) => { return instance.patch("/configs", config); }; +/// Update geo data +export const updateGeoData = async () => { + const instance = await getAxios(); + return instance.post("/configs/geo"); +}; + /// Get current rules export const getRules = async () => { const instance = await getAxios();