diff --git a/src/ipc/database/handler.ts b/src/ipc/database/handler.ts index 5dbe8db..5c627a8 100644 --- a/src/ipc/database/handler.ts +++ b/src/ipc/database/handler.ts @@ -14,6 +14,25 @@ function getDbWithWal(dbPath: string, options: Database.Options = {}): Database. return db; } +/** + * Initializes the database and ensures WAL mode is enabled. + * Should be called on application startup. + */ +export function initDatabase(): void { + try { + const dbPaths = getAntigravityDbPaths(); + if (dbPaths.length === 0) { + return; + } + + const db = getDatabaseConnection(); + db.close(); + logger.info('Database initialized and verified (WAL mode)'); + } catch (error) { + logger.error('Failed to initialize database on startup', error); + } +} + /** * Ensures that the database file exists. * @param dbPath {string} The path to the database file. diff --git a/src/main.ts b/src/main.ts index 423b45d..18b9622 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -import { app, BrowserWindow, Tray, Menu, nativeImage } from 'electron'; +import { app, BrowserWindow } from 'electron'; import path from 'path'; import fs from 'fs'; @@ -9,6 +9,7 @@ import { IPC_CHANNELS } from './constants'; import { updateElectronApp, UpdateSourceType } from 'update-electron-app'; import { logger } from './utils/logger'; import { CloudAccountRepo } from './ipc/database/cloudHandler'; +import { initDatabase } from './ipc/database/handler'; import { CloudMonitorService } from './services/CloudMonitorService'; // Static Imports to fix Bundle Resolution Errors @@ -232,6 +233,9 @@ app // We might want to exit here or show a dialog, but for now we proceed // though functionality will be broken. } + + logger.info('Step: Initialize Antigravity DB (WAL Mode)'); + initDatabase(); }) .then(() => { logger.info('Step: setupORPC');