fix(proxy): confirm runtime chain updates before UI changes

This commit is contained in:
Tunglies
2026-10-08 02:09:37 +08:00
parent 9e622a82c9
commit 5ed291c91f
7 changed files with 106 additions and 49 deletions
+24 -15
View File
@@ -445,10 +445,14 @@ export const ProxyChain = ({
if (isConnected) {
setIsConnecting(true)
try {
await mutate(() => updateProxyChainConfigInRuntime(null), {
id: 'update-proxy-chain-runtime',
errorNotice: false,
})
const result = await mutate(
() => updateProxyChainConfigInRuntime(null),
{
id: 'update-proxy-chain-runtime',
errorNotice: false,
},
)
if (!result.ok) return
const targetGroup =
mode === 'global'
@@ -519,10 +523,14 @@ export const ProxyChain = ({
// 第一步:保存链式代理配置
const chainProxies = currentProxyChain.map((node) => node.name)
debugLog('Saving chain config:', chainProxies)
await mutate(() => updateProxyChainConfigInRuntime(chainProxies), {
id: 'update-proxy-chain-runtime',
errorNotice: false,
})
const result = await mutate(
() => updateProxyChainConfigInRuntime(chainProxies),
{
id: 'update-proxy-chain-runtime',
errorNotice: false,
},
)
if (!result.ok) return
debugLog('Chain configuration saved successfully')
// 第二步:连接到代理链的最后一个节点
@@ -619,14 +627,15 @@ export const ProxyChain = ({
<IconButton
size="small"
onClick={() => {
mutate(() => updateProxyChainConfigInRuntime(null), {
void mutate(() => updateProxyChainConfigInRuntime(null), {
id: 'update-proxy-chain-runtime',
errorNotice: false,
})
localStorage.removeItem('proxy-chain-group')
localStorage.removeItem('proxy-chain-exit-node')
localStorage.removeItem('proxy-chain-items')
onUpdateChain([])
onFulfilled: () => {
localStorage.removeItem('proxy-chain-group')
localStorage.removeItem('proxy-chain-exit-node')
localStorage.removeItem('proxy-chain-items')
onUpdateChain([])
},
}).catch(() => {})
}}
sx={{
color: theme.palette.error.main,
+14 -8
View File
@@ -400,20 +400,26 @@ export function ProxyGroupsChain(props: ProxyGroupsChainProps) {
setRuleMenuAnchor(null)
}
const handleGroupSelect = (groupName: string) => {
onGroupSelect(groupName)
handleGroupMenuClose()
const handleGroupSelect = async (groupName: string) => {
if (mode === 'rule') {
mutate(() => updateProxyChainConfigInRuntime(null), {
id: 'update-proxy-chain-runtime',
errorNotice: false,
})
try {
const result = await mutate(
() => updateProxyChainConfigInRuntime(null),
{
id: 'update-proxy-chain-runtime',
},
)
if (!result.ok) return
} catch {
return
}
localStorage.removeItem('proxy-chain-group')
localStorage.removeItem('proxy-chain-exit-node')
localStorage.removeItem('proxy-chain-items')
setProxyChain([])
}
onGroupSelect(groupName)
handleGroupMenuClose()
}
const handleCloseDuplicateWarning = useCallback(() => {