|
|
@ -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, |
|
|
|
); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|