mirror of
https://github.com/LifeArchiveProject/WeChatDataAnalysis.git
synced 2026-06-18 15:54:08 +08:00
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 相关依赖,避免构建裁剪导致模块缺失
This commit is contained in:
+23
-1
@@ -25,7 +25,29 @@
|
||||
},
|
||||
"files": [
|
||||
"src/**/*",
|
||||
"package.json"
|
||||
"package.json",
|
||||
{
|
||||
"from": "node_modules",
|
||||
"to": "node_modules",
|
||||
"filter": [
|
||||
"electron-updater/**/*",
|
||||
"builder-util-runtime/**/*",
|
||||
"debug/**/*",
|
||||
"ms/**/*",
|
||||
"sax/**/*",
|
||||
"js-yaml/**/*",
|
||||
"argparse/**/*",
|
||||
"lazy-val/**/*",
|
||||
"lodash.escaperegexp/**/*",
|
||||
"lodash.isequal/**/*",
|
||||
"tiny-typed-emitter/**/*",
|
||||
"fs-extra/**/*",
|
||||
"graceful-fs/**/*",
|
||||
"jsonfile/**/*",
|
||||
"universalify/**/*",
|
||||
"semver/**/*"
|
||||
]
|
||||
}
|
||||
],
|
||||
"extraResources": [
|
||||
{
|
||||
|
||||
+27
-2
@@ -8,7 +8,13 @@ const {
|
||||
dialog,
|
||||
shell,
|
||||
} = require("electron");
|
||||
const { autoUpdater } = require("electron-updater");
|
||||
let autoUpdater = null;
|
||||
let autoUpdaterLoadError = null;
|
||||
try {
|
||||
({ autoUpdater } = require("electron-updater"));
|
||||
} catch (err) {
|
||||
autoUpdaterLoadError = err;
|
||||
}
|
||||
const { spawn, spawnSync } = require("child_process");
|
||||
const fs = require("fs");
|
||||
const http = require("http");
|
||||
@@ -297,6 +303,12 @@ function isAutoUpdateEnabled() {
|
||||
|
||||
const forced = parseEnvBool(process.env.AUTO_UPDATE_ENABLED);
|
||||
let enabled = forced != null ? forced : !!app.isPackaged;
|
||||
if (enabled && !autoUpdater) {
|
||||
enabled = false;
|
||||
logMain(
|
||||
`[main] auto-update disabled: electron-updater unavailable: ${autoUpdaterLoadError?.message || "unknown error"}`
|
||||
);
|
||||
}
|
||||
|
||||
// In packaged builds electron-updater reads update config from app-update.yml.
|
||||
// If missing, treat auto-update as disabled to avoid noisy errors.
|
||||
@@ -823,6 +835,10 @@ function getPackagedBackendPath() {
|
||||
return path.join(process.resourcesPath, "backend", "wechat-backend.exe");
|
||||
}
|
||||
|
||||
function getPackagedWcdbDllPath() {
|
||||
return path.join(process.resourcesPath, "backend", "native", "wcdb_api.dll");
|
||||
}
|
||||
|
||||
function startBackend() {
|
||||
if (backendProc) return backendProc;
|
||||
|
||||
@@ -853,8 +869,17 @@ function startBackend() {
|
||||
`Packaged backend not found: ${backendExe}. Build it into desktop/resources/backend/wechat-backend.exe`
|
||||
);
|
||||
}
|
||||
const packagedWcdbDll = getPackagedWcdbDllPath();
|
||||
if (fs.existsSync(packagedWcdbDll)) {
|
||||
env.WECHAT_TOOL_WCDB_API_DLL_PATH = packagedWcdbDll;
|
||||
logMain(`[main] using packaged wcdb_api.dll: ${packagedWcdbDll}`);
|
||||
} else {
|
||||
logMain(`[main] packaged wcdb_api.dll not found: ${packagedWcdbDll}`);
|
||||
}
|
||||
|
||||
const backendCwd = path.dirname(backendExe);
|
||||
backendProc = spawn(backendExe, [], {
|
||||
cwd: env.WECHAT_TOOL_DATA_DIR,
|
||||
cwd: backendCwd,
|
||||
env,
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
windowsHide: true,
|
||||
|
||||
@@ -253,7 +253,9 @@ def _ensure_initialized() -> None:
|
||||
return
|
||||
rc = int(lib.wcdb_init())
|
||||
if rc != 0:
|
||||
raise WCDBRealtimeError(f"wcdb_init failed: {rc}")
|
||||
logs = get_native_logs(require_initialized=False)
|
||||
hint = f" logs={logs[:6]}" if logs else ""
|
||||
raise WCDBRealtimeError(f"wcdb_init failed: {rc}.{hint}")
|
||||
_initialized = True
|
||||
|
||||
|
||||
@@ -315,11 +317,12 @@ def _call_out_error(fn, *args) -> None:
|
||||
pass
|
||||
|
||||
|
||||
def get_native_logs() -> list[str]:
|
||||
try:
|
||||
_ensure_initialized()
|
||||
except Exception:
|
||||
return []
|
||||
def get_native_logs(*, require_initialized: bool = True) -> list[str]:
|
||||
if require_initialized:
|
||||
try:
|
||||
_ensure_initialized()
|
||||
except Exception:
|
||||
return []
|
||||
lib = _load_wcdb_lib()
|
||||
out = ctypes.c_char_p()
|
||||
rc = int(lib.wcdb_get_logs(ctypes.byref(out)))
|
||||
|
||||
Reference in New Issue
Block a user