mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-19 02:12:10 +08:00
WebSocket hooks (use-connection-data, use-log-data) - Single-pass merge for connection snapshots; reuse previous row reference when upload/download are unchanged so downstream memos can bail out - Single-allocation cap on closedConnections (no double concat+slice) - Single-allocation clamp in appendLogs - Cache dayjs().format result within each 50ms log flush window Connection table (connection-table.tsx) - Decouple 5s relative-time tick from columnDefs via shared module-level tickStore + memoised RelativeTimeCell so the tick no longer rebuilds the table - RowComponent memo with custom comparator (relies on stable row reference) - Lift sx objects to module scope - Stable onShowDetail via ref App data provider (app-data-provider, app-data-context) - Split monolithic context into six sub-contexts (Proxies/Rules/ClashConfig/ System/Uptime/Refreshers); 3s uptime ticks no longer invalidate unrelated consumers - useAppData adapter aggregates sub-contexts; consumer files unchanged - useStableFn helper stabilises all refresh* callback identities - Extract useCtx helper to remove repeated null-check boilerplate Canvas traffic graph (enhanced-canvas-traffic-graph, use-traffic-monitor) - Lift Y-axis scale (max/min) to drawGraph layer; calculateY allocations per frame: ~600 -> 1 - Document visibility gate stops RAF and the setNow interval when the window is hidden; appendData unaffected - Reuse the existing visibilitychange listener instead of adding a second one; isDocumentVisibleRef guards animate() inside the frame - Convert forEach arrow shorthands to block bodies - Drop unnecessary state-setter deps from a useCallback Proxy groups (proxy-groups, proxy-render, use-render-list) - Narrow proxyColItemsMemo dep: headState -> headState.showType - Per-group fingerprint cache + prevListRef in use-render-list; steady-state refetch ticks become O(0) and the list reference stays stable when nothing changed - useStableCallback wraps handleCheckAll / handleLocation
117 lines
3.2 KiB
TypeScript
117 lines
3.2 KiB
TypeScript
import { Context, createContext, use } from 'react'
|
|
import {
|
|
BaseConfig,
|
|
ProxyProvider,
|
|
Rule,
|
|
RuleProvider,
|
|
} from 'tauri-plugin-mihomo-api'
|
|
|
|
export interface AppDataContextType {
|
|
proxies: any
|
|
clashConfig: BaseConfig
|
|
rules: Rule[]
|
|
sysproxy: any
|
|
runningMode?: string
|
|
uptime: number
|
|
proxyProviders: Record<string, ProxyProvider>
|
|
ruleProviders: Record<string, RuleProvider>
|
|
systemProxyAddress: string
|
|
isCoreDataPending: boolean
|
|
|
|
refreshProxy: () => Promise<any>
|
|
refreshClashConfig: () => Promise<any>
|
|
refreshRules: () => Promise<any>
|
|
refreshSysproxy: () => Promise<any>
|
|
refreshProxyProviders: () => Promise<any>
|
|
refreshRuleProviders: () => Promise<any>
|
|
refreshAll: () => Promise<any>
|
|
}
|
|
|
|
export interface ConnectionWithSpeed extends IConnectionsItem {
|
|
curUpload: number
|
|
curDownload: number
|
|
}
|
|
|
|
export interface ConnectionSpeedData {
|
|
id: string
|
|
upload: number
|
|
download: number
|
|
timestamp: number
|
|
}
|
|
|
|
export interface ProxiesContextType {
|
|
proxies: any
|
|
proxyProviders: Record<string, ProxyProvider | undefined>
|
|
isProxiesPending: boolean
|
|
}
|
|
|
|
export interface RulesContextType {
|
|
rules: Rule[]
|
|
ruleProviders: Record<string, RuleProvider | undefined>
|
|
}
|
|
|
|
export interface ClashConfigContextType {
|
|
clashConfig: BaseConfig | undefined
|
|
isClashConfigPending: boolean
|
|
}
|
|
|
|
export interface SystemContextType {
|
|
sysproxy: any
|
|
runningMode?: string
|
|
systemProxyAddress: string
|
|
}
|
|
|
|
export interface UptimeContextType {
|
|
uptime: number
|
|
}
|
|
|
|
export interface RefreshersContextType {
|
|
refreshProxy: () => Promise<any>
|
|
refreshClashConfig: () => Promise<any>
|
|
refreshRules: () => Promise<any>
|
|
refreshSysproxy: () => Promise<any>
|
|
refreshProxyProviders: () => Promise<any>
|
|
refreshRuleProviders: () => Promise<any>
|
|
refreshAll: () => Promise<any>
|
|
}
|
|
|
|
export const ProxiesContext = createContext<ProxiesContextType | null>(null)
|
|
export const RulesContext = createContext<RulesContextType | null>(null)
|
|
export const ClashConfigContext = createContext<ClashConfigContextType | null>(
|
|
null,
|
|
)
|
|
export const SystemContext = createContext<SystemContextType | null>(null)
|
|
export const UptimeContext = createContext<UptimeContextType | null>(null)
|
|
export const RefreshersContext = createContext<RefreshersContextType | null>(
|
|
null,
|
|
)
|
|
|
|
const useCtx = <T>(ctx: Context<T | null>): T => {
|
|
const v = use(ctx)
|
|
if (!v) throw new Error('useAppData must be used within AppDataProvider')
|
|
return v
|
|
}
|
|
|
|
export const useAppData = (): AppDataContextType => {
|
|
const { proxies, proxyProviders, isProxiesPending } = useCtx(ProxiesContext)
|
|
const { rules, ruleProviders } = useCtx(RulesContext)
|
|
const { clashConfig, isClashConfigPending } = useCtx(ClashConfigContext)
|
|
const { sysproxy, runningMode, systemProxyAddress } = useCtx(SystemContext)
|
|
const { uptime } = useCtx(UptimeContext)
|
|
const refreshers = useCtx(RefreshersContext)
|
|
|
|
return {
|
|
proxies,
|
|
clashConfig: clashConfig as BaseConfig,
|
|
rules,
|
|
sysproxy,
|
|
runningMode,
|
|
uptime,
|
|
proxyProviders: proxyProviders as Record<string, ProxyProvider>,
|
|
ruleProviders: ruleProviders as Record<string, RuleProvider>,
|
|
systemProxyAddress,
|
|
isCoreDataPending: isProxiesPending || isClashConfigPending,
|
|
...refreshers,
|
|
}
|
|
}
|