mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-05 05:50:04 +08:00
chore: trim excessive comments
This commit is contained in:
@@ -191,7 +191,6 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
const { systemProxyAddress } = useSystemData()
|
||||
const displayedMixedPort = useDisplayedMixedPort()
|
||||
|
||||
// 为当前状态计算系统代理地址
|
||||
const getSystemProxyAddress = useMemo(() => {
|
||||
const isPacMode = value.pac ?? false
|
||||
|
||||
@@ -250,14 +249,11 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
close: () => setOpen(false),
|
||||
}))
|
||||
|
||||
// 获取网络接口和主机名
|
||||
const fetchNetworkInterfaces = async () => {
|
||||
try {
|
||||
// 获取系统网络接口信息
|
||||
const interfaces = await getNetworkInterfacesInfo()
|
||||
const ipAddresses: string[] = []
|
||||
|
||||
// 从interfaces中提取IPv4和IPv6地址
|
||||
interfaces.forEach((iface) => {
|
||||
iface.addr.forEach((address) => {
|
||||
if (address.V4 && address.V4.ip) {
|
||||
@@ -269,7 +265,6 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
})
|
||||
})
|
||||
|
||||
// 获取当前系统的主机名
|
||||
let hostname = ''
|
||||
try {
|
||||
hostname = await getSystemHostname()
|
||||
@@ -278,12 +273,9 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
console.error('获取主机名失败:', err)
|
||||
}
|
||||
|
||||
// 构建选项列表
|
||||
const options = ['127.0.0.1', 'localhost']
|
||||
|
||||
// 确保主机名添加到列表,即使它是空字符串也记录下来
|
||||
if (hostname) {
|
||||
// 如果主机名不是localhost或127.0.0.1,则添加它
|
||||
if (hostname !== 'localhost' && hostname !== '127.0.0.1') {
|
||||
hostname = hostname + '.local'
|
||||
options.push(hostname)
|
||||
@@ -295,16 +287,13 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
debugLog('主机名为空')
|
||||
}
|
||||
|
||||
// 添加IP地址
|
||||
options.push(...ipAddresses)
|
||||
|
||||
// 去重
|
||||
const uniqueOptions = Array.from(new Set(options))
|
||||
debugLog('最终选项列表:', uniqueOptions)
|
||||
setHostOptions(uniqueOptions)
|
||||
} catch (error) {
|
||||
console.error('获取网络接口失败:', error)
|
||||
// 失败时至少提供基本选项
|
||||
setHostOptions(['127.0.0.1', 'localhost'])
|
||||
}
|
||||
}
|
||||
@@ -325,7 +314,6 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
return
|
||||
}
|
||||
|
||||
// 修改验证规则,允许IP和主机名
|
||||
const ipv4Regex =
|
||||
/^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
|
||||
const ipv6Regex =
|
||||
@@ -369,7 +357,6 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
let pacContent = value.pac_content
|
||||
if (pacContent) {
|
||||
pacContent = pacContent.replace(/%proxy_host%/g, value.proxy_host)
|
||||
// 将 mixed-port 转换为字符串
|
||||
const mixedPortStr = displayedMixedPort.toString()
|
||||
pacContent = pacContent.replace(/%mixed-port%/g, mixedPortStr)
|
||||
}
|
||||
@@ -378,7 +365,6 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
patch.pac_file_content = pacContent
|
||||
}
|
||||
|
||||
// 处理IPv6地址,如果是IPv6地址但没有被方括号包围,则添加方括号
|
||||
let proxyHost = value.proxy_host
|
||||
if (
|
||||
ipv6Regex.test(proxyHost) &&
|
||||
@@ -392,7 +378,6 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
patch.proxy_host = proxyHost
|
||||
}
|
||||
|
||||
// 判断是否需要重置系统代理
|
||||
const needResetProxy =
|
||||
value.pac !== proxy_auto_config ||
|
||||
proxyHost !== proxy_host ||
|
||||
@@ -402,7 +387,6 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
|
||||
Promise.resolve().then(async () => {
|
||||
try {
|
||||
// 乐观更新本地状态
|
||||
if (Object.keys(patch).length > 0) {
|
||||
mutateVerge({ ...verge, ...patch }, false)
|
||||
}
|
||||
@@ -413,7 +397,6 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
try {
|
||||
await invalidateProxyState()
|
||||
|
||||
// 如果需要重置代理且代理当前启用
|
||||
if (needResetProxy && enabled) {
|
||||
const [currentSysProxy, currentAutoProxy] = await Promise.all([
|
||||
getSystemProxy(),
|
||||
@@ -439,7 +422,6 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
console.error('配置保存失败:', err)
|
||||
mutateVerge()
|
||||
showNotice.error(err)
|
||||
// setOpen(true);
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -587,7 +569,6 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
setValue((v) => ({
|
||||
...v,
|
||||
use_default: e,
|
||||
// 当取消选择use_default且当前bypass为空时,填充默认值
|
||||
bypass: nextBypass,
|
||||
}))
|
||||
return
|
||||
@@ -697,6 +678,5 @@ const FlexBox = styled('div')`
|
||||
|
||||
.label {
|
||||
flex: none;
|
||||
//width: 85px;
|
||||
}
|
||||
`
|
||||
|
||||
Reference in New Issue
Block a user