/** * Initialize Sentry error tracking if DSN is configured. * Captures errors and sends them to Sentry for monitoring and debugging. * @source */ constsentryDsn = (import.meta.env.VITE_SENTRY_DSNasstring) || undefined; if (sentryDsn) { Sentry.init({ dsn:sentryDsn, environment:import.meta.env.MODE, release:import.meta.env.VITE_APP_VERSION, integrations: [Sentry.browserTracingIntegration()], tracesSampleRate:0.1, beforeSend(event) { // Sanitize sensitive data if (event.request?.headers) { deleteevent.request.headers["Authorization"]; deleteevent.request.headers["Cookie"]; } if (event.extra) { deleteevent.extra.token; deleteevent.extra.apiKey; } returnevent; }, ignoreErrors: [ "ResizeObserver loop", "Non-Error promise rejection", "Network request failed", "Failed to fetch", ], }); }
/** * Install console interceptor to capture all console output for debugging. * Gated behind VITE_CAPTURE_CONSOLE environment flag. * Enabled by default in production, can be enabled in development via VITE_CAPTURE_CONSOLE=1. * @source */ letcleanupConsoleInterceptor: (() =>void) | null = null;
// Determine if console interceptor should be enabled constshouldCaptureConsole = import.meta.env.MODE === "production" || import.meta.env.VITE_CAPTURE_CONSOLE === "1";
if (shouldCaptureConsole) { try { cleanupConsoleInterceptor = installConsoleInterceptor(); if (import.meta.env.MODE !== "production") { console.debug( "[Renderer] 🔍 Console interceptor enabled via VITE_CAPTURE_CONSOLE", ); } } catch (error) { console.warn("[Renderer] ⚠️ Failed to install console interceptor:", error); } }
// Always register cleanup on unload window.addEventListener("unload", () => { if (cleanupConsoleInterceptor) { cleanupConsoleInterceptor(); } });
/** * Initialize the storage abstraction layer. * Sets up storage keys and initializes the backend storage mechanism (electron-store or localStorage). * This must complete before rendering the application to ensure all storage operations are ready. * @source */ try { awaitinitializeStorage(); console.info("[Renderer] ✅ Storage initialized successfully"); } catch (error) { console.error("[Renderer] ❌ Storage initialization failed:", error); // App continues with fallback in-memory storage if initialization fails }
/** * Initialize worker pools in the background (non-blocking). * Workers load in parallel with the UI rendering to improve performance. * Uses void operator to start async initialization without blocking React rendering. * * @source */ void (async () => { try { const { initializeWorkerPoolsAsync } = awaitimport("@/workers"); awaitinitializeWorkerPoolsAsync(); } catch (error) { console.warn( "[Renderer] ⚠️ Worker pool initialization failed (will fall back to main thread):", errorinstanceofError ? error.message : String(error), ); // Non-critical: if workers fail, the app falls back to main thread execution } })();
// Load and render the React application immediately after storage is ready // Workers will continue initializing in the background without blocking rendering import("@/App");
Description
Renderer process initialization script. Initializes Sentry error tracking and the application storage layer before rendering React.
Source