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