diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 14ad6e71..4a3002f8 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -478,7 +478,8 @@ "Bash(git commit -m \"$\\(cat <<''EOF''\nfeat\\(service-party-app\\): 添加 Windows 一键编译脚本\n\n添加 build-windows.bat 脚本,支持:\n- 检查 Node.js 和 Go 环境\n- 编译 TSS 子进程 \\(tss-party.exe\\)\n- 安装 npm 依赖\n- 编译 Electron 应用\n\n使用方法: 双击运行 build-windows.bat\n\n🤖 Generated with [Claude Code]\\(https://claude.com/claude-code\\)\n\nCo-Authored-By: Claude Opus 4.5 \nEOF\n\\)\")", "Bash(./node_modules/.bin/tsc:*)", "Bash(npm ls:*)", - "Bash(npm run build:win:*)" + "Bash(npm run build:win:*)", + "Bash(npm run clean:*)" ], "deny": [], "ask": [] diff --git a/backend/mpc-system/services/service-party-app/electron/modules/database.ts b/backend/mpc-system/services/service-party-app/electron/modules/database.ts index 41c60330..3af9add5 100644 --- a/backend/mpc-system/services/service-party-app/electron/modules/database.ts +++ b/backend/mpc-system/services/service-party-app/electron/modules/database.ts @@ -6,6 +6,23 @@ import initSqlJs from 'sql.js'; import type { Database as SqlJsDatabase, SqlJsStatic } from 'sql.js'; import { v4 as uuidv4 } from 'uuid'; +// ============================================================================= +// sql.js WASM 文件路径 +// ============================================================================= +function getSqlJsWasmPath(): string { + // 在开发环境中,WASM 文件在 node_modules 中 + // 在生产环境中,WASM 文件被解压到 app.asar.unpacked 目录 + const isDev = !app.isPackaged; + + if (isDev) { + // 开发环境: 使用 node_modules 中的文件 + return path.join(__dirname, '../../node_modules/sql.js/dist/sql-wasm.wasm'); + } else { + // 生产环境: 使用 asar.unpacked 中的文件 + return path.join(process.resourcesPath, 'app.asar.unpacked/node_modules/sql.js/dist/sql-wasm.wasm'); + } +} + // ============================================================================= // 数据库路径 // ============================================================================= @@ -89,8 +106,24 @@ export class DatabaseManager { * 初始化数据库 */ private async initialize(): Promise { + // 获取 WASM 文件路径 + const wasmPath = getSqlJsWasmPath(); + console.log('[Database] WASM path:', wasmPath); + console.log('[Database] WASM exists:', fs.existsSync(wasmPath)); + // 初始化 sql.js (加载 WASM) - this.SQL = await initSqlJs(); + // 如果 WASM 文件不存在,让 sql.js 自己处理(会尝试从 CDN 加载或使用内置版本) + const config: { locateFile?: (file: string) => string } = {}; + if (fs.existsSync(wasmPath)) { + config.locateFile = (file: string) => { + if (file === 'sql-wasm.wasm') { + return wasmPath; + } + return file; + }; + } + + this.SQL = await initSqlJs(config); // 如果数据库文件存在,加载它 if (fs.existsSync(this.dbPath)) { diff --git a/backend/mpc-system/services/service-party-app/package.json b/backend/mpc-system/services/service-party-app/package.json index b6d688ad..7d767c31 100644 --- a/backend/mpc-system/services/service-party-app/package.json +++ b/backend/mpc-system/services/service-party-app/package.json @@ -66,10 +66,15 @@ "buildResources": "resources", "output": "release" }, + "asar": true, + "asarUnpack": [ + "node_modules/sql.js/**/*" + ], "files": [ "dist/**/*", "dist-electron/**/*", - "wasm/**/*" + "wasm/**/*", + "node_modules/sql.js/**/*" ], "extraResources": [ {