mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-04-22 07:26:46 +00:00
fix(windows): 修复 Electron 加载 WCDB 运行时导致的崩溃
This commit is contained in:
@@ -25,9 +25,7 @@ export class WcdbService {
|
|||||||
private logEnabled = false
|
private logEnabled = false
|
||||||
private monitorListener: ((type: string, json: string) => void) | null = null
|
private monitorListener: ((type: string, json: string) => void) | null = null
|
||||||
|
|
||||||
constructor() {
|
constructor() {}
|
||||||
this.initWorker()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化 Worker 线程
|
* 初始化 Worker 线程
|
||||||
|
|||||||
14
package.json
14
package.json
@@ -13,13 +13,13 @@
|
|||||||
},
|
},
|
||||||
"//": "二改不应改变此处的作者与应用信息",
|
"//": "二改不应改变此处的作者与应用信息",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"postinstall": "electron-builder install-app-deps",
|
"postinstall": "electron-builder install-app-deps && node scripts/prepare-electron-runtime.cjs",
|
||||||
"rebuild": "electron-rebuild",
|
"rebuild": "electron-rebuild",
|
||||||
"dev": "vite",
|
"dev": "node scripts/prepare-electron-runtime.cjs && vite",
|
||||||
"typecheck": "tsc --noEmit",
|
"typecheck": "tsc --noEmit",
|
||||||
"build": "tsc && vite build && electron-builder",
|
"build": "tsc && vite build && electron-builder",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"electron:dev": "vite --mode electron",
|
"electron:dev": "node scripts/prepare-electron-runtime.cjs && vite --mode electron",
|
||||||
"electron:build": "npm run build"
|
"electron:build": "npm run build"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -105,19 +105,19 @@
|
|||||||
"icon": "public/icon.ico",
|
"icon": "public/icon.ico",
|
||||||
"extraFiles": [
|
"extraFiles": [
|
||||||
{
|
{
|
||||||
"from": "resources/msvcp140.dll",
|
"from": "resources/runtime/win32/msvcp140.dll",
|
||||||
"to": "."
|
"to": "."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"from": "resources/msvcp140_1.dll",
|
"from": "resources/runtime/win32/msvcp140_1.dll",
|
||||||
"to": "."
|
"to": "."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"from": "resources/vcruntime140.dll",
|
"from": "resources/runtime/win32/vcruntime140.dll",
|
||||||
"to": "."
|
"to": "."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"from": "resources/vcruntime140_1.dll",
|
"from": "resources/runtime/win32/vcruntime140_1.dll",
|
||||||
"to": "."
|
"to": "."
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
57
scripts/prepare-electron-runtime.cjs
Normal file
57
scripts/prepare-electron-runtime.cjs
Normal file
@@ -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();
|
||||||
Reference in New Issue
Block a user