From c0d3adfe21bc78772ac2df3a2344d91768436c4f Mon Sep 17 00:00:00 2001 From: yyhhyy <95077259+yyhhyyyyyy@users.noreply.github.com> Date: Thu, 7 Nov 2024 20:23:36 +0800 Subject: [PATCH] add route-exclude-address setting (#319) --- src/main/utils/template.ts | 1 + src/renderer/src/pages/tun.tsx | 47 +++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/main/utils/template.ts b/src/main/utils/template.ts index 16f9b89..91e390f 100644 --- a/src/main/utils/template.ts +++ b/src/main/utils/template.ts @@ -63,6 +63,7 @@ export const defaultControledMihomoConfig: Partial = { 'auto-redirect': false, 'auto-detect-interface': true, 'dns-hijack': ['any:53'], + 'route-exclude-address': [], mtu: 1500 }, dns: { diff --git a/src/renderer/src/pages/tun.tsx b/src/renderer/src/pages/tun.tsx index eb1a484..eb33250 100644 --- a/src/renderer/src/pages/tun.tsx +++ b/src/renderer/src/pages/tun.tsx @@ -8,6 +8,7 @@ import { platform } from '@renderer/utils/init' import React, { Key, useState } from 'react' import BasePasswordModal from '@renderer/components/base/base-password-modal' import { useAppConfig } from '@renderer/hooks/use-app-config' +import { MdDeleteForever } from 'react-icons/md' const Tun: React.FC = () => { const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig() @@ -23,6 +24,7 @@ const Tun: React.FC = () => { 'auto-redirect': autoRedirect = false, 'auto-detect-interface': autoDetectInterface = true, 'dns-hijack': dnsHijack = ['any:53'], + 'route-exclude-address': routeExcludeAddress = [], 'strict-route': strictRoute = false, mtu = 1500 } = tun || {} @@ -35,6 +37,7 @@ const Tun: React.FC = () => { autoDetectInterface, dnsHijack, strictRoute, + routeExcludeAddress, mtu }) const setValues = (v: typeof values): void => { @@ -42,6 +45,22 @@ const Tun: React.FC = () => { setChanged(true) } + const handleExcludeAddressChange = (value: string, index: number): void => { + const newExcludeAddresses = [...values.routeExcludeAddress] + if (index === newExcludeAddresses.length) { + if (value.trim() !== '') { + newExcludeAddresses.push(value) + } + } else { + if (value.trim() === '') { + newExcludeAddresses.splice(index, 1) + } else { + newExcludeAddresses[index] = value + } + } + setValues({ ...values, routeExcludeAddress: newExcludeAddresses }) + } + const onSave = async (patch: Partial): Promise => { await patchControledMihomoConfig(patch) await restartCore() @@ -83,6 +102,7 @@ const Tun: React.FC = () => { 'auto-detect-interface': values.autoDetectInterface, 'dns-hijack': values.dnsHijack, 'strict-route': values.strictRoute, + 'route-exclude-address': values.routeExcludeAddress, mtu: values.mtu } }) @@ -226,7 +246,7 @@ const Tun: React.FC = () => { }} /> - + { }} /> +
+

排除自定义网段

+ {[...values.routeExcludeAddress, ''].map((address, index) => ( +
+ handleExcludeAddressChange(v, index)} + /> + {index < values.routeExcludeAddress.length && ( + + )} +
+ ))} +