feat: preview dlspeed in proxies page (#924)

This commit is contained in:
YetAnotherZephyruso 2024-08-20 09:42:52 +08:00 committed by GitHub
parent 8a778f5374
commit 51a88b506c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import {
IconReload,
IconSettings,
} from '@tabler/icons-solidjs'
import byteSize from 'byte-size'
import { twMerge } from 'tailwind-merge'
import {
Button,
@ -24,6 +25,7 @@ import {
hideUnAvailableProxies,
proxiesOrderingType,
renderProxiesInTwoColumns,
useConnections,
useProxies,
} from '~/signals'
@ -60,6 +62,8 @@ export default () => {
updatingMap,
} = useProxies()
const { speedGroupByName } = useConnections()
const [collapsedMap, setCollapsedMap] = makePersisted(
createSignal<Record<string, boolean>>({}),
{
@ -210,7 +214,11 @@ export default () => {
<div class="text-sm text-slate-500">
{proxyGroup.type}{' '}
{proxyGroup.now?.length > 0 && ` :: ${proxyGroup.now}`}
{proxyGroup.now?.length > 0 && ` :: ${proxyGroup.now}`}{' '}
{byteSize(
speedGroupByName()[proxyGroup.name] ?? 0,
).toString()}
/s
</div>
<Show when={!collapsedMap()[proxyGroup.name]}>

View File

@ -25,6 +25,7 @@ export const [quickFilterRegex, setQuickFilterRegex] = makePersisted(
export const [allConnections, setAllConnections] = createSignal<Connection[]>(
[],
)
export const [latestConnectionMsg, setLatestConnectionMsg] =
createSignal<WsMsg>(null)
@ -69,9 +70,26 @@ export const useConnections = () => {
})
})
const speedGroupByName = createMemo(() => {
const returnMap: Record<string, number> = {}
activeConnections().forEach((c) => {
c.chains.forEach((chain) => {
if (!returnMap[chain]) {
returnMap[chain] = 0
}
returnMap[chain] += c.downloadSpeed
})
})
return returnMap
})
return {
closedConnections,
activeConnections,
speedGroupByName,
paused,
setPaused,
}