Skip to content

Commit

Permalink
feat: preview dlspeed in proxies page
Browse files Browse the repository at this point in the history
  • Loading branch information
Zephyruso committed Aug 19, 2024
1 parent 8a778f5 commit 118b34a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/pages/Proxies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
IconReload,
IconSettings,
} from '@tabler/icons-solidjs'
import byteSize from 'byte-size'
import { twMerge } from 'tailwind-merge'
import {
Button,
Expand All @@ -24,6 +25,7 @@ import {
hideUnAvailableProxies,
proxiesOrderingType,
renderProxiesInTwoColumns,
useConnections,
useProxies,
} from '~/signals'

Expand Down Expand Up @@ -60,6 +62,8 @@ export default () => {
updatingMap,
} = useProxies()

const { speedGroupByName } = useConnections()

const [collapsedMap, setCollapsedMap] = makePersisted(
createSignal<Record<string, boolean>>({}),
{
Expand Down Expand Up @@ -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]}>
Expand Down
18 changes: 18 additions & 0 deletions src/signals/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const [quickFilterRegex, setQuickFilterRegex] = makePersisted(
export const [allConnections, setAllConnections] = createSignal<Connection[]>(
[],
)

export const [latestConnectionMsg, setLatestConnectionMsg] =
createSignal<WsMsg>(null)

Expand Down Expand Up @@ -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,
}
Expand Down

0 comments on commit 118b34a

Please sign in to comment.