diff --git a/src/main/utils/template.ts b/src/main/utils/template.ts index cc21ce2..786bd48 100644 --- a/src/main/utils/template.ts +++ b/src/main/utils/template.ts @@ -2,6 +2,7 @@ export const defaultConfig: IAppConfig = { core: 'mihomo', silentStart: false, proxyDisplayMode: 'simple', + proxyDisplayOrder: 'default', sysProxy: { enable: false, mode: 'manual' } } diff --git a/src/renderer/src/components/proxies/proxy-item.tsx b/src/renderer/src/components/proxies/proxy-item.tsx index 2ad3858..5975f8e 100644 --- a/src/renderer/src/components/proxies/proxy-item.tsx +++ b/src/renderer/src/components/proxies/proxy-item.tsx @@ -1,5 +1,5 @@ import { Button, Card, CardBody } from '@nextui-org/react' -import React, { useEffect, useState } from 'react' +import React, { useEffect, useMemo, useState } from 'react' import PubSub from 'pubsub-js' interface Props { @@ -14,12 +14,14 @@ interface Props { const ProxyItem: React.FC = (props) => { const { mutateProxies, proxyDisplayMode, group, proxy, selected, onSelect, onProxyDelay } = props - const [delay, setDelay] = useState(() => { + + const delay = useMemo(() => { if (proxy.history.length > 0) { return proxy.history[proxy.history.length - 1].delay } return -1 - }) + }, [proxy]) + const [loading, setLoading] = useState(false) function delayColor(delay: number): 'primary' | 'success' | 'warning' | 'danger' { @@ -37,19 +39,11 @@ const ProxyItem: React.FC = (props) => { const onDelay = (): void => { setLoading(true) - onProxyDelay(proxy.name, group.testUrl).then( - (delay) => { - setDelay(delay.delay || 0) - mutateProxies() - setLoading(false) - }, - () => { - setDelay(0) - setLoading(false) - } - ) + onProxyDelay(proxy.name, group.testUrl).finally(() => { + mutateProxies() + setLoading(false) + }) } - console.log(delay) useEffect(() => { const token = PubSub.subscribe(`${group.name}-delay`, onDelay) @@ -58,6 +52,7 @@ const ProxyItem: React.FC = (props) => { PubSub.unsubscribe(token) } }, []) + return ( onSelect(group.name, proxy.name)} @@ -66,12 +61,16 @@ const ProxyItem: React.FC = (props) => { className={`${selected ? 'bg-primary/30' : ''}`} radius="sm" > - +
-
{proxy.name}
+
+ {proxy.name} +
{proxyDisplayMode === 'full' && ( -
{proxy.type}
+
+ {proxy.type} +
)}
+
+ + +
} > { @@ -112,7 +157,7 @@ const Proxies: React.FC = () => { src={groups[index].icon} /> ) : null} -
+
{groups[index].name} {proxyDisplayMode === 'full' && ( <> @@ -128,6 +173,29 @@ const Proxies: React.FC = () => {
+