refactor: activate selected proxies (#7285)

* feat(profiles): add automatic node activation after profile switch

* refactor(use-profiles): simplify patchCurrent logic by always mutating profiles

* refactor(use-profiles): remove unused activateSelected function and related imports

* refactor: rename worker handle to activate selected task

* fix: clippy

* refactor(config): replace log statements with structured logging

* refactor(config): fix incorrect retry logic in profile activation

* feat(profiles): update proxy cache when switching profiles

* docs: update changelog with bug fixes and logic improvements

* refactor(profiles): remove unused imports and redundant cache update
This commit is contained in:
oomeow
2026-07-01 12:47:03 +00:00
committed by GitHub
parent af0518d578
commit c2ddb5c111
5 changed files with 115 additions and 182 deletions
+8 -25
View File
@@ -1,7 +1,7 @@
import {
closestCenter,
DndContext,
DragEndEvent,
type DragEndEvent,
DragOverlay,
KeyboardSensor,
PointerSensor,
@@ -36,23 +36,23 @@ import {
} from 'react'
import { useTranslation } from 'react-i18next'
import { useLocation } from 'react-router'
import {
closeAllConnections,
selectNodeForGroup,
} from 'tauri-plugin-mihomo-api'
import { closeAllConnections } from 'tauri-plugin-mihomo-api'
import { BasePage, BaseStyledTextField, DialogRef } from '@/components/base'
import {
BasePage,
BaseStyledTextField,
type DialogRef,
} from '@/components/base'
import { ProfileItem } from '@/components/profile/profile-item'
import { ProfileMore } from '@/components/profile/profile-more'
import {
ProfileViewer,
ProfileViewerRef,
type ProfileViewerRef,
} from '@/components/profile/profile-viewer'
import { ConfigViewer } from '@/components/setting/mods/config-viewer'
import { useListen } from '@/hooks/use-listen'
import { useProfiles } from '@/hooks/use-profiles'
import {
calcuProxies,
createProfile,
deleteProfile,
enhanceProfiles,
@@ -67,7 +67,6 @@ import { showNotice } from '@/services/notice-service'
import {
fetchCacheData,
revalidateQueries,
setCacheData,
useQuery,
} from '@/services/query-client'
import {
@@ -466,22 +465,6 @@ const ProfilePage = () => {
return
}
// 选择所记忆的节点
const current = profiles.items?.find((e) => e.uid === profile)
for (const item of current?.selected ?? []) {
if (item.name && item.now) {
try {
await selectNodeForGroup(item.name, item.now)
} catch (err) {
debugLog(
`[Profile] 选择节点失败: ${item.name} -> ${item.now}`,
err,
)
}
}
}
setCacheData(['getProxies'], await calcuProxies())
// 完成切换
await mutateLogs()
closeAllConnections()