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

View File

@ -25,6 +25,7 @@ export const [quickFilterRegex, setQuickFilterRegex] = makePersisted(
export const [allConnections, setAllConnections] = createSignal<Connection[]>( export const [allConnections, setAllConnections] = createSignal<Connection[]>(
[], [],
) )
export const [latestConnectionMsg, setLatestConnectionMsg] = export const [latestConnectionMsg, setLatestConnectionMsg] =
createSignal<WsMsg>(null) 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 { return {
closedConnections, closedConnections,
activeConnections, activeConnections,
speedGroupByName,
paused, paused,
setPaused, setPaused,
} }