diff --git a/src/components/setting/mods/tun-viewer.tsx b/src/components/setting/mods/tun-viewer.tsx index 9474c2b21..90cdf94cd 100644 --- a/src/components/setting/mods/tun-viewer.tsx +++ b/src/components/setting/mods/tun-viewer.tsx @@ -12,7 +12,13 @@ import type { Ref } from "react"; import { useImperativeHandle, useState } from "react"; import { useTranslation } from "react-i18next"; -import { BaseDialog, DialogRef, Switch, TooltipIcon } from "@/components/base"; +import { + BaseDialog, + BaseSplitChipEditor, + TooltipIcon, + DialogRef, + Switch, +} from "@/components/base"; import { useClash } from "@/hooks/use-clash"; import { enhanceProfiles } from "@/services/cmds"; import { showNotice } from "@/services/notice-service"; @@ -22,6 +28,12 @@ import { StackModeSwitch } from "./stack-mode-switch"; const OS = getSystem(); +const splitRouteExcludeAddress = (value: string) => + value + .split(/[,\n;\r]+/) + .map((item) => item.trim()) + .filter(Boolean); + export function TunViewer({ ref }: { ref?: Ref }) { const { t } = useTranslation(); @@ -32,6 +44,7 @@ export function TunViewer({ ref }: { ref?: Ref }) { stack: "mixed", device: OS === "macos" ? "utun1024" : "Mihomo", autoRoute: true, + routeExcludeAddress: "", autoRedirect: false, autoDetectInterface: true, dnsHijack: ["any:53"], @@ -50,6 +63,9 @@ export function TunViewer({ ref }: { ref?: Ref }) { stack: clash?.tun.stack ?? "gvisor", device: clash?.tun.device ?? (OS === "macos" ? "utun1024" : "Mihomo"), autoRoute: nextAutoRoute, + routeExcludeAddress: (clash?.tun["route-exclude-address"] ?? []).join( + ",", + ), autoRedirect: computedAutoRedirect, autoDetectInterface: clash?.tun["auto-detect-interface"] ?? true, dnsHijack: clash?.tun["dns-hijack"] ?? ["any:53"], @@ -62,6 +78,9 @@ export function TunViewer({ ref }: { ref?: Ref }) { const onSave = useLockFn(async () => { try { + const routeExcludeAddress = splitRouteExcludeAddress( + values.routeExcludeAddress, + ); const tun: IConfigData["tun"] = { stack: values.stack, device: @@ -71,6 +90,7 @@ export function TunViewer({ ref }: { ref?: Ref }) { : "Mihomo" : values.device, "auto-route": values.autoRoute, + "route-exclude-address": routeExcludeAddress, ...(OS === "linux" ? { "auto-redirect": values.autoRedirect, @@ -120,6 +140,7 @@ export function TunViewer({ ref }: { ref?: Ref }) { : {}), "auto-detect-interface": true, "dns-hijack": ["any:53"], + "route-exclude-address": [], "strict-route": false, mtu: 1500, }; @@ -127,6 +148,7 @@ export function TunViewer({ ref }: { ref?: Ref }) { stack: "gvisor", device: OS === "macos" ? "utun1024" : "Mihomo", autoRoute: true, + routeExcludeAddress: "", autoRedirect: false, autoDetectInterface: true, dnsHijack: ["any:53"], @@ -284,6 +306,26 @@ export function TunViewer({ ref }: { ref?: Ref }) { } /> + + + setValues((v) => ({ ...v, routeExcludeAddress: nextValue })) + } + renderHeader={(modeToggle) => ( + + + {modeToggle ? ( + {modeToggle} + ) : null} + + )} + /> ); diff --git a/src/locales/ar/settings.json b/src/locales/ar/settings.json index 9e65dab78..9bed7f06e 100644 --- a/src/locales/ar/settings.json +++ b/src/locales/ar/settings.json @@ -444,6 +444,7 @@ "stack": "مكدس TUN", "device": "Device Name", "autoRoute": "توجيه تلقائي", + "routeExcludeAddress": "عناوين مستثناة من التوجيه", "strictRoute": "توجيه صارم", "autoDetectInterface": "الكشف التلقائي عن الواجهة", "dnsHijack": "اختطاف DNS", diff --git a/src/locales/de/settings.json b/src/locales/de/settings.json index f6dcce83e..d534fc4c0 100644 --- a/src/locales/de/settings.json +++ b/src/locales/de/settings.json @@ -444,6 +444,7 @@ "stack": "TUN-Modus-Stack", "device": "Device Name", "autoRoute": "Globale Routing automatisch einstellen", + "routeExcludeAddress": "Routen-Ausnahmeadressen", "strictRoute": "Strenges Routing", "autoDetectInterface": "Netzwerkschnittstelle automatisch auswählen", "dnsHijack": "DNS-Hijacking", diff --git a/src/locales/en/settings.json b/src/locales/en/settings.json index 62050797a..0c7799a8a 100644 --- a/src/locales/en/settings.json +++ b/src/locales/en/settings.json @@ -444,6 +444,7 @@ "stack": "Tun Stack", "device": "Device Name", "autoRoute": "Auto Route", + "routeExcludeAddress": "Route Exclude Address", "strictRoute": "Strict Route", "autoDetectInterface": "Auto Detect Interface", "dnsHijack": "DNS Hijack", diff --git a/src/locales/es/settings.json b/src/locales/es/settings.json index ec5789add..517af3902 100644 --- a/src/locales/es/settings.json +++ b/src/locales/es/settings.json @@ -444,6 +444,7 @@ "stack": "Pila del modo TUN", "device": "Device Name", "autoRoute": "Configurar enrutamiento global automáticamente", + "routeExcludeAddress": "Direcciones excluidas de ruta", "strictRoute": "Enrutamiento estricto", "autoDetectInterface": "Detectar automáticamente la interfaz de salida del tráfico", "dnsHijack": "Secuestro de DNS", diff --git a/src/locales/fa/settings.json b/src/locales/fa/settings.json index 665baea70..996c71ad3 100644 --- a/src/locales/fa/settings.json +++ b/src/locales/fa/settings.json @@ -444,6 +444,7 @@ "stack": "انباشته Tun", "device": "Device Name", "autoRoute": "مسیر خودکار", + "routeExcludeAddress": "نشانی‌های مستثنا از مسیردهی", "strictRoute": "مسیر دقیق", "autoDetectInterface": "تشخیص خودکار رابط", "dnsHijack": "ربایش DNS", diff --git a/src/locales/id/settings.json b/src/locales/id/settings.json index c4e483e74..be6bb5128 100644 --- a/src/locales/id/settings.json +++ b/src/locales/id/settings.json @@ -444,6 +444,7 @@ "stack": "Tumpukan Tun", "device": "Device Name", "autoRoute": "Rute Otomatis", + "routeExcludeAddress": "Alamat Pengecualian Rute", "strictRoute": "Rute Ketat", "autoDetectInterface": "Deteksi Antarmuka Otomatis", "dnsHijack": "Pembajakan DNS", diff --git a/src/locales/jp/settings.json b/src/locales/jp/settings.json index 27190f882..669736c04 100644 --- a/src/locales/jp/settings.json +++ b/src/locales/jp/settings.json @@ -444,6 +444,7 @@ "stack": "TUNモードスタック", "device": "Device Name", "autoRoute": "グローバルルートを自動設定", + "routeExcludeAddress": "ルート除外アドレス", "strictRoute": "厳格なルート", "autoDetectInterface": "トラフィックの出口インターフェースを自動選択", "dnsHijack": "DNSハイジャック", diff --git a/src/locales/ko/settings.json b/src/locales/ko/settings.json index 871e2fea4..37e81fe49 100644 --- a/src/locales/ko/settings.json +++ b/src/locales/ko/settings.json @@ -444,6 +444,7 @@ "stack": "스택", "device": "장치 이름", "autoRoute": "자동 라우팅", + "routeExcludeAddress": "라우트 제외 주소", "strictRoute": "엄격 라우팅", "autoDetectInterface": "인터페이스 자동 감지", "dnsHijack": "DNS 하이재킹", diff --git a/src/locales/ru/settings.json b/src/locales/ru/settings.json index 9de3ce390..2b2859718 100644 --- a/src/locales/ru/settings.json +++ b/src/locales/ru/settings.json @@ -444,6 +444,7 @@ "stack": "Стек", "device": "Device Name", "autoRoute": "Автоматическая маршрутизация", + "routeExcludeAddress": "Адреса исключения маршрута", "strictRoute": "Строгая маршрутизация", "autoDetectInterface": "Автоопределение интерфейса", "dnsHijack": "DNS-перехват", diff --git a/src/locales/tr/settings.json b/src/locales/tr/settings.json index c9e676f2f..e8bb49021 100644 --- a/src/locales/tr/settings.json +++ b/src/locales/tr/settings.json @@ -444,6 +444,7 @@ "stack": "Tun Yığını", "device": "Device Name", "autoRoute": "Otomatik Yönlendirme", + "routeExcludeAddress": "Yönlendirme Hariç Adresler", "strictRoute": "Katı Yönlendirme", "autoDetectInterface": "Arayüzü Otomatik Algıla", "dnsHijack": "DNS Ele Geçirme", diff --git a/src/locales/tt/settings.json b/src/locales/tt/settings.json index 575d66146..9cfa0c170 100644 --- a/src/locales/tt/settings.json +++ b/src/locales/tt/settings.json @@ -444,6 +444,7 @@ "stack": "Стек", "device": "Device Name", "autoRoute": "Авто-маршрутлау", + "routeExcludeAddress": "Route Exclude Address", "strictRoute": "Катгый маршрутлау", "autoDetectInterface": "Интерфейсны автоматик ачыклау", "dnsHijack": "DNS'ны үзгәртеп тоту (hijack)", diff --git a/src/locales/zh/settings.json b/src/locales/zh/settings.json index 16ea28488..26476b46c 100644 --- a/src/locales/zh/settings.json +++ b/src/locales/zh/settings.json @@ -444,6 +444,7 @@ "stack": "TUN 模式堆栈", "device": "虚拟网卡名称", "autoRoute": "自动设置全局路由", + "routeExcludeAddress": "排除自定义网段", "strictRoute": "严格路由", "autoDetectInterface": "自动选择流量出口接口", "dnsHijack": "DNS 劫持", diff --git a/src/locales/zhtw/settings.json b/src/locales/zhtw/settings.json index cbde72131..6f0e42adb 100644 --- a/src/locales/zhtw/settings.json +++ b/src/locales/zhtw/settings.json @@ -444,6 +444,7 @@ "stack": "虛擬網路介面卡模式堆疊", "device": "Device Name", "autoRoute": "自動設定全域路由", + "routeExcludeAddress": "排除自訂網段", "strictRoute": "嚴格路由", "autoDetectInterface": "自動偵測流量輸出介面", "dnsHijack": "DNS 綁架", diff --git a/src/types/generated/i18n-keys.ts b/src/types/generated/i18n-keys.ts index 4c4878c4d..3de3504c1 100644 --- a/src/types/generated/i18n-keys.ts +++ b/src/types/generated/i18n-keys.ts @@ -572,6 +572,7 @@ export const translationKeys = [ "settings.modals.tun.fields.stack", "settings.modals.tun.fields.device", "settings.modals.tun.fields.autoRoute", + "settings.modals.tun.fields.routeExcludeAddress", "settings.modals.tun.fields.strictRoute", "settings.modals.tun.fields.autoDetectInterface", "settings.modals.tun.fields.dnsHijack", diff --git a/src/types/generated/i18n-resources.ts b/src/types/generated/i18n-resources.ts index 461d34be9..4767037d0 100644 --- a/src/types/generated/i18n-resources.ts +++ b/src/types/generated/i18n-resources.ts @@ -1015,6 +1015,7 @@ export interface TranslationResources { device: string; dnsHijack: string; mtu: string; + routeExcludeAddress: string; stack: string; strictRoute: string; }; diff --git a/src/types/global.d.ts b/src/types/global.d.ts index 0387e4f3f..85c273151 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -44,6 +44,7 @@ interface IConfigData { "auto-redirect"?: boolean; "auto-detect-interface": boolean; "dns-hijack": string[]; + "route-exclude-address"?: string[]; "strict-route": boolean; mtu: number; };