From e12caa16a67d99b7e12170be6a9cc57ec046b9d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9C=E5=8C=97=E5=B0=98?= <2678115663@qq.com> Date: Sat, 18 Apr 2026 17:42:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(windows):=20=E4=BF=AE=E5=A4=8D=20Electron?= =?UTF-8?q?=20=E5=8A=A0=E8=BD=BD=20WCDB=20=E8=BF=90=E8=A1=8C=E6=97=B6?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=9A=84=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/services/wcdbService.ts | 4 +- package.json | 14 +++---- scripts/prepare-electron-runtime.cjs | 57 ++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 scripts/prepare-electron-runtime.cjs diff --git a/electron/services/wcdbService.ts b/electron/services/wcdbService.ts index d4c77ef..2f1957f 100644 --- a/electron/services/wcdbService.ts +++ b/electron/services/wcdbService.ts @@ -25,9 +25,7 @@ export class WcdbService { private logEnabled = false private monitorListener: ((type: string, json: string) => void) | null = null - constructor() { - this.initWorker() - } + constructor() {} /** * 初始化 Worker 线程 diff --git a/package.json b/package.json index 2aac96c..dfc882d 100644 --- a/package.json +++ b/package.json @@ -13,13 +13,13 @@ }, "//": "二改不应改变此处的作者与应用信息", "scripts": { - "postinstall": "electron-builder install-app-deps", + "postinstall": "electron-builder install-app-deps && node scripts/prepare-electron-runtime.cjs", "rebuild": "electron-rebuild", - "dev": "vite", + "dev": "node scripts/prepare-electron-runtime.cjs && vite", "typecheck": "tsc --noEmit", "build": "tsc && vite build && electron-builder", "preview": "vite preview", - "electron:dev": "vite --mode electron", + "electron:dev": "node scripts/prepare-electron-runtime.cjs && vite --mode electron", "electron:build": "npm run build" }, "dependencies": { @@ -105,19 +105,19 @@ "icon": "public/icon.ico", "extraFiles": [ { - "from": "resources/msvcp140.dll", + "from": "resources/runtime/win32/msvcp140.dll", "to": "." }, { - "from": "resources/msvcp140_1.dll", + "from": "resources/runtime/win32/msvcp140_1.dll", "to": "." }, { - "from": "resources/vcruntime140.dll", + "from": "resources/runtime/win32/vcruntime140.dll", "to": "." }, { - "from": "resources/vcruntime140_1.dll", + "from": "resources/runtime/win32/vcruntime140_1.dll", "to": "." } ] diff --git a/scripts/prepare-electron-runtime.cjs b/scripts/prepare-electron-runtime.cjs new file mode 100644 index 0000000..1230732 --- /dev/null +++ b/scripts/prepare-electron-runtime.cjs @@ -0,0 +1,57 @@ +const fs = require('node:fs'); +const path = require('node:path'); + +const runtimeNames = [ + 'msvcp140.dll', + 'msvcp140_1.dll', + 'vcruntime140.dll', + 'vcruntime140_1.dll', +]; + +function copyIfDifferent(sourcePath, targetPath) { + const source = fs.statSync(sourcePath); + const targetExists = fs.existsSync(targetPath); + + if (targetExists) { + const target = fs.statSync(targetPath); + if (target.size === source.size && target.mtimeMs >= source.mtimeMs) { + return false; + } + } + + fs.copyFileSync(sourcePath, targetPath); + return true; +} + +function main() { + if (process.platform !== 'win32') { + return; + } + + const projectRoot = path.resolve(__dirname, '..'); + const sourceDir = path.join(projectRoot, 'resources', 'runtime', 'win32'); + const targetDir = path.join(projectRoot, 'node_modules', 'electron', 'dist'); + + if (!fs.existsSync(sourceDir) || !fs.existsSync(targetDir)) { + return; + } + + let copiedCount = 0; + + for (const name of runtimeNames) { + const sourcePath = path.join(sourceDir, name); + const targetPath = path.join(targetDir, name); + if (!fs.existsSync(sourcePath)) { + continue; + } + if (copyIfDifferent(sourcePath, targetPath)) { + copiedCount += 1; + } + } + + if (copiedCount > 0) { + console.log(`[prepare-electron-runtime] synced ${copiedCount} runtime DLL(s) to ${targetDir}`); + } +} + +main();