fix: enable WAL mode and force initialization on startup

This commit is contained in:
Draculabo committed 2026-01-25 03:53:13 +08:00
1 parent 47be175e27
commit 1bce5d331d
2 files changed
+24 -1

No files matched your search

+19
View File
@@ -14,6 +14,25 @@ function getDbWithWal(dbPath: string, options: Database.Options = {}): Database.
return db; 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. * Ensures that the database file exists.
* @param dbPath {string} The path to the database file. * @param dbPath {string} The path to the database file.
+5 -1
View File
@@ -1,4 +1,4 @@
import { app, BrowserWindow, Tray, Menu, nativeImage } from 'electron'; import { app, BrowserWindow } from 'electron';
import path from 'path'; import path from 'path';
import fs from 'fs'; import fs from 'fs';
@@ -9,6 +9,7 @@ import { IPC_CHANNELS } from './constants';
import { updateElectronApp, UpdateSourceType } from 'update-electron-app'; import { updateElectronApp, UpdateSourceType } from 'update-electron-app';
import { logger } from './utils/logger'; import { logger } from './utils/logger';
import { CloudAccountRepo } from './ipc/database/cloudHandler'; import { CloudAccountRepo } from './ipc/database/cloudHandler';
import { initDatabase } from './ipc/database/handler';
import { CloudMonitorService } from './services/CloudMonitorService'; import { CloudMonitorService } from './services/CloudMonitorService';
// Static Imports to fix Bundle Resolution Errors // 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 // We might want to exit here or show a dialog, but for now we proceed
// though functionality will be broken. // though functionality will be broken.
} }
logger.info('Step: Initialize Antigravity DB (WAL Mode)');
initDatabase();
}) })
.then(() => { .then(() => {
logger.info('Step: setupORPC'); logger.info('Step: setupORPC');