Files
clash-verge-rev/scripts/perf/adapter.ts
T
Tunglies a0ce1cdadf chore(perf): extract replay tooling into a standalone harness (#8645)
* chore(perf): use the external measurement harness

Keep real Traffic, Logs and Connections scenes and the isolated native
entry beside product APIs. Invoke the standalone runner with an explicit
project path and remove bundled measurement orchestration.

Support the optional owned virtual display and read-only isolation
snapshots without changing ordinary product startup or networking.

* docs: scope agent guidance to the active task

Keep behavior and ownership guidance with the relevant task routes,
including the external performance adapter workflow. Preserve focused
self-review for routine changes and independent review where required.

* docs(perf): link the standalone harness repository

Link the harness repository and operating guide, and document first-time
checkout setup while preserving explicit paths for routine invocation.

* fix(perf): account for external harness dependencies in Knip

* chore(perf): keep tool dependencies and guidance outside the product

* docs(perf): keep product guidance focused on the adapter
2026-11-14 06:11:35 +00:00

58 lines
1.9 KiB
TypeScript

import { MihomoWebSocket } from 'tauri-plugin-mihomo-api'
import { subscribe, scenario } from './replay'
// Only this perf entry replaces socket transport; the normal application never imports it.
export function installAdapter() {
const connect = async (kind: string) => {
const data = document.documentElement.dataset
data.perfSubscriptions = String(Number(data.perfSubscriptions || 0) + 1)
const callbacks = new Set<
(message: { type: 'Text'; data: string }) => void
>()
const unsubscribe = subscribe((frame) => {
const messages =
kind === 'logs'
? (frame.payload as ILogItem[])
: [
kind === 'traffic'
? { up: frame.sequence * 1000, down: frame.sequence * 5000 }
: frame.payload,
]
for (const payload of messages) {
const message = { type: 'Text' as const, data: JSON.stringify(payload) }
callbacks.forEach((callback) => {
callback(message)
data.perfDelivered = String(Number(data.perfDelivered || 0) + 1)
})
}
})
return {
addListener: (
callback: (message: { type: 'Text'; data: string }) => void,
) => {
callbacks.add(callback)
return () => callbacks.delete(callback)
},
close: async () => {
unsubscribe()
callbacks.clear()
data.perfSubscriptions = String(Number(data.perfSubscriptions) - 1)
},
} as unknown as MihomoWebSocket
}
MihomoWebSocket.connect_logs = async () => connect('logs')
MihomoWebSocket.connect_connections = async () => connect('connections')
MihomoWebSocket.connect_traffic = async () => connect('traffic')
if (scenario === 'logs')
localStorage.setItem(
'clash-log',
JSON.stringify({
enable: true,
logLevel: 'INFO',
logFilter: 'all',
logOrder: 'desc',
}),
)
}