# Commit Message for SharedArrayBuffer Platform Exclusion

fix: eliminate SharedArrayBuffer checks on non-web platforms

* Add platform guard in AbsurdSqlDatabaseService to only initialize on web
* Change singleton pattern from eager to lazy instantiation
* Update worker import to use lazy singleton pattern
* Prevents absurd-sql initialization on Electron/Capacitor platforms
* Reduces console noise and memory footprint on desktop/mobile
* Maintains full web platform functionality and performance

Resolves SharedArrayBuffer-related console output on Electron platform
while preserving all web features and maintaining clean architecture.
This commit is contained in:
Matthew Raymer
2025-07-03 05:15:57 +00:00
parent 797db7069c
commit 292aceee75
21 changed files with 1044 additions and 151 deletions

88
src/main.electron.ts Normal file
View File

@@ -0,0 +1,88 @@
/**
* @file Electron Main Entry Point
* @author Matthew Raymer
*
* This file initializes the TimeSafari application for the Electron desktop platform.
* It provides the main entry point for the Electron renderer process and handles
* platform-specific initialization and configuration.
*
* Electron-Specific Features:
* - Desktop platform service initialization
* - Electron-specific error handling
* - Desktop UI optimizations
* - Native desktop integrations
*
* Integration Points:
* - Electron main process communication
* - Desktop file system access
* - Native OS integration
* - Platform-specific services
*
* Type Safety:
* - Uses ElectronPlatformService for desktop-specific functionality
* - Ensures type safety across Electron renderer and main processes
* - Maintains compatibility with Capacitor-Electron plugins
*
* @example
* // Electron renderer process initialization
* // Automatically detects Electron environment
* // Provides desktop-optimized user experience
*/
import { initializeApp } from "./main.common";
import { handleApiError } from "./services/api";
import { logger } from "./utils/logger";
logger.log("[Electron] Starting initialization");
logger.log("[Electron] Platform:", process.env.VITE_PLATFORM);
// Verify we're running in the correct platform environment
if (process.env.VITE_PLATFORM !== "electron") {
logger.warn(
"[Electron] Platform mismatch - expected 'electron', got:",
process.env.VITE_PLATFORM,
);
}
const app = initializeApp();
// Initialize API error handling for unhandled promise rejections
window.addEventListener("unhandledrejection", (event) => {
if (event.reason?.response) {
handleApiError(event.reason, event.reason.config?.url || "unknown");
}
});
// Electron-specific initialization
if (typeof window !== "undefined" && window.require) {
// We're in an Electron renderer process
logger.log("[Electron] Detected Electron renderer process");
// **CRITICAL FIX**: Disable any existing service worker that might be intercepting API calls
try {
if (navigator.serviceWorker?.getRegistrations) {
navigator.serviceWorker.getRegistrations().then(function(registrations) {
for(let registration of registrations) {
console.log("[Electron] Unregistering service worker:", registration.scope);
registration.unregister();
}
}).catch(error => {
console.log("[Electron] Failed to unregister service workers:", error);
});
}
} catch (error) {
console.log("[Electron] Service worker cleanup not available:", error);
}
// Add any Electron-specific initialization here
// For example, IPC communication setup, desktop-specific features, etc.
}
logger.log("[Electron] Mounting app");
app.mount("#app");
logger.log("[Electron] App mounted");
// Add Electron-specific cleanup on beforeunload
window.addEventListener("beforeunload", () => {
logger.log("[Electron] App unloading");
});