From fd0db6e306bb198d301bef424efbb2ab9a3087a2 Mon Sep 17 00:00:00 2001 From: cc <98377878+hicccc77@users.noreply.github.com> Date: Mon, 4 May 2026 18:33:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=81=94=E7=B3=BB=E4=BA=BA?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=AF=BC=E5=87=BA=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/exportWorker.ts | 10 +++++++++- electron/services/chatService.ts | 18 ++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/electron/exportWorker.ts b/electron/exportWorker.ts index c8ab220..60f896e 100644 --- a/electron/exportWorker.ts +++ b/electron/exportWorker.ts @@ -166,7 +166,15 @@ async function run() { let result: any if (config.mode === 'contacts') { - const { contactExportService } = await import('./services/contactExportService') + const [{ contactExportService }, { chatService }] = await Promise.all([ + import('./services/contactExportService'), + import('./services/chatService') + ]) + chatService.setRuntimeConfig({ + dbPath: config.dbPath, + decryptKey: config.decryptKey, + myWxid: config.myWxid + }) result = await contactExportService.exportContacts( String(config.outputDir || ''), config.options || {} diff --git a/electron/services/chatService.ts b/electron/services/chatService.ts index 93ee1e9..c436218 100644 --- a/electron/services/chatService.ts +++ b/electron/services/chatService.ts @@ -344,6 +344,7 @@ const FRIEND_EXCLUDE_USERNAMES = new Set(['medianote', 'floatbottle', 'qmessage' class ChatService { private configService: ConfigService + private runtimeConfig?: { dbPath?: string; decryptKey?: string; myWxid?: string } private connected = false private readonly dbMonitorListeners = new Set<(type: string, json: string) => void>() private messageCursors: Map = new Map() @@ -452,6 +453,10 @@ class ChatService { this.voiceTranscriptCache = new LRUCache(1000) // 最多缓存1000条转写记录 } + setRuntimeConfig(config: { dbPath?: string; decryptKey?: string; myWxid?: string }): void { + this.runtimeConfig = config + } + /** * 清理账号目录名 */ @@ -537,12 +542,9 @@ class ChatService { */ async connect(): Promise<{ success: boolean; error?: string }> { try { - if (this.connected && wcdbService.isReady()) { - return { success: true } - } - const wxid = this.configService.get('myWxid') - const dbPath = this.configService.get('dbPath') - const decryptKey = this.configService.get('decryptKey') + const wxid = String(this.runtimeConfig?.myWxid || this.configService.get('myWxid') || '').trim() + const dbPath = String(this.runtimeConfig?.dbPath || this.configService.get('dbPath') || '').trim() + const decryptKey = String(this.runtimeConfig?.decryptKey || this.configService.get('decryptKey') || '').trim() if (!wxid) { return { success: false, error: '请先在设置页面配置微信ID' } } @@ -553,6 +555,10 @@ class ChatService { return { success: false, error: '请先在设置页面配置解密密钥' } } + if (this.connected && wcdbService.isReady()) { + return { success: true } + } + // 使用 ConfigService 统一解析账号目录 const accountDir = this.configService.getAccountDir(dbPath, wxid) if (!accountDir) {