Compare commits

..
Author SHA1 Message Date
renovate[bot] 4edbf6e931 chore(deps): update dependency tldts to v7.6.3 2026-11-29 17:28:21 +00:00
12 changed files with 141 additions and 134 deletions
+1 -1
View File
@@ -78,7 +78,7 @@
"rehype-sanitize": "^6.0.0",
"swr": "^2.5.1",
"tauri-plugin-mihomo-api": "github:clash-verge-rev/tauri-plugin-mihomo#main",
"tldts": "7.6.2",
"tldts": "7.6.3",
"types-pac": "^1.0.3",
"validator": "^13.15.35"
},
+9 -9
View File
@@ -312,8 +312,8 @@ importers:
specifier: github:clash-verge-rev/tauri-plugin-mihomo#main
version: https://codeload.github.com/clash-verge-rev/tauri-plugin-mihomo/tar.gz/7e4fa8642cf6c394ed88b5a969420d8eab60087f
tldts:
specifier: 7.6.2
version: 7.6.2
specifier: 7.6.3
version: 7.6.3
types-pac:
specifier: ^1.0.3
version: 1.0.3
@@ -4056,11 +4056,11 @@ packages:
resolution: {integrity: sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==}
engines: {node: '>=12.0.0'}
tldts-core@7.6.2:
resolution: {integrity: sha512-/ZG+gignPzfgtpWNnbS7AKcU1ptt9jDqhIlr7vHOaw/Psz6HjXyB2CeFS3RrUGYwER/Q4F6IS8+9rZuYfRUz+Q==}
tldts-core@7.6.3:
resolution: {integrity: sha512-HjQiEhyxofqR2GM1cOp8CSwMYoKpmz/guhmZniTUayo7W/8d6uXebMelNanMFwRz0jKcMIprTzQDLuPdDyTBNA==}
tldts@7.6.2:
resolution: {integrity: sha512-IylRLICacWmPVf5tQIOvKkZzf2Vp8qJT3bAZox+3bWXj5P/pn45PC1a9l86loP7D/ywbSt/h/NnyIoR0fg4utA==}
tldts@7.6.3:
resolution: {integrity: sha512-x/ocO0PagQVYQHoAk19SsR9j/ylnRLU82sugMUl9eGdHGHgw46NLzopvcYDUCW/kgVFwJe/syU9dMjbrS2e5cQ==}
hasBin: true
trim-lines@3.0.1:
@@ -8162,11 +8162,11 @@ snapshots:
fdir: 6.5.0(picomatch@4.0.7)
picomatch: 4.0.7
tldts-core@7.6.2: {}
tldts-core@7.6.3: {}
tldts@7.6.2:
tldts@7.6.3:
dependencies:
tldts-core: 7.6.2
tldts-core: 7.6.3
trim-lines@3.0.1: {}
+6 -4
View File
@@ -6,7 +6,8 @@ import { createRoot } from 'react-dom/client'
import { SWRConfig } from 'swr'
import { VirtualList } from '../../src/components/base/virtual-list'
import { VisibleConnectionRowItem } from '../../src/components/connection/connection-row-item'
import { ConnectionRowItem } from '../../src/components/connection/connection-row-item'
import { useConnectionRowViews } from '../../src/components/connection/connection-row-view'
import LogItem from '../../src/components/log/log-item'
import { initializeLanguage } from '../../src/services/i18n'
import { setPreloadConfig } from '../../src/services/preload'
@@ -34,9 +35,10 @@ export function Components() {
}),
[],
)
const rows = useConnectionRowViews(connections)
return (
<VirtualList
count={scenario === 'logs' ? logs.length : connections.length}
count={scenario === 'logs' ? logs.length : rows.length}
estimateSize={scenario === 'logs' ? 50 : 56}
style={{ height: 640, margin: 24 }}
renderItem={(index) =>
@@ -46,8 +48,8 @@ export function Components() {
searchState={searchState}
/>
) : (
<VisibleConnectionRowItem
connection={connections[index]}
<ConnectionRowItem
row={rows[index]}
closed={false}
onShowDetail={() => {}}
/>
+8 -10
View File
@@ -210,7 +210,7 @@ impl<'a> MemberResolver<'a> {
.collect()
}
fn resolve(&self, name: String, scoped: impl FnOnce(&str) -> Option<&'a String>) -> ProxyMemberRef {
fn resolve(&self, name: String, scoped: Option<&String>) -> ProxyMemberRef {
if self.group_names.contains(&name) {
ProxyMemberRef::Group { name }
} else if let Some(record_id) = self.core_node_ids.get(&name) {
@@ -225,7 +225,7 @@ impl<'a> MemberResolver<'a> {
}
} else {
let candidates = self.provider_candidates.get(&name).map_or(&[][..], Vec::as_slice);
match (scoped(&name), candidates) {
match (scoped, candidates) {
(Some(record_id), _) | (None, [(_, record_id)]) => ProxyMemberRef::Node {
name,
record_id: record_id.clone(),
@@ -415,14 +415,12 @@ fn build_group(name: String, proxy: Proxy, resolver: &MemberResolver<'_>) -> Pro
.unwrap_or_default()
.into_iter()
.map(|member| {
resolver.resolve(member, |member| {
let (occurrence, scoped) = seen
.entry(member.to_owned())
.or_insert_with(|| (0, resolver.scoped_candidates(&name, member)));
let picked = scoped.get(*occurrence).or_else(|| scoped.first()).copied();
*occurrence += 1;
picked
})
let (occurrence, scoped) = seen
.entry(member.clone())
.or_insert_with(|| (0, resolver.scoped_candidates(&name, &member)));
let picked = scoped.get(*occurrence).or_else(|| scoped.first()).copied();
*occurrence += 1;
resolver.resolve(member, picked)
})
.collect();
@@ -1,15 +1,12 @@
import { CloseRounded } from '@mui/icons-material'
import { IconButton } from '@mui/material'
import { useLockFn } from 'ahooks'
import { memo, useCallback, useMemo } from 'react'
import { memo, useCallback } from 'react'
import { useTranslation } from 'react-i18next'
import { closeConnection } from 'tauri-plugin-mihomo-api'
import { RelativeTime } from './connection-relative-time'
import {
createConnectionRowView,
type ConnectionRowView,
} from './connection-row-view'
import type { ConnectionRowView } from './connection-row-view'
import type { ConnectionRuleKind } from './connection-rule'
interface Props {
@@ -73,7 +70,7 @@ const actionStyle = {
transform: 'translateY(-50%)',
} as const
const ConnectionRowItem = memo(
export const ConnectionRowItem = memo(
function ConnectionRowItem({ row, closed, onShowDetail }: Props) {
const { t } = useTranslation()
const onDelete = useLockFn(async () => closeConnection(row.id))
@@ -132,11 +129,3 @@ 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,3 +1,5 @@
import { useMemo, useRef } from 'react'
const TRAFFIC_UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
export interface ConnectionRowView {
@@ -83,7 +85,7 @@ export const getConnectionTypeLabel = (connection: IConnectionsItem) => {
export const getConnectionStartTime = (connection: IConnectionsItem) =>
Date.parse(connection.start || '') || 0
export const createConnectionRowView = (connection: IConnectionsItem) => {
const createConnectionRowView = (connection: IConnectionsItem) => {
const uploadSpeed = connection.curUpload ?? 0
const downloadSpeed = connection.curDownload ?? 0
@@ -112,3 +114,66 @@ export 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])
}
+18 -58
View File
@@ -218,51 +218,11 @@ const getConnectionCellValue = (
}
}
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,
const compareConnectionCellValue = (
field: ColumnField,
left: IConnectionsItem,
right: IConnectionsItem,
getSnapshot: (row: IConnectionsItem) => TableRowSnapshot,
) => {
switch (field) {
case 'download':
@@ -274,6 +234,14 @@ const compareConnectionTraffic = (
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 = (
@@ -629,21 +597,13 @@ export const ConnectionTable = (props: Props) => {
const sortedConnections = useMemo(() => {
if (!sorting) return connections
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 direction = sorting.desc ? -1 : 1
return [...connections].sort(
(left, right) =>
compareConnectionCellValue(sorting.id, left, right, getRowSnapshot) *
direction,
)
}, [connections, sorting, getRowSnapshot])
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(open)
const { proxyView } = useProxiesData()
const proxyGroups = useMemo(() => proxyView?.groups ?? [], [proxyView])
+12 -5
View File
@@ -30,8 +30,11 @@ import {
ConnectionDetail,
ConnectionDetailRef,
} from '@/components/connection/connection-detail'
import { VisibleConnectionRowItem } from '@/components/connection/connection-row-item'
import { getConnectionStartTime } from '@/components/connection/connection-row-view'
import { ConnectionRowItem } from '@/components/connection/connection-row-item'
import {
getConnectionStartTime,
useConnectionRowViews,
} 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'
@@ -142,6 +145,10 @@ const ConnectionsPage = () => {
curOrderOpt,
])
const displayRows = useConnectionRowViews(
isTableLayout ? EMPTY_CONNECTIONS : filterConn,
)
const detailRef = useRef<ConnectionDetailRef>(null!)
const selectConnectionsType = useCallback(
@@ -332,11 +339,11 @@ const ConnectionsPage = () => {
) : (
<VirtualList
key={connectionsType}
count={filterConn.length}
count={displayRows.length}
estimateSize={56}
renderItem={(i) => (
<VisibleConnectionRowItem
connection={filterConn[i]}
<ConnectionRowItem
row={displayRows[i]}
closed={connectionsType === 'closed'}
onShowDetail={showDetailById}
/>
+10 -8
View File
@@ -52,16 +52,21 @@ 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(filterLogs.length - 1, {
virtuosoRef.current?.scrollToIndex(filteredLogs.length - 1, {
behavior: 'smooth',
})
}
}, [isDescending, filterLogs.length])
}, [isDescending, filteredLogs.length])
const handleLogLevelChange = (newLevel: LogFilter) => {
setClashLog((pre) => ({ ...pre!, logFilter: newLevel }))
@@ -171,16 +176,13 @@ const LogPage = () => {
/>
</Box>
{filterLogs.length > 0 ? (
{filteredLogs.length > 0 ? (
<VirtualList
ref={virtuosoRef}
count={filterLogs.length}
count={filteredLogs.length}
estimateSize={50}
renderItem={(i) => (
<LogItem
value={filterLogs[isDescending ? filterLogs.length - 1 - i : i]}
searchState={searchState}
/>
<LogItem value={filteredLogs[i]} searchState={searchState} />
)}
onScroll={(event) => {
const element = event.currentTarget as HTMLDivElement
+4 -14
View File
@@ -1,4 +1,4 @@
import { Context, createContext, use, useEffect } from 'react'
import { Context, createContext, use } from 'react'
import { BaseConfig, Rule, RuleProvider } from 'tauri-plugin-mihomo-api'
import type { ProxyViewV1 } from '@/types/proxy-view'
@@ -39,9 +39,7 @@ export interface RefreshersContextType {
refreshAll: () => Promise<unknown>
}
export const ProxiesContext = createContext<
(ProxiesContextType & { registerConsumer: () => () => void }) | null
>(null)
export const ProxiesContext = createContext<ProxiesContextType | null>(null)
export const RulesContext = createContext<RulesContextType | null>(null)
export const ClashConfigContext = createContext<ClashConfigContextType | null>(
null,
@@ -59,16 +57,8 @@ const useCtx = <T>(ctx: Context<T | null>, hookName: string): T => {
return v
}
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 useProxiesData = (): ProxiesContextType =>
useCtx(ProxiesContext, 'useProxiesData')
export const useRulesData = () => {
const { rules, ruleProviders } = useCtx(RulesContext, 'useRulesData')
+3 -9
View File
@@ -1,4 +1,4 @@
import React, { useCallback, useMemo, useRef, useState } from 'react'
import React, { useCallback, useMemo, useRef } from 'react'
import {
getBaseConfig,
getRuleProviders,
@@ -53,11 +53,6 @@ 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,
@@ -67,7 +62,7 @@ export const AppDataProvider = ({
} = useQuery({
queryKey: ['getProxyView'],
queryFn: getProxyView,
refetchInterval: proxyViewConsumers > 0 ? 15000 : false,
refetchInterval: 15000,
refetchIntervalInBackground: false,
...TQ_MIHOMO,
})
@@ -133,9 +128,8 @@ export const AppDataProvider = ({
proxyView,
isProxyViewPending,
isProxyViewError: Boolean(proxyViewError),
registerConsumer: registerProxyViewConsumer,
}),
[proxyView, isProxyViewPending, proxyViewError, registerProxyViewConsumer],
[proxyView, isProxyViewPending, proxyViewError],
)
const rulesValue = useMemo(