fix(sysproxy): avoid proxy reset during cold start or lightweight mode recovery (#7917)

* refactor(sysproxy-viewer): remove unused clashConfig and effect logic

* style(proxy-control-switches): add type import for DialogRef

* docs: add cold start proxy reset fix to changelog

* docs: update changelog with recent fixes
This commit is contained in:
oomeow
2026-09-13 13:26:29 +00:00
committed by GitHub
parent 6695268905
commit bfef4e84ea
3 changed files with 9 additions and 42 deletions
+1
View File
@@ -23,6 +23,7 @@
- 修复订阅编辑器因节点名称为空而崩溃、因格式错误而丢失内容的问题
- 修复 DNS 编辑器空内容报错、初始值覆盖已有设置的问题
- 修复关闭自动检查更新后,手动检查更新无效的问题
- 修复应用冷启动或从轻量模式打开界面时, 系统代理被重复设置的问题
**🖥️ Windows**
@@ -18,7 +18,6 @@ import {
useEffect,
useImperativeHandle,
useMemo,
useRef,
useState,
} from 'react'
import { useTranslation } from 'react-i18next'
@@ -27,7 +26,7 @@ import {
BaseDialog,
BaseFieldset,
BaseSplitChipEditor,
DialogRef,
type DialogRef,
Switch,
TooltipIcon,
} from '@/components/base'
@@ -35,7 +34,7 @@ import { EditorViewer } from '@/components/profile/editor-viewer'
import { useDisplayedMixedPort } from '@/hooks/use-displayed-mixed-port'
import { useSystemProxyState } from '@/hooks/use-system-proxy-state'
import { useVerge } from '@/hooks/use-verge'
import { useClashConfigData, useSystemData } from '@/providers/app-data-context'
import { useSystemData } from '@/providers/app-data-context'
import {
getAutotemProxy,
getEmbeddedServerPort,
@@ -110,7 +109,6 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
const { verge, patchVerge, mutateVerge } = useVerge()
const [hostOptions, setHostOptions] = useState<string[]>([])
const { clashConfig } = useClashConfigData()
const { indicator: isProxyReallyEnabled, invalidateProxyState } =
useSystemProxyState()
@@ -156,38 +154,6 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
return '127.0.0.1,192.168.0.0/16,10.0.0.0/8,172.16.0.0/12,localhost,*.local,*.crashlytics.com,<local>'
}
const prevMixedPortRef = useRef(clashConfig?.mixedPort)
useEffect(() => {
const mixedPort = clashConfig?.mixedPort
if (!mixedPort || mixedPort === prevMixedPortRef.current) {
return
}
prevMixedPortRef.current = mixedPort
if (!enabled) {
return
}
const updateProxy = async () => {
try {
const currentSysProxy = await getSystemProxy()
const currentAutoProxy = await getAutotemProxy()
if (value.pac ? currentAutoProxy?.enable : currentSysProxy?.enable) {
await patchVergeConfig({ enable_system_proxy: false })
await sleep(200)
await patchVergeConfig({ enable_system_proxy: true })
await invalidateProxyState()
}
} catch (err) {
showNotice.error(err)
}
}
updateProxy()
}, [clashConfig?.mixedPort, enabled, value.pac, invalidateProxyState])
const { systemProxyAddress } = useSystemData()
const displayedMixedPort = useDisplayedMixedPort()
@@ -256,10 +222,10 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
interfaces.forEach((iface) => {
iface.addr.forEach((address) => {
if (address.V4 && address.V4.ip) {
if (address.V4?.ip) {
ipAddresses.push(address.V4.ip)
}
if (address.V6 && address.V6.ip) {
if (address.V6?.ip) {
ipAddresses.push(address.V6.ip)
}
})
@@ -277,7 +243,7 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
if (hostname) {
if (hostname !== 'localhost' && hostname !== '127.0.0.1') {
hostname = hostname + '.local'
hostname = `${hostname}.local`
options.push(hostname)
debugLog('主机名已添加到选项中:', hostname)
} else {
@@ -409,7 +375,7 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
if (isProxyActive) {
await patchVergeConfig({ enable_system_proxy: false })
await new Promise((resolve) => setTimeout(resolve, 50))
await sleep(50)
await patchVergeConfig({ enable_system_proxy: true })
await invalidateProxyState()
}
@@ -7,10 +7,10 @@ import {
} from '@mui/icons-material'
import { Box, Typography, alpha, useTheme } from '@mui/material'
import { useLockFn } from 'ahooks'
import React, { useRef, useState } from 'react'
import { useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { DialogRef, Switch, TooltipIcon } from '@/components/base'
import { type DialogRef, Switch, TooltipIcon } from '@/components/base'
import { SysproxyViewer } from '@/components/setting/mods/sysproxy-viewer'
import { TunViewer } from '@/components/setting/mods/tun-viewer'
import { useServiceUninstaller } from '@/hooks/use-service-uninstaller'