From 4e5ac8683b6de668e4ca59878303b428b7cbfa2f Mon Sep 17 00:00:00 2001 From: wonfen Date: Mon, 19 Oct 2026 20:01:43 +0800 Subject: [PATCH] feat(proxy): confirm before enabling chain proxy Show the speed warning with explicit enable/keep-disabled actions, and add a close button to the empty chain panel. --- Changelog.md | 1 + src/components/proxy/proxy-chain.tsx | 7 +++ src/components/proxy/proxy-groups-chain.tsx | 3 + src/components/proxy/proxy-groups.tsx | 13 +++- src/locales/ar/proxies.json | 2 + src/locales/de/proxies.json | 2 + src/locales/en/proxies.json | 2 + src/locales/es/proxies.json | 2 + src/locales/fa/proxies.json | 2 + src/locales/id/proxies.json | 2 + src/locales/jp/proxies.json | 2 + src/locales/ko/proxies.json | 2 + src/locales/pt/proxies.json | 2 + src/locales/ru/proxies.json | 2 + src/locales/tr/proxies.json | 2 + src/locales/tt/proxies.json | 2 + src/locales/zh/proxies.json | 2 + src/locales/zhtw/proxies.json | 2 + src/pages/proxies.tsx | 67 +++++++++++++-------- src/types/generated/i18n-keys.ts | 2 + src/types/generated/i18n-resources.ts | 2 + 21 files changed, 96 insertions(+), 27 deletions(-) diff --git a/Changelog.md b/Changelog.md index 310e376f8..d738083fc 100644 --- a/Changelog.md +++ b/Changelog.md @@ -22,6 +22,7 @@
🚀 优化改进 +- 优化「链式代理」:开启前需确认网速影响提示,空面板新增「关闭」按钮 **🖥️ Windows** diff --git a/src/components/proxy/proxy-chain.tsx b/src/components/proxy/proxy-chain.tsx index 439b23e2e..1eb188165 100644 --- a/src/components/proxy/proxy-chain.tsx +++ b/src/components/proxy/proxy-chain.tsx @@ -75,6 +75,7 @@ interface ProxyChainProps { onMarkUnsavedChanges?: () => void mode?: string selectedGroup?: string | null + onExitChainMode: () => void } interface ProxyChainItemProps { @@ -331,6 +332,7 @@ export const ProxyChain = ({ onMarkUnsavedChanges, mode, selectedGroup, + onExitChainMode, }: ProxyChainProps) => { const theme = useTheme() const { t } = useTranslation() @@ -696,13 +698,18 @@ export const ProxyChain = ({ {t('proxies.page.chain.empty')} + ) : ( void availableGroups: any[] activeSelectedGroup: string | null showScrollTop: boolean @@ -305,6 +306,7 @@ export function ProxyGroupsChain(props: ProxyGroupsChainProps) { const { mode, chainConfigData, + onExitChainMode, availableGroups, activeSelectedGroup, showScrollTop, @@ -521,6 +523,7 @@ export function ProxyGroupsChain(props: ProxyGroupsChainProps) { chainConfigData={chainConfigData} mode={mode} selectedGroup={activeSelectedGroup} + onExitChainMode={onExitChainMode} /> diff --git a/src/components/proxy/proxy-groups.tsx b/src/components/proxy/proxy-groups.tsx index ac86975c5..28e3b3e06 100644 --- a/src/components/proxy/proxy-groups.tsx +++ b/src/components/proxy/proxy-groups.tsx @@ -71,6 +71,7 @@ interface Props { mode: string isChainMode?: boolean chainConfigData?: string | null + onExitChainMode: () => void } function useEmptyRenderList() { @@ -199,8 +200,9 @@ function useProxyRenderState( function ChainProxyGroups(props: { mode: string chainConfigData?: string | null + onExitChainMode: () => void }) { - const { mode, chainConfigData } = props + const { mode, chainConfigData, onExitChainMode } = props const { proxyView } = useProxiesData() const [selectedGroup, setSelectedGroup] = useState(null) @@ -355,6 +357,7 @@ function ChainProxyGroups(props: { { - const { mode, isChainMode = false, chainConfigData } = props + const { mode, isChainMode = false, chainConfigData, onExitChainMode } = props const { profiles, isLoading: isProfilesLoading } = useProfiles() const { isProxyViewPending } = useProxiesData() const { isRunningModePending } = useSystemData() @@ -648,7 +651,11 @@ export const ProxyGroups = (props: Props) => { return case 'render': return isChainMode ? ( - + ) : ( ) diff --git a/src/locales/ar/proxies.json b/src/locales/ar/proxies.json index 55f99cec8..c884d9a0e 100644 --- a/src/locales/ar/proxies.json +++ b/src/locales/ar/proxies.json @@ -70,6 +70,8 @@ "chain": { "header": "Chain Proxy Config", "warning": "Chain proxy will significantly reduce network speed. If you do not have a clear business need, or do not understand this configuration, keep it disabled.", + "confirmEnable": "I understand, enable", + "keepDisabled": "Keep disabled", "empty": "Chain proxy will significantly reduce network speed. If you do not have a clear business need, or do not understand this configuration, keep it disabled.", "instruction": "Click nodes in order to add to proxy chain", "minimumNodes": "Chain proxy requires at least 2 nodes", diff --git a/src/locales/de/proxies.json b/src/locales/de/proxies.json index 3e19338ea..0ae1d2af3 100644 --- a/src/locales/de/proxies.json +++ b/src/locales/de/proxies.json @@ -70,6 +70,8 @@ "chain": { "header": "Proxy-Kette konfigurieren", "warning": "Eine Proxy-Kette verringert die Netzwerkgeschwindigkeit deutlich. Wenn Sie keinen klaren Bedarf haben oder diese Konfiguration nicht verstehen, lassen Sie sie deaktiviert.", + "confirmEnable": "Verstanden, aktivieren", + "keepDisabled": "Deaktiviert lassen", "empty": "Eine Proxy-Kette verringert die Netzwerkgeschwindigkeit deutlich. Wenn Sie keinen klaren Bedarf haben oder diese Konfiguration nicht verstehen, lassen Sie sie deaktiviert.", "instruction": "Klicken Sie die Knoten nacheinander an, um sie zur Proxy-Kette hinzuzufügen", "minimumNodes": "Eine Proxy-Kette braucht mindestens 2 Knoten", diff --git a/src/locales/en/proxies.json b/src/locales/en/proxies.json index ead3f0cbf..83c2a56bc 100644 --- a/src/locales/en/proxies.json +++ b/src/locales/en/proxies.json @@ -70,6 +70,8 @@ "chain": { "header": "Chain Proxy Config", "warning": "Chain proxy will significantly reduce network speed. If you do not have a clear business need, or do not understand this configuration, keep it disabled.", + "confirmEnable": "I understand, enable", + "keepDisabled": "Keep disabled", "empty": "Chain proxy will significantly reduce network speed. If you do not have a clear business need, or do not understand this configuration, keep it disabled.", "instruction": "Click nodes in order to add to proxy chain", "minimumNodes": "Chain proxy requires at least 2 nodes", diff --git a/src/locales/es/proxies.json b/src/locales/es/proxies.json index 537790ba3..46d0b4f5a 100644 --- a/src/locales/es/proxies.json +++ b/src/locales/es/proxies.json @@ -70,6 +70,8 @@ "chain": { "header": "Chain Proxy Config", "warning": "Chain proxy will significantly reduce network speed. If you do not have a clear business need, or do not understand this configuration, keep it disabled.", + "confirmEnable": "I understand, enable", + "keepDisabled": "Keep disabled", "empty": "Chain proxy will significantly reduce network speed. If you do not have a clear business need, or do not understand this configuration, keep it disabled.", "instruction": "Click nodes in order to add to proxy chain", "minimumNodes": "Chain proxy requires at least 2 nodes", diff --git a/src/locales/fa/proxies.json b/src/locales/fa/proxies.json index b430a2475..d055557d7 100644 --- a/src/locales/fa/proxies.json +++ b/src/locales/fa/proxies.json @@ -70,6 +70,8 @@ "chain": { "header": "Chain Proxy Config", "warning": "Chain proxy will significantly reduce network speed. If you do not have a clear business need, or do not understand this configuration, keep it disabled.", + "confirmEnable": "I understand, enable", + "keepDisabled": "Keep disabled", "empty": "Chain proxy will significantly reduce network speed. If you do not have a clear business need, or do not understand this configuration, keep it disabled.", "instruction": "Click nodes in order to add to proxy chain", "minimumNodes": "Chain proxy requires at least 2 nodes", diff --git a/src/locales/id/proxies.json b/src/locales/id/proxies.json index 7bb44c604..83f3c6c23 100644 --- a/src/locales/id/proxies.json +++ b/src/locales/id/proxies.json @@ -70,6 +70,8 @@ "chain": { "header": "Chain Proxy Config", "warning": "Chain proxy will significantly reduce network speed. If you do not have a clear business need, or do not understand this configuration, keep it disabled.", + "confirmEnable": "I understand, enable", + "keepDisabled": "Keep disabled", "empty": "Chain proxy will significantly reduce network speed. If you do not have a clear business need, or do not understand this configuration, keep it disabled.", "instruction": "Click nodes in order to add to proxy chain", "minimumNodes": "Chain proxy requires at least 2 nodes", diff --git a/src/locales/jp/proxies.json b/src/locales/jp/proxies.json index 950e65646..3dcb125dd 100644 --- a/src/locales/jp/proxies.json +++ b/src/locales/jp/proxies.json @@ -70,6 +70,8 @@ "chain": { "header": "Chain Proxy Config", "warning": "Chain proxy will significantly reduce network speed. If you do not have a clear business need, or do not understand this configuration, keep it disabled.", + "confirmEnable": "I understand, enable", + "keepDisabled": "Keep disabled", "empty": "Chain proxy will significantly reduce network speed. If you do not have a clear business need, or do not understand this configuration, keep it disabled.", "instruction": "Click nodes in order to add to proxy chain", "minimumNodes": "Chain proxy requires at least 2 nodes", diff --git a/src/locales/ko/proxies.json b/src/locales/ko/proxies.json index 64e7b6a9c..1ec805f00 100644 --- a/src/locales/ko/proxies.json +++ b/src/locales/ko/proxies.json @@ -70,6 +70,8 @@ "chain": { "header": "체인 프록시 구성", "warning": "체인 프록시는 네트워크 속도를 크게 저하시킬 수 있습니다. 명확한 업무상 필요가 없거나 이 구성을 이해하지 못한다면 비활성화 상태로 두세요.", + "confirmEnable": "이해했습니다, 활성화", + "keepDisabled": "비활성화 유지", "empty": "체인 프록시는 네트워크 속도를 크게 저하시킬 수 있습니다. 명확한 업무상 필요가 없거나 이 구성을 이해하지 못한다면 비활성화 상태로 두세요.", "instruction": "프록시 체인에 추가하려면 순서대로 노드를 클릭하세요", "minimumNodes": "체인 프록시는 최소 2개의 노드가 필요합니다", diff --git a/src/locales/pt/proxies.json b/src/locales/pt/proxies.json index 1740f6043..2f32fcdc9 100644 --- a/src/locales/pt/proxies.json +++ b/src/locales/pt/proxies.json @@ -70,6 +70,8 @@ "chain": { "header": "Configuração do proxy em cadeia", "warning": "O proxy em cadeia reduz significativamente a velocidade da rede. Se você não tem uma necessidade clara ou não entende esta configuração, mantenha-o desativado.", + "confirmEnable": "Entendi, ativar", + "keepDisabled": "Manter desativado", "empty": "O proxy em cadeia reduz significativamente a velocidade da rede. Se você não tem uma necessidade clara ou não entende esta configuração, mantenha-o desativado.", "instruction": "Clique nos nós em ordem para adicioná-los à cadeia de proxy", "minimumNodes": "O proxy em cadeia requer pelo menos 2 nós", diff --git a/src/locales/ru/proxies.json b/src/locales/ru/proxies.json index 603abacc1..9ac3af1df 100644 --- a/src/locales/ru/proxies.json +++ b/src/locales/ru/proxies.json @@ -70,6 +70,8 @@ "chain": { "header": "Цепочка прокси", "warning": "Цепочка прокси может значительно снизить скорость сети. Если у вас нет явной рабочей необходимости или вы не понимаете эту настройку, оставьте ее отключенной.", + "confirmEnable": "Понятно, включить", + "keepDisabled": "Оставить выключенным", "empty": "Цепочка прокси может значительно снизить скорость сети. Если у вас нет явной рабочей необходимости или вы не понимаете эту настройку, оставьте ее отключенной.", "instruction": "Нажимайте на узлы по порядку, чтобы добавить их в цепочку", "minimumNodes": "Для цепочки требуется минимум 2 узла", diff --git a/src/locales/tr/proxies.json b/src/locales/tr/proxies.json index 6c4a84122..5fa5f8a4b 100644 --- a/src/locales/tr/proxies.json +++ b/src/locales/tr/proxies.json @@ -70,6 +70,8 @@ "chain": { "header": "Zincir Vekil Yapılandırması", "warning": "Zincir vekil ağ hızını belirgin biçimde düşürür. Açık bir ihtiyacınız yoksa ya da bu yapılandırmayı bilmiyorsanız devre dışı bırakın.", + "confirmEnable": "Anladım, etkinleştir", + "keepDisabled": "Devre dışı kalsın", "empty": "Zincir vekil ağ hızını belirgin biçimde düşürür. Açık bir ihtiyacınız yoksa ya da bu yapılandırmayı bilmiyorsanız devre dışı bırakın.", "instruction": "Vekil zincirine eklemek için düğümlere sırayla tıklayın", "minimumNodes": "Zincir vekil en az 2 düğüm gerektirir", diff --git a/src/locales/tt/proxies.json b/src/locales/tt/proxies.json index 59fcd096b..6222875fe 100644 --- a/src/locales/tt/proxies.json +++ b/src/locales/tt/proxies.json @@ -70,6 +70,8 @@ "chain": { "header": "Chain Proxy Config", "warning": "Chain proxy will significantly reduce network speed. If you do not have a clear business need, or do not understand this configuration, keep it disabled.", + "confirmEnable": "I understand, enable", + "keepDisabled": "Keep disabled", "empty": "Chain proxy will significantly reduce network speed. If you do not have a clear business need, or do not understand this configuration, keep it disabled.", "instruction": "Click nodes in order to add to proxy chain", "minimumNodes": "Chain proxy requires at least 2 nodes", diff --git a/src/locales/zh/proxies.json b/src/locales/zh/proxies.json index cc792f5e7..3cecd8eb7 100644 --- a/src/locales/zh/proxies.json +++ b/src/locales/zh/proxies.json @@ -70,6 +70,8 @@ "chain": { "header": "代理链配置", "warning": "链式代理会显著降低网速。如果您没有明确的业务需求,或不了解此项配置,请保持关闭", + "confirmEnable": "我明白,开启", + "keepDisabled": "保持关闭", "empty": "链式代理会显著降低网速。如果您没有明确的业务需求,或不了解此项配置,请保持关闭", "instruction": "顺序点击节点添加到代理链中", "minimumNodes": "链式代理至少需要 2 个节点", diff --git a/src/locales/zhtw/proxies.json b/src/locales/zhtw/proxies.json index 48150df00..890a8ac4b 100644 --- a/src/locales/zhtw/proxies.json +++ b/src/locales/zhtw/proxies.json @@ -70,6 +70,8 @@ "chain": { "header": "鏈式代理設定", "warning": "鏈式代理會顯著降低網速。如果您沒有明確的業務需求,或不了解此項設定,請保持關閉", + "confirmEnable": "我明白,開啟", + "keepDisabled": "保持關閉", "empty": "鏈式代理會顯著降低網速。如果您沒有明確的業務需求,或不了解此項設定,請保持關閉", "instruction": "依序點擊節點新增到鏈式代理中", "minimumNodes": "鏈式代理至少需要 2 個節點", diff --git a/src/pages/proxies.tsx b/src/pages/proxies.tsx index cbf1d9ce3..14b56f25f 100644 --- a/src/pages/proxies.tsx +++ b/src/pages/proxies.tsx @@ -1,10 +1,10 @@ import { LanOutlined, LanRounded, WarningRounded } from '@mui/icons-material' -import { Box, Button, ButtonGroup } from '@mui/material' +import { Box, Button, ButtonGroup, Typography } from '@mui/material' import { useLockFn } from 'ahooks' import { useCallback, useEffect, useReducer, useState } from 'react' import { useTranslation } from 'react-i18next' -import { BasePage, TooltipIcon } from '@/components/base' +import { BaseDialog, BasePage, TooltipIcon } from '@/components/base' import { ProviderButton } from '@/components/proxy/provider-button' import { ProxyGroups } from '@/components/proxy/proxy-groups' import { @@ -38,6 +38,7 @@ const ProxyPage = () => { return false } }) + const [chainConfirmOpen, setChainConfirmOpen] = useState(false) const [chainConfigData, dispatchChainConfigData] = useReducer( (_: string | null, action: string | null) => action, @@ -68,32 +69,34 @@ const ProxyPage = () => { } }) - const onToggleChainMode = useLockFn(async () => { - const newChainMode = !isChainMode + const applyChainMode = (enabled: boolean) => { + setIsChainMode(enabled) + localStorage.setItem('proxy-chain-mode-enabled', enabled.toString()) + } - if (!newChainMode) { - // 退出链式代理模式时,清除链式代理配置 - try { - debugLog('Exiting chain mode, clearing chain configuration') - const result = await mutate( - () => updateProxyChainConfigInRuntime(null), - { - id: 'update-proxy-chain-runtime', - errorNotice: false, - }, - ) - if (!result.ok) return - debugLog('Chain configuration cleared successfully') - } catch (error) { - console.error('Failed to clear chain configuration:', error) - showNotice.error(error) - return - } + const onExitChainMode = useLockFn(async () => { + // 退出链式代理模式时,清除链式代理配置 + try { + debugLog('Exiting chain mode, clearing chain configuration') + const result = await mutate(() => updateProxyChainConfigInRuntime(null), { + id: 'update-proxy-chain-runtime', + errorNotice: false, + }) + if (!result.ok) return + debugLog('Chain configuration cleared successfully') + } catch (error) { + console.error('Failed to clear chain configuration:', error) + showNotice.error(error) + return } - setIsChainMode(newChainMode) - localStorage.setItem('proxy-chain-mode-enabled', newChainMode.toString()) + applyChainMode(false) }) + const onToggleChainMode = () => { + if (isChainMode) onExitChainMode().catch(() => {}) + else setChainConfirmOpen(true) + } + // 当开启链式代理模式时,获取配置数据 useEffect(() => { if (!isChainMode) { @@ -202,7 +205,23 @@ const ProxyPage = () => { mode={curMode ?? 'rule'} isChainMode={isChainMode} chainConfigData={chainConfigData} + onExitChainMode={onExitChainMode} /> + setChainConfirmOpen(false)} + onClose={() => setChainConfirmOpen(false)} + onOk={() => { + setChainConfirmOpen(false) + applyChainMode(true) + }} + > + {chainWarning} + ) } diff --git a/src/types/generated/i18n-keys.ts b/src/types/generated/i18n-keys.ts index 4e566dce4..07be729be 100644 --- a/src/types/generated/i18n-keys.ts +++ b/src/types/generated/i18n-keys.ts @@ -322,6 +322,8 @@ export const translationKeys = [ 'proxies.page.empty.actions.openLogs', 'proxies.page.chain.header', 'proxies.page.chain.warning', + 'proxies.page.chain.confirmEnable', + 'proxies.page.chain.keepDisabled', 'proxies.page.chain.empty', 'proxies.page.chain.instruction', 'proxies.page.chain.minimumNodes', diff --git a/src/types/generated/i18n-resources.ts b/src/types/generated/i18n-resources.ts index 87aba3645..b2f2a64bf 100644 --- a/src/types/generated/i18n-resources.ts +++ b/src/types/generated/i18n-resources.ts @@ -525,6 +525,7 @@ export interface TranslationResources { toggleChain: string } chain: { + confirmEnable: string connectFailed: string disconnectFailed: string duplicateNode: string @@ -533,6 +534,7 @@ export interface TranslationResources { exitNode: string header: string instruction: string + keepDisabled: string minimumNodes: string minimumNodesHint: string warning: string