mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-05 05:50:04 +08:00
perf(core): batch close connections on mode change
This commit is contained in:
@@ -7,10 +7,9 @@ import { Box, Paper, Stack, Typography } from '@mui/material'
|
||||
import { useLockFn } from 'ahooks'
|
||||
import { type ReactNode, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { type BaseConfig, closeAllConnections } from 'tauri-plugin-mihomo-api'
|
||||
import type { BaseConfig } from 'tauri-plugin-mihomo-api'
|
||||
|
||||
import { useClashMode, useRuntimeConfig } from '@/hooks/use-clash'
|
||||
import { useVerge } from '@/hooks/use-verge'
|
||||
import {
|
||||
useAppRefreshers,
|
||||
useClashConfigData,
|
||||
@@ -58,7 +57,6 @@ const MODE_ICONS: Record<ClashMode, ReactNode> = {
|
||||
|
||||
export const ClashModeCard = () => {
|
||||
const { t } = useTranslation()
|
||||
const { verge } = useVerge()
|
||||
const { clashConfig } = useClashConfigData()
|
||||
const { isCoreDataPending } = useCoreDataStatus()
|
||||
const { refreshClashConfig } = useAppRefreshers()
|
||||
@@ -89,9 +87,6 @@ export const ClashModeCard = () => {
|
||||
|
||||
const onChangeMode = useLockFn(async (mode: ClashMode) => {
|
||||
if (mode === currentMode) return
|
||||
if (verge?.auto_close_connection) {
|
||||
closeAllConnections()
|
||||
}
|
||||
|
||||
setOptimisticMode(mode)
|
||||
try {
|
||||
|
||||
@@ -3,12 +3,10 @@ import { Box, Button, ButtonGroup } from '@mui/material'
|
||||
import { useLockFn } from 'ahooks'
|
||||
import { useCallback, useEffect, useReducer, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { closeAllConnections } from 'tauri-plugin-mihomo-api'
|
||||
|
||||
import { BasePage, TooltipIcon } from '@/components/base'
|
||||
import { ProviderButton } from '@/components/proxy/provider-button'
|
||||
import { ProxyGroups } from '@/components/proxy/proxy-groups'
|
||||
import { useVerge } from '@/hooks/use-verge'
|
||||
import {
|
||||
useAppRefreshers,
|
||||
useClashConfigData,
|
||||
@@ -51,17 +49,12 @@ const ProxyPage = () => {
|
||||
const updateChainConfigData = useCallback((value: string | null) => {
|
||||
dispatchChainConfigData(value)
|
||||
}, [])
|
||||
const { verge } = useVerge()
|
||||
|
||||
const normalizedMode = clashConfig?.mode?.toLowerCase()
|
||||
const curMode = isMode(normalizedMode) ? normalizedMode : undefined
|
||||
const chainWarning = t('proxies.page.chain.warning')
|
||||
|
||||
const onChangeMode = useLockFn(async (mode: Mode) => {
|
||||
// 断开连接
|
||||
if (mode !== curMode && verge?.auto_close_connection) {
|
||||
closeAllConnections()
|
||||
}
|
||||
try {
|
||||
// patchClashMode 在后端 PATCH 失败时会 reject,需提示用户而非静默失败
|
||||
await patchClashMode(mode)
|
||||
|
||||
Reference in New Issue
Block a user