Skip to content

Commit

Permalink
fix(proxies): group type does not show UDP
Browse files Browse the repository at this point in the history
  • Loading branch information
riolurs committed Sep 4, 2023
1 parent 9973c20 commit f0fbe09
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/components/ProxyNodeCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createMemo } from 'solid-js'
import { twMerge } from 'tailwind-merge'
import { Latency } from '~/components'
import { formatProxyType } from '~/helpers'
import { filterGroupType, formatProxyType } from '~/helpers'
import { useProxies } from '~/signals'

export const ProxyNodeCard = (props: {
Expand Down Expand Up @@ -32,7 +32,15 @@ export const ProxyNodeCard = (props: {
)}
>
{formatProxyType(proxyNode()?.type)}
{proxyNode()?.udp && ' :: udp'}
{filterGroupType(proxyNode()?.type) ? (
<span>
{' :: '}
{proxyNode()?.xudp && 'x'}
{proxyNode()?.udp && 'udp'}
</span>
) : (
<span>{proxyNode()?.now}</span>
)}
</div>
<div class="text-xs">
<Latency name={props.proxyName} />
Expand Down
17 changes: 16 additions & 1 deletion src/helpers/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,27 @@ export const formatProxyType = (type = '') => {
const t = type.toLowerCase()

if (t.includes('shadowsocks')) {
return t.replace('shadowsocks', 'ss')
return 'ss'
}

return t
}

export const filterGroupType = (type = '') => {
const t = type.toLowerCase()
const conditions = [
'selector',
'direct',
'reject',
'urltest',
'loadbalance',
'fallback',
'relay',
]

return !conditions.includes(t)
}

export const sortProxiesByOrderingType = (
proxyNames: string[],
proxyLatencyMap: Record<string, number>,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Proxies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default () => {
</Button>
</div>
<div class="text-sm text-slate-500">
{proxy.type} :: {proxy.now}
{proxy.type} {proxy.now?.length > 0 && ` :: ${proxy.now}`}
</div>
<Show when={!collapsedMap()[`group-${proxy.name}`]}>
<ProxyNodePreview
Expand Down
4 changes: 4 additions & 0 deletions src/signals/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type { Proxy, ProxyNode, ProxyProvider } from '~/types'
type ProxyInfo = {
name: string
udp: boolean
now: string
xudp: boolean
type: string
}
// these signals should be global state
Expand All @@ -25,7 +27,9 @@ const setProxiesInfo = (proxies: (Proxy | ProxyNode)[]) => {

newProxyNodeMap[proxy.name] = {
udp: proxy.udp,
xudp: proxy.xudp,
type: proxy.type,
now: proxy.now,
name: proxy.name,
}
newLatencyMap[proxy.name] = latency
Expand Down
1 change: 1 addition & 0 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type ProxyNode = {
tfo: boolean
udp: boolean
xudp: boolean
now: string
id: string
extra: Record<string, unknown>
history: {
Expand Down

0 comments on commit f0fbe09

Please sign in to comment.