Skip to content

Commit 3d0f752

Browse files
author
pompurin404
committed
use proxy-group url
1 parent 08c00ae commit 3d0f752

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/renderer/src/pages/proxies.tsx

+18-15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Avatar, Button, Card, CardBody, Chip } from '@nextui-org/react'
22
import BasePage from '@renderer/components/base/base-page'
33
import { useAppConfig } from '@renderer/hooks/use-app-config'
44
import {
5+
getRuntimeConfig,
56
mihomoChangeProxy,
67
mihomoGroupDelay,
78
mihomoProxies,
@@ -21,29 +22,31 @@ import { MdOutlineSpeed } from 'react-icons/md'
2122

2223
const Proxies: React.FC = () => {
2324
const { data: proxies, mutate } = useSWR('mihomoProxies', mihomoProxies)
25+
const { data: runtime } = useSWR('getRuntimeConfig', getRuntimeConfig)
2426
const { appConfig, patchAppConfig } = useAppConfig()
2527
const { proxyDisplayMode = 'simple', proxyDisplayOrder = 'default' } = appConfig || {}
28+
2629
const groups = useMemo(() => {
2730
const groups: IMihomoGroup[] = []
28-
if (proxies && proxies.proxies && proxies.proxies['GLOBAL']) {
29-
const globalGroup = proxies.proxies['GLOBAL'] as IMihomoGroup
30-
for (const global of globalGroup.all) {
31-
if (isGroup(proxies.proxies[global])) {
32-
if (proxies.proxies[global].hidden) continue
33-
groups.push(proxies.proxies[global] as IMihomoGroup)
34-
}
35-
}
36-
Object.keys(proxies.proxies).forEach((key) => {
37-
if (isGroup(proxies.proxies[key])) {
38-
if (!groups.find((group) => group.name === key)) {
39-
if (proxies.proxies[key].hidden) return
40-
groups.push(proxies.proxies[key] as IMihomoGroup)
41-
}
31+
if (proxies && proxies.proxies) {
32+
runtime?.['proxy-groups']?.forEach((group: { name: string; url?: string }) => {
33+
const { name, url } = group
34+
if (
35+
proxies.proxies[name] &&
36+
isGroup(proxies.proxies[name]) &&
37+
!proxies.proxies[name].hidden
38+
) {
39+
const newGroup = proxies.proxies[name]
40+
newGroup.testUrl = url
41+
groups.push(newGroup as IMihomoGroup)
4242
}
4343
})
44+
if (!groups.find((group) => group.name === 'GLOBAL')) {
45+
groups.push(proxies.proxies['GLOBAL'] as IMihomoGroup)
46+
}
4447
}
4548
return groups
46-
}, [proxies])
49+
}, [proxies, runtime])
4750

4851
const [isOpen, setIsOpen] = useState(Array(groups.length).fill(false))
4952
const virtuosoRef = useRef<GroupedVirtuosoHandle>(null)

0 commit comments

Comments
 (0)