This commit is contained in:
chenqiang 2025-08-12 11:18:56 +08:00
parent 4f88bd9db1
commit a9559b4a81
3 changed files with 11 additions and 7 deletions

View File

@ -411,11 +411,11 @@ export async function initializeDatabase() {
console.log('数据库整体初始化成功');
global.initResult = true;
return true;
return { success: true };
} catch (error) {
console.error('数据库初始化失败:', error);
global.initResult = false;
return false;
return { success: false, error: error.message };
} finally {
global.isInitializing = false;
}

View File

@ -2,20 +2,21 @@
import path from 'path';
import fs from 'fs';
import { fileURLToPath } from 'url';
// 导入app模块
import { app } from 'electron';
// 获取当前文件所在目录
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// 获取项目根目录
const getProjectRoot = () => {
return path.resolve(__dirname, '../..');
// 获取用户数据目录(跨平台解决方案)
const getUserDataPath = () => {
return app.getPath('userData');
};
// 确保数据目录存在
const ensureDataDirExists = () => {
const projectRoot = getProjectRoot();
const dataDir = path.join(projectRoot, 'data');
const dataDir = path.join(getUserDataPath(), 'data');
if (!fs.existsSync(dataDir)) {
fs.mkdirSync(dataDir, { recursive: true });
}

View File

@ -179,6 +179,9 @@ async function setupApp() {
try {
console.log("应用启动 - 检查数据库初始化状态...");
// 等待应用就绪
await app.whenReady();
// 执行数据库迁移
await migrateDatabases();