Skip to content

Commit 1e465ca

Browse files
committed
fix(desktop-runtime): 兼容 updater 缺失并修复打包后 wcdb 加载路径
- electron-updater 改为可选加载,缺失时自动禁用更新并记录原因 - 打包环境优先注入 WECHAT_TOOL_WCDB_API_DLL_PATH 指向 resources/backend/native/wcdb_api.dll - 启动后端进程 cwd 调整为 exe 所在目录,避免运行目录不一致 - wcdb_init 失败时附带 native log 摘要,提升故障排查信息 - package.json 显式保留 updater 相关依赖,避免构建裁剪导致模块缺失
1 parent 6fcbd48 commit 1e465ca

3 files changed

Lines changed: 59 additions & 9 deletions

File tree

desktop/package.json

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,29 @@
2525
},
2626
"files": [
2727
"src/**/*",
28-
"package.json"
28+
"package.json",
29+
{
30+
"from": "node_modules",
31+
"to": "node_modules",
32+
"filter": [
33+
"electron-updater/**/*",
34+
"builder-util-runtime/**/*",
35+
"debug/**/*",
36+
"ms/**/*",
37+
"sax/**/*",
38+
"js-yaml/**/*",
39+
"argparse/**/*",
40+
"lazy-val/**/*",
41+
"lodash.escaperegexp/**/*",
42+
"lodash.isequal/**/*",
43+
"tiny-typed-emitter/**/*",
44+
"fs-extra/**/*",
45+
"graceful-fs/**/*",
46+
"jsonfile/**/*",
47+
"universalify/**/*",
48+
"semver/**/*"
49+
]
50+
}
2951
],
3052
"extraResources": [
3153
{

desktop/src/main.cjs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ const {
88
dialog,
99
shell,
1010
} = require("electron");
11-
const { autoUpdater } = require("electron-updater");
11+
let autoUpdater = null;
12+
let autoUpdaterLoadError = null;
13+
try {
14+
({ autoUpdater } = require("electron-updater"));
15+
} catch (err) {
16+
autoUpdaterLoadError = err;
17+
}
1218
const { spawn, spawnSync } = require("child_process");
1319
const fs = require("fs");
1420
const http = require("http");
@@ -297,6 +303,12 @@ function isAutoUpdateEnabled() {
297303

298304
const forced = parseEnvBool(process.env.AUTO_UPDATE_ENABLED);
299305
let enabled = forced != null ? forced : !!app.isPackaged;
306+
if (enabled && !autoUpdater) {
307+
enabled = false;
308+
logMain(
309+
`[main] auto-update disabled: electron-updater unavailable: ${autoUpdaterLoadError?.message || "unknown error"}`
310+
);
311+
}
300312

301313
// In packaged builds electron-updater reads update config from app-update.yml.
302314
// If missing, treat auto-update as disabled to avoid noisy errors.
@@ -823,6 +835,10 @@ function getPackagedBackendPath() {
823835
return path.join(process.resourcesPath, "backend", "wechat-backend.exe");
824836
}
825837

838+
function getPackagedWcdbDllPath() {
839+
return path.join(process.resourcesPath, "backend", "native", "wcdb_api.dll");
840+
}
841+
826842
function startBackend() {
827843
if (backendProc) return backendProc;
828844

@@ -853,8 +869,17 @@ function startBackend() {
853869
`Packaged backend not found: ${backendExe}. Build it into desktop/resources/backend/wechat-backend.exe`
854870
);
855871
}
872+
const packagedWcdbDll = getPackagedWcdbDllPath();
873+
if (fs.existsSync(packagedWcdbDll)) {
874+
env.WECHAT_TOOL_WCDB_API_DLL_PATH = packagedWcdbDll;
875+
logMain(`[main] using packaged wcdb_api.dll: ${packagedWcdbDll}`);
876+
} else {
877+
logMain(`[main] packaged wcdb_api.dll not found: ${packagedWcdbDll}`);
878+
}
879+
880+
const backendCwd = path.dirname(backendExe);
856881
backendProc = spawn(backendExe, [], {
857-
cwd: env.WECHAT_TOOL_DATA_DIR,
882+
cwd: backendCwd,
858883
env,
859884
stdio: ["ignore", "pipe", "pipe"],
860885
windowsHide: true,

src/wechat_decrypt_tool/wcdb_realtime.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,9 @@ def _ensure_initialized() -> None:
253253
return
254254
rc = int(lib.wcdb_init())
255255
if rc != 0:
256-
raise WCDBRealtimeError(f"wcdb_init failed: {rc}")
256+
logs = get_native_logs(require_initialized=False)
257+
hint = f" logs={logs[:6]}" if logs else ""
258+
raise WCDBRealtimeError(f"wcdb_init failed: {rc}.{hint}")
257259
_initialized = True
258260

259261

@@ -315,11 +317,12 @@ def _call_out_error(fn, *args) -> None:
315317
pass
316318

317319

318-
def get_native_logs() -> list[str]:
319-
try:
320-
_ensure_initialized()
321-
except Exception:
322-
return []
320+
def get_native_logs(*, require_initialized: bool = True) -> list[str]:
321+
if require_initialized:
322+
try:
323+
_ensure_initialized()
324+
except Exception:
325+
return []
323326
lib = _load_wcdb_lib()
324327
out = ctypes.c_char_p()
325328
rc = int(lib.wcdb_get_logs(ctypes.byref(out)))

0 commit comments

Comments
 (0)