Feature: add meanDelay display

This commit is contained in:
Dreamacro 2023-02-28 13:20:50 +08:00
parent 0f141b679c
commit 20978b12b0
5 changed files with 10 additions and 115 deletions

View File

@ -49,10 +49,11 @@ export function Proxy (props: ProxyProps) {
})
}, [config.name, getDelay, set])
const delay = useMemo(
() => config.history?.length ? config.history.slice(-1)[0].delay : 0,
[config],
)
const delay = config.history?.length ? config.history.slice(-1)[0].delay : 0
const meanDelay = config.history?.length ? config.history.slice(-1)[0].meanDelay : undefined
const delayText = delay === 0 ? '-' : `${delay}ms`
const meanDelayText = meanDelay === undefined || meanDelay === 0 ? '' : `(${meanDelay}ms)`
useLayoutEffect(() => {
const handler = () => { speedTest() }
@ -63,9 +64,9 @@ export function Proxy (props: ProxyProps) {
const hasError = useMemo(() => delay === 0, [delay])
const color = useMemo(
() => Object.keys(TagColors).find(
threshold => delay <= TagColors[threshold as keyof typeof TagColors],
threshold => (meanDelay ?? delay) <= TagColors[threshold as keyof typeof TagColors],
),
[delay],
[delay, meanDelay],
)
const backgroundColor = hasError ? '#E5E7EB' : color
@ -80,7 +81,7 @@ export function Proxy (props: ProxyProps) {
<p className="proxy-name">{config.name}</p>
</div>
<div className="flex flex-col h-full items-center justify-center md:flex-row md:h-[18px] md:justify-between md:space-y-0 space-y-3 text-[10px]">
<p>{delay === 0 ? '-' : `${delay}ms`}</p>
<p >{delayText}{meanDelayText}</p>
{ config.udp && <p className="bg-gray-200 p-[3px] rounded text-gray-600">UDP</p> }
</div>
</div>

View File

@ -102,7 +102,7 @@ export default function Settings () {
)
const controllers = isClashX
? <span>{`${externalControllerHost}:${externalControllerPort}`}</span>
? <span className="text-primary-darken text-sm">{`${externalControllerHost}:${externalControllerPort}`}</span>
: (
<>
<Select

View File

@ -52,6 +52,7 @@ export interface ProxyProviders {
interface History {
time: string
delay: number
meanDelay?: number
}
export interface Proxy {

View File

@ -1,106 +0,0 @@
/**
* proxy config interface
*/
export const ProxyType = {
Shadowsocks: 'ss',
Vmess: 'vmess',
Socks5: 'socks5',
}
export type Proxy = ShadowsocksProxy & VmessProxy & Socks5Proxy
export const SsProxyConfigList = [
'name', 'type', 'server', 'port', 'cipher', 'password', 'obfs', 'obfs-host',
]
export interface ShadowsocksProxy {
name?: string
type?: 'ss'
server?: string
port?: number
cipher?: string
password?: string
obfs?: string
'obfs-host'?: string
}
export const VmessProxyConfigList = [
'name', 'type', 'server', 'port', 'uuid', 'alterid', 'cipher', 'tls',
]
export interface VmessProxy {
name?: string
type?: 'vmess'
server?: string
port?: number
uuid?: string
alterId?: number
cipher?: string
tls?: boolean
}
export const Socks5ProxyConfigList = ['name', 'type', 'server', 'port']
export interface Socks5Proxy {
name?: string
type?: 'socks5'
server?: string
port?: number
}
export type ProxyGroup = SelectProxyGroup & UrlTestProxyGroup & FallbackProxyGroup & LoadBalanceGroup
export interface SelectProxyGroup {
name?: string
type?: 'select'
proxies?: string[] // proxy names
}
export interface LoadBalanceGroup {
name?: string
type?: 'load-balance'
proxies?: string[] // proxy names
}
export interface FallbackProxyGroup {
name?: string
type?: 'fallback'
proxies?: string[] // proxy names
url?: string
interval?: number // second
}
export interface UrlTestProxyGroup {
name?: string
type?: 'url-test'
proxies?: string[] // proxy names
url?: string
interval?: number // second
}

View File

@ -1,5 +1,4 @@
export * from './BaseProps'
export * from './Config'
export * from './Proxy'
export * from './Rule'
export * from './Cipher'