From 4f4e09c3de1ae0c328c6d1e954d905b5f01fed70 Mon Sep 17 00:00:00 2001 From: hicccc77 <98377878+hicccc77@users.noreply.github.com> Date: Sun, 29 Mar 2026 16:07:09 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E9=87=8D=E8=A3=85=E5=90=8E=20openMessageCursor=20=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=20-3=20(no=20message=20db)=20=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 forceReopen() 方法:清空路径缓存后强制重新初始化账号连接 - openMessageCursor 在 result=-3 时自动触发 forceReopen 并重试一次 - 改善 -3 错误的提示文案,引导用户重新指定数据目录 修复 #591 --- electron/services/wcdbCore.ts | 49 +++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/electron/services/wcdbCore.ts b/electron/services/wcdbCore.ts index df535fa..4f0d97b 100644 --- a/electron/services/wcdbCore.ts +++ b/electron/services/wcdbCore.ts @@ -2596,13 +2596,34 @@ export class WcdbCore { } } + /** + * 强制重新打开账号连接(绕过路径缓存),用于微信重装后消息数据库刷新失败时的自动恢复。 + * 返回重新打开是否成功。 + */ + private async forceReopen(): Promise { + if (!this.currentPath || !this.currentKey || !this.currentWxid) return false + const path = this.currentPath + const key = this.currentKey + const wxid = this.currentWxid + this.writeLog('forceReopen: clearing cached handle and reopening...', true) + // 清空缓存状态,让 open() 真正重新打开 + try { this.wcdbShutdown() } catch { } + this.handle = null + this.currentPath = null + this.currentKey = null + this.currentWxid = null + this.currentDbStoragePath = null + this.initialized = false + return this.open(path, key, wxid) + } + async openMessageCursor(sessionId: string, batchSize: number, ascending: boolean, beginTimestamp: number, endTimestamp: number): Promise<{ success: boolean; cursor?: number; error?: string }> { if (!this.ensureReady()) { return { success: false, error: 'WCDB 未连接' } } try { const outCursor = [0] - const result = this.wcdbOpenMessageCursor( + let result = this.wcdbOpenMessageCursor( this.handle, sessionId, batchSize, @@ -2611,13 +2632,37 @@ export class WcdbCore { endTimestamp, outCursor ) + // result=-3 表示 WCDB_STATUS_NO_MESSAGE_DB:消息数据库缓存为空(常见于微信重装后) + // 自动强制重连并重试一次 + if (result === -3 && outCursor[0] <= 0) { + this.writeLog('openMessageCursor: result=-3 (no message db), attempting forceReopen...', true) + const reopened = await this.forceReopen() + if (reopened && this.handle !== null) { + outCursor[0] = 0 + result = this.wcdbOpenMessageCursor( + this.handle, + sessionId, + batchSize, + ascending ? 1 : 0, + beginTimestamp, + endTimestamp, + outCursor + ) + this.writeLog(`openMessageCursor retry after forceReopen: result=${result} cursor=${outCursor[0]}`, true) + } else { + this.writeLog('openMessageCursor forceReopen failed, giving up', true) + } + } if (result !== 0 || outCursor[0] <= 0) { await this.printLogs(true) this.writeLog( `openMessageCursor failed: sessionId=${sessionId} batchSize=${batchSize} ascending=${ascending ? 1 : 0} begin=${beginTimestamp} end=${endTimestamp} result=${result} cursor=${outCursor[0]}`, true ) - return { success: false, error: `创建游标失败: ${result},请查看日志` } + const hint = result === -3 + ? `创建游标失败: ${result}(消息数据库未找到)。如果你最近重装过微信,请尝试重新指定数据目录后重试` + : `创建游标失败: ${result},请查看日志` + return { success: false, error: hint } } return { success: true, cursor: outCursor[0] } } catch (e) { From b64525487e0059df657721c326e4b864932ff9be Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 1 Apr 2026 05:11:30 +0000 Subject: [PATCH 2/2] chore(deps-dev): bump @xmldom/xmldom Bumps the npm_and_yarn group with 1 update in the / directory: [@xmldom/xmldom](https://github.com/xmldom/xmldom). Updates `@xmldom/xmldom` from 0.8.11 to 0.8.12 - [Release notes](https://github.com/xmldom/xmldom/releases) - [Changelog](https://github.com/xmldom/xmldom/blob/master/CHANGELOG.md) - [Commits](https://github.com/xmldom/xmldom/compare/0.8.11...0.8.12) --- updated-dependencies: - dependency-name: "@xmldom/xmldom" dependency-version: 0.8.12 dependency-type: indirect dependency-group: npm_and_yarn ... Signed-off-by: dependabot[bot] --- package-lock.json | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 95ea5a4..b057112 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3040,9 +3040,9 @@ } }, "node_modules/@xmldom/xmldom": { - "version": "0.8.11", - "resolved": "https://registry.npmmirror.com/@xmldom/xmldom/-/xmldom-0.8.11.tgz", - "integrity": "sha512-cQzWCtO6C8TQiYl1ruKNn2U6Ao4o4WBBcbL61yJl84x+j5sOWWFU9X7DpND8XZG3daDppSsigMdfAIl2upQBRw==", + "version": "0.8.12", + "resolved": "https://registry.npmmirror.com/@xmldom/xmldom/-/xmldom-0.8.12.tgz", + "integrity": "sha512-9k/gHF6n/pAi/9tqr3m3aqkuiNosYTurLLUtc7xQ9sxB/wm7WPygCv8GYa6mS0fLJEHhqMC1ATYhz++U/lRHqg==", "dev": true, "license": "MIT", "engines": { @@ -9072,6 +9072,9 @@ "sherpa-onnx-win-x64": "^1.12.23" } }, + "node_modules/sherpa-onnx-node/node_modules/sherpa-onnx-darwin-x64": { + "optional": true + }, "node_modules/sherpa-onnx-win-ia32": { "version": "1.12.23", "resolved": "https://registry.npmmirror.com/sherpa-onnx-win-ia32/-/sherpa-onnx-win-ia32-1.12.23.tgz",