mirror of
https://github.com/MetaCubeX/metacubexd.git
synced 2024-11-23 21:35:36 +08:00
refactor: use ws request conns
This commit is contained in:
parent
6957cb4ddf
commit
f2ef7790dd
@ -4,12 +4,16 @@ import { twMerge } from 'tailwind-merge'
|
||||
import { Header } from '~/components'
|
||||
import { ROUTES } from '~/constants'
|
||||
import {
|
||||
WsMsg,
|
||||
curTheme,
|
||||
endpoint,
|
||||
selectedEndpoint,
|
||||
setAllConnections,
|
||||
setLatestConnectionMsg,
|
||||
useAutoSwitchTheme,
|
||||
useProxies,
|
||||
useTwemoji,
|
||||
useWsRequest,
|
||||
} from '~/signals'
|
||||
|
||||
const Setup = lazy(() => import('~/pages/Setup'))
|
||||
@ -28,6 +32,8 @@ export const App = () => {
|
||||
createEffect(() => {
|
||||
if (selectedEndpoint() && endpoint()) {
|
||||
void useProxies().updateProxies()
|
||||
setAllConnections([])
|
||||
setLatestConnectionMsg(useWsRequest<WsMsg>('connections'))
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -1,9 +1,8 @@
|
||||
import { differenceWith, isNumber, unionWith } from 'lodash'
|
||||
import { Accessor, createEffect, createSignal, untrack } from 'solid-js'
|
||||
import { Connection, ConnectionRawMessage } from '~/types'
|
||||
import { selectedEndpoint, useWsRequest } from './request'
|
||||
|
||||
type WsMsg = {
|
||||
export type WsMsg = {
|
||||
connections: ConnectionRawMessage[]
|
||||
uploadTotal: number
|
||||
downloadTotal: number
|
||||
@ -13,7 +12,8 @@ type WsMsg = {
|
||||
// when user selects proxy and close some connections they can back and check connections
|
||||
// they closed
|
||||
let allConnections: Connection[] = []
|
||||
const setAllConnections = (allConns: Connection[]) => {
|
||||
|
||||
export const setAllConnections = (allConns: Connection[]) => {
|
||||
allConnections = allConns
|
||||
}
|
||||
|
||||
@ -23,12 +23,9 @@ export let latestConnectionMsg: Accessor<WsMsg> = () => ({
|
||||
connections: [],
|
||||
})
|
||||
|
||||
createEffect(() => {
|
||||
if (selectedEndpoint()) {
|
||||
setAllConnections([])
|
||||
latestConnectionMsg = useWsRequest<WsMsg>('connections')
|
||||
}
|
||||
})
|
||||
export const setLatestConnectionMsg = (accessor: Accessor<WsMsg>) => {
|
||||
latestConnectionMsg = accessor
|
||||
}
|
||||
|
||||
export const useConnections = () => {
|
||||
const [closedConnections, setClosedConnections] = createSignal<Connection[]>(
|
||||
|
Loading…
Reference in New Issue
Block a user