feat(telemetry): handle application shutdown process

This update introduces a structured shutdown process for the application. It ensures that background tasks are properly terminated and telemetry is notified when the frontend is shutting down, preventing any ongoing operations from continuing during this state.

- Added event listeners to manage app shutdown events
- Implemented a shutdown handler to clear timers and notify telemetry
- Updated background task checks to respect the shutdown state
This commit is contained in:
Christoph Brandau
2026-08-10 17:29:03 +02:00
parent a6c86daf62
commit ac7cacd687
2 changed files with 42 additions and 9 deletions
+8
View File
@@ -5,6 +5,11 @@ type TelemetryLevel = "info" | "warn" | "error";
const MAX_MESSAGE_LENGTH = 2_048;
let telemetryEnabled = false;
let configuration: Promise<unknown> = Promise.resolve();
let frontendShuttingDown = false;
export function beginFrontendShutdown() {
frontendShuttingDown = true;
}
// Telemetry must never contain repository contents or identifying local data.
function sanitize(message: string): string {
@@ -42,6 +47,9 @@ function randomHex(bytes: number): string {
}
export async function tracedInvoke<T>(command: string, args?: Record<string, unknown>): Promise<T> {
if (frontendShuttingDown) {
throw new Error("Application is shutting down");
}
if (!telemetryEnabled) return invoke<T>(command, args);
const startedAtMs = Date.now();
const started = performance.now();