import { initializeApp } from "./main.common"; import { logger } from "./utils/logger"; async function initializeSQLite() { try { // Wait for SQLite to be available in the main process let retries = 0; const maxRetries = 5; const retryDelay = 1000; // 1 second while (retries < maxRetries) { try { const isAvailable = await window.CapacitorSQLite.isAvailable(); if (isAvailable) { logger.info("[Electron] SQLite plugin bridge initialized successfully"); return true; } } catch (error) { logger.warn(`[Electron] SQLite not available yet (attempt ${retries + 1}/${maxRetries}):`, error); } retries++; if (retries < maxRetries) { await new Promise(resolve => setTimeout(resolve, retryDelay)); } } throw new Error("SQLite plugin not available after maximum retries"); } catch (error) { logger.error("[Electron] Failed to initialize SQLite plugin bridge:", error); throw error; } } const platform = process.env.VITE_PLATFORM; const pwa_enabled = process.env.VITE_PWA_ENABLED === "true"; logger.info("[Electron] Initializing app"); logger.info("[Electron] Platform:", { platform }); logger.info("[Electron] PWA enabled:", { pwa_enabled }); if (pwa_enabled) { logger.warn("[Electron] PWA is enabled, but not supported in electron"); } // Initialize app and SQLite const app = initializeApp(); // Initialize SQLite first, then mount the app initializeSQLite() .then(() => { logger.info("[Electron] SQLite initialized, mounting app..."); app.mount("#app"); }) .catch(error => { logger.error("[Electron] Failed to initialize app:", error); // Show error to user const errorDiv = document.createElement("div"); errorDiv.style.cssText = "position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: #ffebee; color: #c62828; padding: 20px; border-radius: 4px; text-align: center; max-width: 80%;"; errorDiv.innerHTML = `

Failed to Initialize Database

There was an error initializing the database. Please try restarting the application.

Error details: ${error.message}

`; document.body.appendChild(errorDiv); });