refactor IPC (#341)

This commit is contained in:
Lingxuan Zuo
2026-03-08 11:54:49 +08:00
committed by GitHub
Unverified
parent c03d92e9a2
commit 3d804a9f5e
52 changed files with 3121 additions and 336 deletions

29
src/lib/telemetry.ts Normal file
View File

@@ -0,0 +1,29 @@
type TelemetryPayload = Record<string, unknown>;
const counters = new Map<string, number>();
function safeStringify(payload: TelemetryPayload): string {
try {
return JSON.stringify(payload);
} catch {
return '{}';
}
}
export function trackUiEvent(event: string, payload: TelemetryPayload = {}): void {
const count = (counters.get(event) ?? 0) + 1;
counters.set(event, count);
const logPayload = {
...payload,
count,
ts: new Date().toISOString(),
};
// Local-only telemetry for UX diagnostics.
console.info(`[ui-metric] ${event} ${safeStringify(logPayload)}`);
}
export function getUiCounter(event: string): number {
return counters.get(event) ?? 0;
}