From 51a88b506c1c4a5c41ff9a5c0e12a630f82a79fe Mon Sep 17 00:00:00 2001 From: YetAnotherZephyruso <176294927+YetAnotherZephyruso@users.noreply.github.com> Date: Tue, 20 Aug 2024 09:42:52 +0800 Subject: [PATCH] feat: preview dlspeed in proxies page (#924) --- src/pages/Proxies.tsx | 10 +++++++++- src/signals/connections.ts | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/pages/Proxies.tsx b/src/pages/Proxies.tsx index f1be622..6a19063 100644 --- a/src/pages/Proxies.tsx +++ b/src/pages/Proxies.tsx @@ -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>({}), { @@ -210,7 +214,11 @@ export default () => {
{proxyGroup.type}{' '} - {proxyGroup.now?.length > 0 && ` :: ${proxyGroup.now}`} + {proxyGroup.now?.length > 0 && ` :: ${proxyGroup.now}`}{' '} + {byteSize( + speedGroupByName()[proxyGroup.name] ?? 0, + ).toString()} + /s
diff --git a/src/signals/connections.ts b/src/signals/connections.ts index cdc7baf..e5fc496 100644 --- a/src/signals/connections.ts +++ b/src/signals/connections.ts @@ -25,6 +25,7 @@ export const [quickFilterRegex, setQuickFilterRegex] = makePersisted( export const [allConnections, setAllConnections] = createSignal( [], ) + export const [latestConnectionMsg, setLatestConnectionMsg] = createSignal(null) @@ -69,9 +70,26 @@ export const useConnections = () => { }) }) + const speedGroupByName = createMemo(() => { + const returnMap: Record = {} + + 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, }