Compare commits

...
Author SHA1 Message Date
renovate[bot]renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>Tunglies
c6ef67718e chore(deps): update cargo dependencies (#8834)
* chore(deps): update cargo dependencies

* fix(network): switch the rustls provider to aws-lc-rs

rustls 0.23.48 deprecates `rustls::crypto::ring::default_provider()`
for lacking post-quantum support, which fails `cargo clippy-all`
(`-D warnings`) on every platform, and it offers no non-deprecated
ring provider constructor.

aws-lc-rs is already compiled in through reqwest, so the delay-test
connector and the static-webpki-roots fallback gain no new build
requirement.

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Tunglies <77394545+Tunglies@users.noreply.github.com>
2026-12-06 02:50:35 +00:00
Tunglies cc074d8967 perf: reduce work in connections, proxy views, and logs (#8770)
* perf(connections): sort by column keys without building row snapshots

* perf(proxy): defer provider candidate lookup until needed

* perf(logs): index descending virtual rows without reversing the list

* perf(connections): build list row views only when mounted

* refactor(connections): align perf replay with visible row derivation

* perf(proxy): stop periodic view refresh without consumers
2026-12-06 01:36:31 +00:00
14 changed files with 182 additions and 190 deletions
Generated
+62 -62
View File
@@ -381,7 +381,7 @@ dependencies = [
"dirs 6.0.0",
"os_info",
"smappservice-rs",
"thiserror 2.0.20",
"thiserror 2.0.21",
"windows-registry",
"windows-result 0.4.1",
]
@@ -664,7 +664,7 @@ dependencies = [
"tap",
"temporal_rs",
"thin-vec",
"thiserror 2.0.20",
"thiserror 2.0.21",
"time",
"timezone_provider",
"xsum",
@@ -928,7 +928,7 @@ dependencies = [
"semver 1.0.28",
"serde",
"serde_json",
"thiserror 2.0.20",
"thiserror 2.0.21",
]
[[package]]
@@ -1194,7 +1194,7 @@ dependencies = [
name = "clash-verge-backup-archive"
version = "0.1.0"
dependencies = [
"thiserror 2.0.20",
"thiserror 2.0.21",
"zip",
]
@@ -1217,7 +1217,7 @@ version = "0.1.0"
dependencies = [
"criterion",
"parking_lot 0.13.0",
"thiserror 2.0.20",
"thiserror 2.0.21",
"tokio",
]
@@ -1244,7 +1244,7 @@ dependencies = [
"flexi_logger",
"log",
"parking_lot 0.13.0",
"thiserror 2.0.20",
"thiserror 2.0.21",
"tracing-estuary",
]
@@ -1271,7 +1271,7 @@ dependencies = [
"serde_json",
"serde_yaml_ng",
"specta",
"thiserror 2.0.20",
"thiserror 2.0.21",
"tristr",
]
@@ -1306,7 +1306,7 @@ dependencies = [
"log",
"serde_yaml_ng",
"sha2 0.11.2",
"thiserror 2.0.20",
"thiserror 2.0.21",
"tokio",
"tristr",
]
@@ -1327,7 +1327,7 @@ dependencies = [
"http",
"percent-encoding",
"serde_yaml_ng",
"thiserror 2.0.20",
"thiserror 2.0.21",
"url",
]
@@ -2058,7 +2058,7 @@ dependencies = [
"log",
"prost-types",
"ringbuf",
"thiserror 2.0.20",
"thiserror 2.0.21",
"tokio",
"tokio-stream",
"tonic",
@@ -2556,7 +2556,7 @@ dependencies = [
"log",
"nu-ansi-term",
"regex",
"thiserror 2.0.20",
"thiserror 2.0.21",
]
[[package]]
@@ -2616,9 +2616,9 @@ checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b"
[[package]]
name = "form_urlencoded"
version = "1.2.2"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf"
checksum = "afa489199eaffb1211795df1c6236ce1ad0d41a6fa45250add73e3b02420f06e"
dependencies = [
"percent-encoding",
]
@@ -3013,7 +3013,7 @@ dependencies = [
"objc2-app-kit",
"once_cell",
"serde",
"thiserror 2.0.20",
"thiserror 2.0.21",
"windows-sys 0.59.0",
"x11rb",
"xkeysym",
@@ -3286,9 +3286,9 @@ dependencies = [
[[package]]
name = "http"
version = "1.5.0"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0"
checksum = "a07dc2d082802d1782faa5b3c8ac252f3a4fc89f51e76c3f37dc2d1a5b857c05"
dependencies = [
"bytes",
"itoa",
@@ -3883,7 +3883,7 @@ dependencies = [
"jni-sys 0.4.1",
"log",
"simd_cesu8",
"thiserror 2.0.20",
"thiserror 2.0.21",
"walkdir",
"windows-link 0.2.1",
]
@@ -3959,7 +3959,7 @@ dependencies = [
"jsonptr",
"serde",
"serde_json",
"thiserror 2.0.20",
"thiserror 2.0.21",
]
[[package]]
@@ -4010,7 +4010,7 @@ dependencies = [
"rand 0.10.2",
"serde",
"serde_json",
"thiserror 2.0.20",
"thiserror 2.0.21",
"tokio",
"tokio-stream",
"tokio-util",
@@ -4399,7 +4399,7 @@ dependencies = [
"objc2-foundation",
"png",
"serde",
"thiserror 2.0.20",
"thiserror 2.0.21",
"windows-sys 0.61.2",
]
@@ -4476,7 +4476,7 @@ dependencies = [
"cc",
"libc",
"serde",
"thiserror 2.0.20",
"thiserror 2.0.21",
"winapi",
]
@@ -5058,7 +5058,7 @@ dependencies = [
"objc2-osa-kit",
"serde",
"serde_json",
"thiserror 2.0.20",
"thiserror 2.0.21",
]
[[package]]
@@ -5625,7 +5625,7 @@ dependencies = [
"rustc-hash",
"rustls",
"socket2",
"thiserror 2.0.20",
"thiserror 2.0.21",
"tokio",
"tracing",
"web-time",
@@ -5648,7 +5648,7 @@ dependencies = [
"rustls",
"rustls-pki-types",
"slab",
"thiserror 2.0.20",
"thiserror 2.0.21",
"tinyvec",
"tracing",
"web-time",
@@ -5846,7 +5846,7 @@ checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac"
dependencies = [
"getrandom 0.2.17",
"libredox",
"thiserror 2.0.20",
"thiserror 2.0.21",
]
[[package]]
@@ -6209,9 +6209,9 @@ dependencies = [
[[package]]
name = "rustls"
version = "0.23.47"
version = "0.23.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ac0e747c10d93d873fd4c50b26ef47ad92d1bfb48f6922003bb514070f6e88c"
checksum = "86c8de8f13bac4bb046743409c751e2343621c0293a805c143ede57c5c95c3f8"
dependencies = [
"aws-lc-rs",
"log",
@@ -6871,7 +6871,7 @@ dependencies = [
"objc2",
"objc2-foundation",
"objc2-service-management",
"thiserror 2.0.20",
"thiserror 2.0.21",
]
[[package]]
@@ -7166,7 +7166,7 @@ dependencies = [
"log",
"serde",
"system-configuration",
"thiserror 2.0.20",
"thiserror 2.0.21",
"tokio",
"url",
"which 8.0.5",
@@ -7356,7 +7356,7 @@ dependencies = [
"tauri-runtime",
"tauri-runtime-wry",
"tauri-utils",
"thiserror 2.0.20",
"thiserror 2.0.21",
"tokio",
"tracing",
"tray-icon",
@@ -7406,7 +7406,7 @@ dependencies = [
"sha2 0.11.2",
"syn 2.0.119",
"tauri-utils",
"thiserror 2.0.20",
"thiserror 2.0.21",
"uuid",
"walkdir",
]
@@ -7452,7 +7452,7 @@ dependencies = [
"serde_json",
"tauri",
"tauri-plugin",
"thiserror 2.0.20",
"thiserror 2.0.21",
]
[[package]]
@@ -7481,7 +7481,7 @@ dependencies = [
"serde_json",
"tauri",
"tauri-plugin",
"thiserror 2.0.20",
"thiserror 2.0.21",
]
[[package]]
@@ -7498,7 +7498,7 @@ dependencies = [
"tauri",
"tauri-plugin",
"tauri-utils",
"thiserror 2.0.20",
"thiserror 2.0.21",
"tracing",
"url",
"windows-registry",
@@ -7546,7 +7546,7 @@ dependencies = [
"tauri",
"tauri-plugin",
"tauri-plugin-fs",
"thiserror 2.0.20",
"thiserror 2.0.21",
"url",
]
@@ -7569,7 +7569,7 @@ dependencies = [
"tauri",
"tauri-plugin",
"tauri-utils",
"thiserror 2.0.20",
"thiserror 2.0.21",
"toml 1.2.1+spec-1.1.0",
"url",
]
@@ -7586,7 +7586,7 @@ dependencies = [
"serde_json",
"tauri",
"tauri-plugin",
"thiserror 2.0.20",
"thiserror 2.0.21",
]
[[package]]
@@ -7608,7 +7608,7 @@ dependencies = [
"tauri",
"tauri-plugin",
"tauri-plugin-fs",
"thiserror 2.0.20",
"thiserror 2.0.21",
"tokio",
"url",
"urlpattern",
@@ -7631,7 +7631,7 @@ dependencies = [
"serde_json",
"tauri",
"tauri-plugin",
"thiserror 2.0.20",
"thiserror 2.0.21",
"tokio",
"tokio-tungstenite",
"ts-rs",
@@ -7653,7 +7653,7 @@ dependencies = [
"serde_repr",
"tauri",
"tauri-plugin",
"thiserror 2.0.20",
"thiserror 2.0.21",
"time",
"url",
"zbus",
@@ -7675,7 +7675,7 @@ dependencies = [
"serde_json",
"tauri",
"tauri-plugin",
"thiserror 2.0.20",
"thiserror 2.0.21",
"url",
"windows 0.62.2",
"zbus",
@@ -7699,7 +7699,7 @@ dependencies = [
"shared_child",
"tauri",
"tauri-plugin",
"thiserror 2.0.20",
"thiserror 2.0.21",
"tokio",
"windows-sys 0.60.2",
]
@@ -7730,7 +7730,7 @@ dependencies = [
"tauri",
"tauri-plugin",
"tempfile",
"thiserror 2.0.20",
"thiserror 2.0.21",
"time",
"tokio",
"url",
@@ -7761,7 +7761,7 @@ dependencies = [
"tauri",
"tauri-plugin",
"tempfile",
"thiserror 2.0.20",
"thiserror 2.0.21",
"tokio",
"tracing",
"uuid",
@@ -7783,7 +7783,7 @@ dependencies = [
"serde_json",
"tauri",
"tauri-plugin",
"thiserror 2.0.20",
"thiserror 2.0.21",
]
[[package]]
@@ -7804,7 +7804,7 @@ dependencies = [
"serde",
"serde_json",
"tauri-utils",
"thiserror 2.0.20",
"thiserror 2.0.21",
"url",
"webkit2gtk",
"webview2-com",
@@ -7853,7 +7853,7 @@ dependencies = [
"specta-util",
"tauri",
"tauri-specta-macros",
"thiserror 2.0.20",
"thiserror 2.0.21",
]
[[package]]
@@ -7899,7 +7899,7 @@ dependencies = [
"serde_json",
"serde_with",
"swift-rs",
"thiserror 2.0.20",
"thiserror 2.0.21",
"toml 1.2.1+spec-1.1.0",
"url",
"urlpattern",
@@ -7924,7 +7924,7 @@ version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed071c670382e85fc2f48ae706492d8c338f4f89bf72520d32f8abfe880aade"
dependencies = [
"thiserror 2.0.20",
"thiserror 2.0.21",
"windows 0.61.3",
"windows-version",
]
@@ -8048,11 +8048,11 @@ dependencies = [
[[package]]
name = "thiserror"
version = "2.0.20"
version = "2.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec86235f5fcc2a73650310756d2ac5b138a5780bbbdfae3eeccec992c435ba4f"
checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e"
dependencies = [
"thiserror-impl 2.0.20",
"thiserror-impl 2.0.21",
]
[[package]]
@@ -8068,9 +8068,9 @@ dependencies = [
[[package]]
name = "thiserror-impl"
version = "2.0.20"
version = "2.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af"
checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524"
dependencies = [
"proc-macro2",
"quote",
@@ -8582,7 +8582,7 @@ dependencies = [
"objc2-foundation",
"png",
"serde",
"thiserror 2.0.20",
"thiserror 2.0.21",
"windows-sys 0.61.2",
]
@@ -8636,7 +8636,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "756050066659291d47a554a9f558125db17428b073c5ffce1daf5dcb0f7231d8"
dependencies = [
"serde_json",
"thiserror 2.0.20",
"thiserror 2.0.21",
"ts-rs-macros",
]
@@ -8665,7 +8665,7 @@ dependencies = [
"log",
"rand 0.9.5",
"sha1 0.10.7",
"thiserror 2.0.20",
"thiserror 2.0.21",
"utf-8",
]
@@ -8758,9 +8758,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
[[package]]
name = "url"
version = "2.5.8"
version = "2.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed"
checksum = "f00cd2407bb42c0ef17be88d4cf020f5cceffd121665bac9b8b9493a369b3b1a"
dependencies = [
"form_urlencoded",
"idna",
@@ -9198,7 +9198,7 @@ version = "0.39.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3a07132775117d6065853d9d1178157b8c90e228de47129d6bce2c7edebedfb"
dependencies = [
"thiserror 2.0.20",
"thiserror 2.0.21",
"windows 0.62.2",
"windows-core 0.62.2",
]
@@ -10062,7 +10062,7 @@ dependencies = [
"log",
"os_pipe",
"rustix 1.1.4",
"thiserror 2.0.20",
"thiserror 2.0.21",
"tree_magic_mini",
"wayland-backend",
"wayland-client",
@@ -10114,7 +10114,7 @@ dependencies = [
"sha2 0.11.2",
"soup3",
"tao-macros",
"thiserror 2.0.20",
"thiserror 2.0.21",
"tracing",
"url",
"webkit2gtk",
+1 -1
View File
@@ -83,7 +83,7 @@ tauri = { version = "2.13.0" }
tauri-plugin-clipboard-manager = "2.5.0"
parking_lot = "0.13.0"
anyhow = "1.0.105"
thiserror = "2.0.20"
thiserror = "2.0.21"
zip = "9.9.0"
boa_engine = "0.22.0"
futures = "0.3.34"
+2 -2
View File
@@ -5,10 +5,10 @@ edition = "2024"
[dependencies]
thiserror = { workspace = true }
http = "1"
http = "1.6.0"
percent-encoding = "2.3.2"
serde_yaml_ng = { workspace = true }
url = "2.5"
url = "2.5.9"
[lints]
workspace = true
+4 -6
View File
@@ -6,8 +6,7 @@ import { createRoot } from 'react-dom/client'
import { SWRConfig } from 'swr'
import { VirtualList } from '../../src/components/base/virtual-list'
import { ConnectionRowItem } from '../../src/components/connection/connection-row-item'
import { useConnectionRowViews } from '../../src/components/connection/connection-row-view'
import { VisibleConnectionRowItem } from '../../src/components/connection/connection-row-item'
import LogItem from '../../src/components/log/log-item'
import { initializeLanguage } from '../../src/services/i18n'
import { setPreloadConfig } from '../../src/services/preload'
@@ -35,10 +34,9 @@ export function Components() {
}),
[],
)
const rows = useConnectionRowViews(connections)
return (
<VirtualList
count={scenario === 'logs' ? logs.length : rows.length}
count={scenario === 'logs' ? logs.length : connections.length}
estimateSize={scenario === 'logs' ? 50 : 56}
style={{ height: 640, margin: 24 }}
renderItem={(index) =>
@@ -48,8 +46,8 @@ export function Components() {
searchState={searchState}
/>
) : (
<ConnectionRowItem
row={rows[index]}
<VisibleConnectionRowItem
connection={connections[index]}
closed={false}
onShowDetail={() => {}}
/>
+1 -1
View File
@@ -100,7 +100,7 @@ async-trait = "0.1.92"
clash_verge_service_ipc = { workspace = true, features = ["client"] }
arc-swap = "1.9.5"
tokio-rustls = "0.26.6"
rustls = { version = "0.23.47", features = ["ring"] }
rustls = { version = "0.23.48", features = ["aws_lc_rs"] }
webpki-roots = "1.0.12"
dark-light = "3.0.0"
bytes = "1.12.2"
+2 -1
View File
@@ -49,9 +49,10 @@ enum TlsRootMode {
}
/// ALPN stays unset: raw TLS connectors offer none, while reqwest needs the h2 offer.
/// The provider is passed explicitly: both rustls providers are compiled in, so the process default may vary.
pub(crate) fn build_webpki_rooted_tls_config() -> Result<rustls::ClientConfig> {
let root_store = rustls::RootCertStore::from_iter(webpki_roots::TLS_SERVER_ROOTS.iter().cloned());
let config = rustls::ClientConfig::builder_with_provider(Arc::new(rustls::crypto::ring::default_provider()))
let config = rustls::ClientConfig::builder_with_provider(Arc::new(rustls::crypto::aws_lc_rs::default_provider()))
.with_safe_default_protocol_versions()?
.with_root_certificates(root_store)
.with_no_client_auth();
@@ -1,12 +1,15 @@
import { CloseRounded } from '@mui/icons-material'
import { IconButton } from '@mui/material'
import { useLockFn } from 'ahooks'
import { memo, useCallback } from 'react'
import { memo, useCallback, useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import { closeConnection } from 'tauri-plugin-mihomo-api'
import { RelativeTime } from './connection-relative-time'
import type { ConnectionRowView } from './connection-row-view'
import {
createConnectionRowView,
type ConnectionRowView,
} from './connection-row-view'
import type { ConnectionRuleKind } from './connection-rule'
interface Props {
@@ -70,7 +73,7 @@ const actionStyle = {
transform: 'translateY(-50%)',
} as const
export const ConnectionRowItem = memo(
const ConnectionRowItem = memo(
function ConnectionRowItem({ row, closed, onShowDetail }: Props) {
const { t } = useTranslation()
const onDelete = useLockFn(async () => closeConnection(row.id))
@@ -129,3 +132,11 @@ export const ConnectionRowItem = memo(
prev.closed === next.closed &&
prev.onShowDetail === next.onShowDetail,
)
export const VisibleConnectionRowItem = memo(function VisibleConnectionRowItem({
connection,
...props
}: Omit<Props, 'row'> & { connection: IConnectionsItem }) {
const row = useMemo(() => createConnectionRowView(connection), [connection])
return <ConnectionRowItem row={row} {...props} />
})
@@ -1,5 +1,3 @@
import { useMemo, useRef } from 'react'
const TRAFFIC_UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
export interface ConnectionRowView {
@@ -85,7 +83,7 @@ export const getConnectionTypeLabel = (connection: IConnectionsItem) => {
export const getConnectionStartTime = (connection: IConnectionsItem) =>
Date.parse(connection.start || '') || 0
const createConnectionRowView = (connection: IConnectionsItem) => {
export const createConnectionRowView = (connection: IConnectionsItem) => {
const uploadSpeed = connection.curUpload ?? 0
const downloadSpeed = connection.curDownload ?? 0
@@ -114,66 +112,3 @@ const createConnectionRowView = (connection: IConnectionsItem) => {
searchableProcess: connection.metadata.process || '',
} satisfies ConnectionRowView
}
const sameConnectionRowView = (
left: ConnectionRowView,
right: ConnectionRowView,
) =>
left.host === right.host &&
left.process === right.process &&
left.network === right.network &&
left.type === right.type &&
left.chains === right.chains &&
left.rule === right.rule &&
left.time === right.time &&
left.source === right.source &&
left.destination === right.destination &&
left.uploadText === right.uploadText &&
left.downloadText === right.downloadText &&
left.uploadSpeedText === right.uploadSpeedText &&
left.downloadSpeedText === right.downloadSpeedText &&
left.upload === right.upload &&
left.download === right.download &&
left.uploadSpeed === right.uploadSpeed &&
left.downloadSpeed === right.downloadSpeed &&
left.searchableHost === right.searchableHost &&
left.searchableDestinationIP === right.searchableDestinationIP &&
left.searchableProcess === right.searchableProcess
export const useConnectionRowViews = (connections: IConnectionsItem[]) => {
const previousRowsRef = useRef(new Map<string, ConnectionRowView>())
const previousConnectionsRef = useRef(new Map<string, IConnectionsItem>())
return useMemo(() => {
const previousRows = previousRowsRef.current
const previousConnections = previousConnectionsRef.current
const nextRows = new Map<string, ConnectionRowView>()
const nextConnections = new Map<string, IConnectionsItem>()
const rows: ConnectionRowView[] = []
connections.forEach((connection) => {
nextConnections.set(connection.id, connection)
const previousRow = previousRows.get(connection.id)
const previousConnection = previousConnections.get(connection.id)
let row: ConnectionRowView
if (previousRow && previousConnection === connection) {
row = previousRow
} else {
const nextRow = createConnectionRowView(connection)
row =
previousRow && sameConnectionRowView(previousRow, nextRow)
? previousRow
: nextRow
}
nextRows.set(connection.id, row)
rows.push(row)
})
previousRowsRef.current = nextRows
previousConnectionsRef.current = nextConnections
return rows
}, [connections])
}
+58 -18
View File
@@ -232,11 +232,51 @@ const getConnectionCellValue = (
}
}
const compareConnectionCellValue = (
field: ColumnField,
type TrafficSortField = 'download' | 'upload' | 'dlSpeed' | 'ulSpeed'
type DisplaySortField = Exclude<ColumnField, TrafficSortField>
const connectionSortKey = (field: DisplaySortField, row: IConnectionsItem) => {
switch (field) {
case 'host':
return getConnectionHost(row)
case 'process':
return getConnectionProcess(row)
case 'source':
return getConnectionSource(row)
case 'remoteDestination':
return getConnectionDestination(row)
case 'chains':
return formatConnectionChains(row.chains)
case 'rule':
return getConnectionRule(row)
case 'type':
return getConnectionTypeLabel(row)
case 'time':
return getConnectionStartTime(row)
}
}
const sortByConnectionKey = (
connections: IConnectionsItem[],
field: DisplaySortField,
direction: number,
) => {
return connections
.map((row) => ({ row, key: connectionSortKey(field, row) }))
.sort((a, b) => {
const order =
typeof a.key === 'number'
? (Number(a.key) || 0) - (Number(b.key) || 0)
: String(a.key).localeCompare(String(b.key))
return order * direction
})
.map(({ row }) => row)
}
const compareConnectionTraffic = (
field: TrafficSortField,
left: IConnectionsItem,
right: IConnectionsItem,
getSnapshot: (row: IConnectionsItem) => TableRowSnapshot,
) => {
switch (field) {
case 'download':
@@ -248,14 +288,6 @@ const compareConnectionCellValue = (
case 'ulSpeed':
return (left.curUpload ?? 0) - (right.curUpload ?? 0)
}
const leftValue = getConnectionCellValue(field, getSnapshot(left))
const rightValue = getConnectionCellValue(field, getSnapshot(right))
if (typeof leftValue === 'number' || typeof rightValue === 'number') {
return (Number(leftValue) || 0) - (Number(rightValue) || 0)
}
return String(leftValue ?? '').localeCompare(String(rightValue ?? ''))
}
const renderCell = (
@@ -589,13 +621,21 @@ export const ConnectionTable = (props: Props) => {
const sortedConnections = useMemo(() => {
if (!sorting) return connections
const direction = sorting.desc ? -1 : 1
return [...connections].sort(
(left, right) =>
compareConnectionCellValue(sorting.id, left, right, getRowSnapshot) *
direction,
)
}, [connections, sorting, getRowSnapshot])
const { id, desc } = sorting
const direction = desc ? -1 : 1
if (
id === 'download' ||
id === 'upload' ||
id === 'dlSpeed' ||
id === 'ulSpeed'
) {
return [...connections].sort(
(left, right) => compareConnectionTraffic(id, left, right) * direction,
)
}
return sortByConnectionKey(connections, id, direction)
}, [connections, sorting])
const tableWidth = useMemo(
() => visibleColumns.reduce((total, column) => total + column.size, 0),
@@ -118,7 +118,7 @@ export const TunnelsViewer = forwardRef<TunnelsViewerRef>((_, ref) => {
})
}, [draftTunnels])
const { proxyView } = useProxiesData()
const { proxyView } = useProxiesData(open)
const proxyGroups = useMemo(() => proxyView?.groups ?? [], [proxyView])
+5 -12
View File
@@ -30,11 +30,8 @@ import {
ConnectionDetail,
ConnectionDetailRef,
} from '@/components/connection/connection-detail'
import { ConnectionRowItem } from '@/components/connection/connection-row-item'
import {
getConnectionStartTime,
useConnectionRowViews,
} from '@/components/connection/connection-row-view'
import { VisibleConnectionRowItem } from '@/components/connection/connection-row-item'
import { getConnectionStartTime } from '@/components/connection/connection-row-view'
import type { ConnectionRuleKind } from '@/components/connection/connection-rule'
import { ConnectionTable } from '@/components/connection/connection-table'
import { useConnectionData } from '@/hooks/use-connection-data'
@@ -145,10 +142,6 @@ const ConnectionsPage = () => {
curOrderOpt,
])
const displayRows = useConnectionRowViews(
isTableLayout ? EMPTY_CONNECTIONS : filterConn,
)
const detailRef = useRef<ConnectionDetailRef>(null!)
const selectConnectionsType = useCallback(
@@ -339,11 +332,11 @@ const ConnectionsPage = () => {
) : (
<VirtualList
key={connectionsType}
count={displayRows.length}
count={filterConn.length}
estimateSize={56}
renderItem={(i) => (
<ConnectionRowItem
row={displayRows[i]}
<VisibleConnectionRowItem
connection={filterConn[i]}
closed={connectionsType === 'closed'}
onShowDetail={showDetailById}
/>
+8 -10
View File
@@ -52,21 +52,16 @@ const LogPage = () => {
})
}, [logData, logState, match, searchState.text])
const filteredLogs = useMemo(
() => (isDescending ? [...filterLogs].reverse() : filterLogs),
[filterLogs, isDescending],
)
const scrollRef = useRef({ isNearBottom: true })
const virtuosoRef = useRef<VirtualListHandle>(null)
useEffect(() => {
if (!isDescending && scrollRef.current.isNearBottom) {
virtuosoRef.current?.scrollToIndex(filteredLogs.length - 1, {
virtuosoRef.current?.scrollToIndex(filterLogs.length - 1, {
behavior: 'smooth',
})
}
}, [isDescending, filteredLogs.length])
}, [isDescending, filterLogs.length])
const handleLogLevelChange = (newLevel: LogFilter) => {
setClashLog((pre) => ({ ...pre!, logFilter: newLevel }))
@@ -176,13 +171,16 @@ const LogPage = () => {
/>
</Box>
{filteredLogs.length > 0 ? (
{filterLogs.length > 0 ? (
<VirtualList
ref={virtuosoRef}
count={filteredLogs.length}
count={filterLogs.length}
estimateSize={50}
renderItem={(i) => (
<LogItem value={filteredLogs[i]} searchState={searchState} />
<LogItem
value={filterLogs[isDescending ? filterLogs.length - 1 - i : i]}
searchState={searchState}
/>
)}
onScroll={(event) => {
const element = event.currentTarget as HTMLDivElement
+14 -4
View File
@@ -1,4 +1,4 @@
import { Context, createContext, use } from 'react'
import { Context, createContext, use, useEffect } from 'react'
import { BaseConfig, Rule, RuleProvider } from 'tauri-plugin-mihomo-api'
import type { ProxyViewV1 } from '@/types/proxy-view'
@@ -39,7 +39,9 @@ export interface RefreshersContextType {
refreshAll: () => Promise<unknown>
}
export const ProxiesContext = createContext<ProxiesContextType | null>(null)
export const ProxiesContext = createContext<
(ProxiesContextType & { registerConsumer: () => () => void }) | null
>(null)
export const RulesContext = createContext<RulesContextType | null>(null)
export const ClashConfigContext = createContext<ClashConfigContextType | null>(
null,
@@ -57,8 +59,16 @@ const useCtx = <T>(ctx: Context<T | null>, hookName: string): T => {
return v
}
export const useProxiesData = (): ProxiesContextType =>
useCtx(ProxiesContext, 'useProxiesData')
export const useProxiesData = (active = true): ProxiesContextType => {
const data = useCtx(ProxiesContext, 'useProxiesData')
const { registerConsumer } = data
useEffect(() => {
if (active) return registerConsumer()
}, [active, registerConsumer])
return data
}
export const useRulesData = () => {
const { rules, ruleProviders } = useCtx(RulesContext, 'useRulesData')
+9 -3
View File
@@ -1,4 +1,4 @@
import React, { useCallback, useMemo, useRef } from 'react'
import React, { useCallback, useMemo, useRef, useState } from 'react'
import {
getBaseConfig,
getRuleProviders,
@@ -53,6 +53,11 @@ export const AppDataProvider = ({
const { verge } = useVerge()
const { data: runtimeConfig } = useRuntimeConfig()
const { clashInfo } = useClashInfo()
const [proxyViewConsumers, setProxyViewConsumers] = useState(0)
const registerProxyViewConsumer = useCallback(() => {
setProxyViewConsumers((count) => count + 1)
return () => setProxyViewConsumers((count) => count - 1)
}, [])
const {
data: proxyView,
@@ -62,7 +67,7 @@ export const AppDataProvider = ({
} = useQuery({
queryKey: ['getProxyView'],
queryFn: getProxyView,
refetchInterval: 15000,
refetchInterval: proxyViewConsumers > 0 ? 15000 : false,
refetchIntervalInBackground: false,
...TQ_MIHOMO,
})
@@ -128,8 +133,9 @@ export const AppDataProvider = ({
proxyView,
isProxyViewPending,
isProxyViewError: Boolean(proxyViewError),
registerConsumer: registerProxyViewConsumer,
}),
[proxyView, isProxyViewPending, proxyViewError],
[proxyView, isProxyViewPending, proxyViewError, registerProxyViewConsumer],
)
const rulesValue = useMemo(