fix: 完善交互、知识库目录与 Windows 运行库提示

This commit is contained in:
电摇小子
2026-08-11 02:59:30 +08:00
parent 1edea7d3cc
commit 7ec0e4f539
16 changed files with 283 additions and 20 deletions
+23 -2
View File
@@ -97,7 +97,7 @@ import { agentHubService } from './services/agent-hub-service'
import { appLogger } from './app-logger'
import type { AppLogEntry } from '../shared/app-log'
import { appUpdateService } from './services/app-update-service'
import { clearCache, getCacheSummary } from './services/cache-service'
import { clearCache, getCacheSummary, openKnowledgeDirectory } from './services/cache-service'
import type { CacheClearScope } from './services/cache-service'
import { configureRecallArchive, RecallArchiveMonitor } from './services/recall-archive-service'
import { VideoAssetService } from './video-asset-service'
@@ -109,6 +109,10 @@ import { VoiceBatchService } from './voice-pipeline/voice-batch-service'
import type { VoiceBatchRequest, VoiceMessageReference } from '../shared/voice-recognition'
import type { AiSearchPipelineRequest } from '../shared/ai-search'
import type { KnowledgeSearchIpcRequest, KnowledgeSearchIpcResult } from '../shared/knowledge'
import {
isWindowsVcRuntimeMissingError,
WINDOWS_VC_RUNTIME_ERROR_MESSAGE
} from '../shared/windows-runtime'
import { KnowledgeSearchService } from './knowledge/knowledge-search-service'
import { AiSearchPipelineService } from './services/ai-search-pipeline-service'
@@ -506,6 +510,13 @@ app.whenReady().then(async () => {
wcdbBootstrapPromise = bootstrapWcdbNativeAsync().then(() => {
console.log('[WCDB4] async bootstrap complete')
})
void wcdbBootstrapPromise.catch((error) => {
appLogger.write({
level: 'error',
scope: 'wcdb-bootstrap',
message: error instanceof Error ? error.message : String(error)
})
})
// 设置应用程序用户模型 ID
electronApp.setAppUserModelId('com.wechatexplorer.app')
@@ -529,6 +540,7 @@ app.whenReady().then(async () => {
ipcMain.handle('app-update:download', () => appUpdateService.download())
ipcMain.handle('app-update:install', () => appUpdateService.install())
ipcMain.handle('cache:getSummary', () => getCacheSummary())
ipcMain.handle('cache:openKnowledgeDirectory', () => openKnowledgeDirectory())
ipcMain.handle('cache:clear', async (_, scope: CacheClearScope) => {
const allowedScopes: CacheClearScope[] = ['bootstrap', 'electron', 'knowledge', 'all']
if (!allowedScopes.includes(scope)) return getCacheSummary()
@@ -625,7 +637,16 @@ app.whenReady().then(async () => {
return { success: true, monitoring }
} catch (error) {
console.error('Failed to init DB:', error)
return { success: false, error: error instanceof Error ? error.message : String(error) }
const detail = error instanceof Error ? error.message : String(error)
if (isWindowsVcRuntimeMissingError(detail, process.platform)) {
return {
success: false,
code: 'VC_RUNTIME_MISSING',
error: WINDOWS_VC_RUNTIME_ERROR_MESSAGE,
monitoring: false
}
}
return { success: false, error: detail }
} finally {
dbInitInFlight = null
}
+13 -2
View File
@@ -1,4 +1,4 @@
import { app, session } from 'electron'
import { app, session, shell } from 'electron'
import fs from 'fs-extra'
import path from 'path'
import { clearBootstrapCache } from './bootstrap-cache'
@@ -62,7 +62,8 @@ export function getCacheSummary(): CacheSummary {
{
id: 'knowledge',
label: '本地知识库索引',
description: '为问问微信建立的所有账号本地检索索引。清理后需手动重新建立,不影响微信原始数据。',
description:
'为问问微信建立的所有账号本地检索索引。清理后需手动重新建立,不影响微信原始数据。',
...knowledge
}
]
@@ -90,3 +91,13 @@ export async function clearCache(
}
return getCacheSummary()
}
export async function openKnowledgeDirectory(): Promise<{ success: boolean; error?: string }> {
try {
await fs.ensureDir(KNOWLEDGE_CACHE_DIR)
const error = await shell.openPath(KNOWLEDGE_CACHE_DIR)
return error ? { success: false, error } : { success: true }
} catch (error) {
return { success: false, error: error instanceof Error ? error.message : String(error) }
}
}
+6
View File
@@ -9,6 +9,10 @@ import type {
DatabaseKeyValidationCode,
DatabaseKeyValidationResult
} from '../../shared/database-key'
import {
isWindowsVcRuntimeMissingError,
WINDOWS_VC_RUNTIME_ERROR_MESSAGE
} from '../../shared/windows-runtime'
import { mergeRecallArchiveMessages, recordRecallArchiveMessages } from './recall-archive-service'
import type { ExportImageQuality } from '../../shared/image-quality'
@@ -675,11 +679,13 @@ const DATABASE_KEY_ERROR_MESSAGES: Record<DatabaseKeyValidationCode, string> = {
ACCOUNT_MISMATCH: '密钥与当前账号不匹配',
ROOT_UNAVAILABLE: '当前数据库目录不可用',
DATABASE_FILE_MISSING: '数据库文件缺失',
VC_RUNTIME_MISSING: WINDOWS_VC_RUNTIME_ERROR_MESSAGE,
UNKNOWN_VALIDATION_ERROR: '未知验证错误'
}
function mapConnectionError(detail: string): DatabaseKeyValidationCode {
const normalized = detail.toLowerCase()
if (isWindowsVcRuntimeMissingError(detail, process.platform)) return 'VC_RUNTIME_MISSING'
if (normalized.includes('-1005') || normalized.includes('不匹配')) return 'ACCOUNT_MISMATCH'
if (normalized.includes('session.db') || normalized.includes('数据库文件')) {
return 'DATABASE_FILE_MISSING'