diff --git a/src/App.vue b/src/App.vue index f66ffafe..371c4ea7 100644 --- a/src/App.vue +++ b/src/App.vue @@ -459,9 +459,10 @@ export default class App extends Vue { return true; } - const serverSubscription = typeof subscription === "object" && subscription !== null - ? { ...subscription } - : {}; + const serverSubscription = + typeof subscription === "object" && subscription !== null + ? { ...subscription } + : {}; if (!allGoingOff) { serverSubscription["notifyType"] = notification.title; logger.log( diff --git a/src/electron/main.ts b/src/electron/main.ts index 54f251c3..15fe43d1 100644 --- a/src/electron/main.ts +++ b/src/electron/main.ts @@ -1,35 +1,59 @@ import { app, BrowserWindow, ipcMain } from "electron"; import path from "path"; import fs from "fs"; -import { CapacitorSQLiteElectron } from '@capacitor-community/sqlite/electron/dist/plugin'; - -// Initialize SQLite plugin for Electron -const sqlitePlugin = new CapacitorSQLiteElectron(); - -// Set up IPC handler for SQLite -ipcMain.handle('capacitor-sqlite', async (_event, ...args) => { - return sqlitePlugin.handle(_event, ...args); -}); - -// Initialize SQLite when app is ready -app.whenReady().then(() => { - createWindow(); -}); +import { CapacitorSQLiteElectron } from "@capacitor-community/sqlite/electron/dist/plugin"; // Simple logger implementation const logger = { // eslint-disable-next-line no-console - log: (...args: unknown[]) => console.log(...args), + log: (...args: unknown[]) => console.log("[Main]", ...args), // eslint-disable-next-line no-console - error: (...args: unknown[]) => console.error(...args), + error: (...args: unknown[]) => console.error("[Main]", ...args), // eslint-disable-next-line no-console - info: (...args: unknown[]) => console.info(...args), + info: (...args: unknown[]) => console.info("[Main]", ...args), // eslint-disable-next-line no-console - warn: (...args: unknown[]) => console.warn(...args), + warn: (...args: unknown[]) => console.warn("[Main]", ...args), // eslint-disable-next-line no-console - debug: (...args: unknown[]) => console.debug(...args), + debug: (...args: unknown[]) => console.debug("[Main]", ...args), }; +// Initialize SQLite plugin for Electron +let sqlitePlugin: CapacitorSQLiteElectron | null = null; + +try { + logger.info("Initializing SQLite plugin..."); + sqlitePlugin = new CapacitorSQLiteElectron(); + logger.info("SQLite plugin initialized successfully"); +} catch (error) { + logger.error("Failed to initialize SQLite plugin:", error); + throw error; +} + +// Set up IPC handler for SQLite +ipcMain.handle("capacitor-sqlite", async (_event, ...args) => { + if (!sqlitePlugin) { + const error = new Error("SQLite plugin not initialized"); + logger.error(error); + throw error; + } + + try { + logger.debug("Handling SQLite request:", args); + const result = await sqlitePlugin.handle(_event, ...args); + logger.debug("SQLite request completed successfully"); + return result; + } catch (error) { + logger.error("SQLite request failed:", error); + throw error; + } +}); + +// Initialize app when ready +app.whenReady().then(() => { + logger.info("App is ready, creating window..."); + createWindow(); +}); + // Check if running in dev mode const isDev = process.argv.includes("--inspect"); @@ -38,7 +62,7 @@ function createWindow(): void { const preloadPath = app.isPackaged ? path.join(process.resourcesPath, "preload.js") : path.join(__dirname, "preload.js"); - + logger.log("[Electron] Preload path:", preloadPath); logger.log("[Electron] Preload exists:", fs.existsSync(preloadPath)); @@ -133,11 +157,15 @@ function createWindow(): void { if (app.isPackaged) { // In production, files are inside the asar archive or extraResources indexPath = path.join(process.resourcesPath, "www", "index.html"); - logger.info("[Electron] App is packaged. Using process.resourcesPath for index.html"); + logger.info( + "[Electron] App is packaged. Using process.resourcesPath for index.html", + ); } else { // In dev, use the local path indexPath = path.resolve(__dirname, "www", "index.html"); - logger.info("[Electron] App is not packaged. Using __dirname for index.html"); + logger.info( + "[Electron] App is not packaged. Using __dirname for index.html", + ); } logger.info("[Electron] Resolved index.html path:", indexPath); @@ -150,7 +178,9 @@ function createWindow(): void { // Removed fs.existsSync check to allow Electron to attempt loading regardless - logger.info("[Electron] Attempting to load index.html via mainWindow.loadFile"); + logger.info( + "[Electron] Attempting to load index.html via mainWindow.loadFile", + ); mainWindow .loadFile(indexPath) .then(() => { @@ -165,9 +195,14 @@ function createWindow(): void { logger.error("[Electron] Attempted path:", indexPath); try { const exists = fs.existsSync(indexPath); - logger.error(`[Electron] fs.existsSync after loadFile error: ${exists}`); + logger.error( + `[Electron] fs.existsSync after loadFile error: ${exists}`, + ); } catch (e) { - logger.error("[Electron] Error checking fs.existsSync after loadFile error:", e); + logger.error( + "[Electron] Error checking fs.existsSync after loadFile error:", + e, + ); } }); diff --git a/src/main.electron.ts b/src/main.electron.ts index 5898f928..be82a7b7 100644 --- a/src/main.electron.ts +++ b/src/main.electron.ts @@ -1,16 +1,16 @@ import { initializeApp } from "./main.common"; import { logger } from "./utils/logger"; -import { Capacitor } from '@capacitor/core'; -import { CapacitorSQLite } from '@capacitor-community/sqlite'; +import { Capacitor } from "@capacitor/core"; +import { CapacitorSQLite } from "@capacitor-community/sqlite"; // Initialize Capacitor for Electron -Object.defineProperty(Capacitor, 'isNativePlatform', { +Object.defineProperty(Capacitor, "isNativePlatform", { get: () => true, - configurable: true + configurable: true, }); // Initialize SQLite plugin for Electron -if (typeof window !== 'undefined') { +if (typeof window !== "undefined") { // Register the plugin globally window.CapacitorSQLite = CapacitorSQLite; logger.info("[Electron] SQLite plugin initialized in native mode"); diff --git a/src/services/platforms/ElectronPlatformService.ts b/src/services/platforms/ElectronPlatformService.ts index dc0582b1..48c2fb91 100644 --- a/src/services/platforms/ElectronPlatformService.ts +++ b/src/services/platforms/ElectronPlatformService.ts @@ -51,7 +51,7 @@ export class ElectronPlatformService implements PlatformService { false, "no-encryption", 1, - true // Use native implementation + true, // Use native implementation ); await this.db.open(); diff --git a/vite.config.electron.mts b/vite.config.electron.mts index 14d5c8be..b9b8eea7 100644 --- a/vite.config.electron.mts +++ b/vite.config.electron.mts @@ -24,7 +24,12 @@ export default defineConfig(async ({ mode }) => { main: path.resolve(__dirname, 'src/electron/main.ts'), preload: path.resolve(__dirname, 'src/electron/preload.js'), }, - external: ['electron'], + external: [ + 'electron', + '@capacitor-community/sqlite', + '@capacitor-community/sqlite/electron', + 'better-sqlite3-multiple-ciphers' + ], output: { format: 'cjs', entryFileNames: '[name].js',