From d47166e6f9bdeb2947bdc68a505e9091b56fde2a Mon Sep 17 00:00:00 2001 From: xuncha <1658671838@qq.com> Date: Sat, 31 Jan 2026 15:39:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=89=93=E5=8C=85=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/VoiceTranscribeDialog.tsx | 2 +- src/pages/ChatPage.tsx | 49 ++++++++++++++++-------- src/pages/ContactsPage.tsx | 12 +++--- src/pages/ExportPage.tsx | 2 +- src/pages/SettingsPage.tsx | 6 +-- src/pages/SnsPage.tsx | 6 +-- src/pages/WelcomePage.tsx | 4 +- 7 files changed, 50 insertions(+), 31 deletions(-) diff --git a/src/components/VoiceTranscribeDialog.tsx b/src/components/VoiceTranscribeDialog.tsx index c8626ef..ff58e1a 100644 --- a/src/components/VoiceTranscribeDialog.tsx +++ b/src/components/VoiceTranscribeDialog.tsx @@ -23,7 +23,7 @@ export const VoiceTranscribeDialog: React.FC = ({ return } - const removeListener = window.electronAPI.whisper.onDownloadProgress((payload) => { + const removeListener = window.electronAPI.whisper.onDownloadProgress((payload: { modelName: string; downloadedBytes: number; totalBytes?: number; percent?: number }) => { if (payload.percent !== undefined) { setDownloadProgress(payload.percent) } diff --git a/src/pages/ChatPage.tsx b/src/pages/ChatPage.tsx index 257e7cd..2b12197 100644 --- a/src/pages/ChatPage.tsx +++ b/src/pages/ChatPage.tsx @@ -491,7 +491,11 @@ function ChatPage(_props: ChatPageProps) { await new Promise(resolve => setTimeout(resolve, 0)) const dllStart = performance.now() - const result = await window.electronAPI.chat.enrichSessionsContactInfo(usernames) + const result = await window.electronAPI.chat.enrichSessionsContactInfo(usernames) as { + success: boolean + contacts?: Record + error?: string + } const dllTime = performance.now() - dllStart // DLL 调用后再次让出控制权 @@ -504,7 +508,8 @@ function ChatPage(_props: ChatPageProps) { if (result.success && result.contacts) { // 将更新加入队列,用于侧边栏更新 - for (const [username, contact] of Object.entries(result.contacts)) { + const contacts = result.contacts || {} + for (const [username, contact] of Object.entries(contacts)) { contactUpdateQueueRef.current.set(username, contact) // 如果是自己的信息且当前个人头像为空,同步更新 @@ -545,7 +550,11 @@ function ChatPage(_props: ChatPageProps) { setIsRefreshingMessages(true) try { // 获取最新消息并增量添加 - const result = await window.electronAPI.chat.getLatestMessages(currentSessionId, 50) + const result = await window.electronAPI.chat.getLatestMessages(currentSessionId, 50) as { + success: boolean; + messages?: Message[]; + error?: string + } if (!result.success || !result.messages) { return } @@ -593,7 +602,12 @@ function ChatPage(_props: ChatPageProps) { const firstMsgEl = listEl?.querySelector('.message-wrapper') as HTMLElement | null try { - const result = await window.electronAPI.chat.getMessages(sessionId, offset, messageLimit, startTime, endTime) + const result = await window.electronAPI.chat.getMessages(sessionId, offset, messageLimit, startTime, endTime) as { + success: boolean; + messages?: Message[]; + hasMore?: boolean; + error?: string + } if (result.success && result.messages) { if (offset === 0) { setMessages(result.messages) @@ -690,7 +704,12 @@ function ChatPage(_props: ChatPageProps) { try { const lastMsg = messages[messages.length - 1] // 从最后一条消息的时间开始往后找 - const result = await window.electronAPI.chat.getMessages(currentSessionId, 0, 50, lastMsg.createTime, 0, true) + const result = await window.electronAPI.chat.getMessages(currentSessionId, 0, 50, lastMsg.createTime, 0, true) as { + success: boolean; + messages?: Message[]; + hasMore?: boolean; + error?: string + } if (result.success && result.messages) { // 过滤掉已经在列表中的重复消息 @@ -1555,7 +1574,7 @@ function MessageBubble({ message, session, showTime, myAvatarUrl, isGroupChat, o const contentToUse = message.content || (message as any).rawContent || message.parsedContent if (contentToUse) { console.log('[Video Debug] Parsing MD5 from content, length:', contentToUse.length) - window.electronAPI.video.parseVideoMd5(contentToUse).then((result) => { + window.electronAPI.video.parseVideoMd5(contentToUse).then((result: { success: boolean; md5?: string; error?: string }) => { console.log('[Video Debug] Parse result:', result) if (result && result.success && result.md5) { console.log('[Video Debug] Parsed MD5:', result.md5) @@ -1563,7 +1582,7 @@ function MessageBubble({ message, session, showTime, myAvatarUrl, isGroupChat, o } else { console.error('[Video Debug] Failed to parse MD5:', result) } - }).catch((err) => { + }).catch((err: unknown) => { console.error('[Video Debug] Parse error:', err) }) } @@ -1671,7 +1690,7 @@ function MessageBubble({ message, session, showTime, myAvatarUrl, isGroupChat, o } const pending = senderAvatarLoading.get(sender) if (pending) { - pending.then((result) => { + pending.then((result: { avatarUrl?: string; displayName?: string } | null) => { if (result) { setSenderAvatarUrl(result.avatarUrl) setSenderName(result.displayName) @@ -1787,7 +1806,7 @@ function MessageBubble({ message, session, showTime, myAvatarUrl, isGroupChat, o sessionId: session.username, imageMd5: message.imageMd5 || undefined, imageDatName: message.imageDatName - }).then((result) => { + }).then((result: { success: boolean; localPath?: string; hasUpdate?: boolean; error?: string }) => { if (cancelled) return if (result.success && result.localPath) { imageDataUrlCache.set(imageCacheKey, result.localPath) @@ -1805,7 +1824,7 @@ function MessageBubble({ message, session, showTime, myAvatarUrl, isGroupChat, o useEffect(() => { if (!isImage) return - const unsubscribe = window.electronAPI.image.onUpdateAvailable((payload) => { + const unsubscribe = window.electronAPI.image.onUpdateAvailable((payload: { cacheKey: string; imageMd5?: string; imageDatName?: string }) => { const matchesCacheKey = payload.cacheKey === message.imageMd5 || payload.cacheKey === message.imageDatName || @@ -1822,7 +1841,7 @@ function MessageBubble({ message, session, showTime, myAvatarUrl, isGroupChat, o useEffect(() => { if (!isImage) return - const unsubscribe = window.electronAPI.image.onCacheResolved((payload) => { + const unsubscribe = window.electronAPI.image.onCacheResolved((payload: { cacheKey: string; imageMd5?: string; imageDatName?: string; localPath: string }) => { const matchesCacheKey = payload.cacheKey === message.imageMd5 || payload.cacheKey === message.imageDatName || @@ -1992,7 +2011,7 @@ function MessageBubble({ message, session, showTime, myAvatarUrl, isGroupChat, o useEffect(() => { if (!isVoice || voiceDataUrl) return window.electronAPI.chat.resolveVoiceCache(session.username, String(message.localId)) - .then(result => { + .then((result: { success: boolean; hasCache: boolean; data?: string; error?: string }) => { if (result.success && result.hasCache && result.data) { const url = `data:audio/wav;base64,${result.data}` voiceDataUrlCache.set(voiceCacheKey, url) @@ -2125,7 +2144,7 @@ function MessageBubble({ message, session, showTime, myAvatarUrl, isGroupChat, o console.log('[Video Debug] Loading video info for MD5:', videoMd5) setVideoLoading(true) - window.electronAPI.video.getVideoInfo(videoMd5).then((result) => { + window.electronAPI.video.getVideoInfo(videoMd5).then((result: { success: boolean; exists: boolean; videoUrl?: string; coverUrl?: string; thumbUrl?: string; error?: string }) => { console.log('[Video Debug] getVideoInfo result:', result) if (result && result.success) { setVideoInfo({ @@ -2138,7 +2157,7 @@ function MessageBubble({ message, session, showTime, myAvatarUrl, isGroupChat, o console.error('[Video Debug] Video info failed:', result) setVideoInfo({ exists: false }) } - }).catch((err) => { + }).catch((err: unknown) => { console.error('[Video Debug] getVideoInfo error:', err) setVideoInfo({ exists: false }) }).finally(() => { @@ -2151,7 +2170,7 @@ function MessageBubble({ message, session, showTime, myAvatarUrl, isGroupChat, o const [autoTranscribeEnabled, setAutoTranscribeEnabled] = useState(false) useEffect(() => { - window.electronAPI.config.get('autoTranscribeVoice').then((value) => { + window.electronAPI.config.get('autoTranscribeVoice').then((value: unknown) => { setAutoTranscribeEnabled(value === true) }) }, []) diff --git a/src/pages/ContactsPage.tsx b/src/pages/ContactsPage.tsx index dd6dd7d..c4d071f 100644 --- a/src/pages/ContactsPage.tsx +++ b/src/pages/ContactsPage.tsx @@ -45,18 +45,18 @@ function ContactsPage() { if (contactsResult.success && contactsResult.contacts) { console.log('📊 总联系人数:', contactsResult.contacts.length) console.log('📊 按类型统计:', { - friends: contactsResult.contacts.filter(c => c.type === 'friend').length, - groups: contactsResult.contacts.filter(c => c.type === 'group').length, - officials: contactsResult.contacts.filter(c => c.type === 'official').length, - other: contactsResult.contacts.filter(c => c.type === 'other').length + friends: contactsResult.contacts.filter((c: ContactInfo) => c.type === 'friend').length, + groups: contactsResult.contacts.filter((c: ContactInfo) => c.type === 'group').length, + officials: contactsResult.contacts.filter((c: ContactInfo) => c.type === 'official').length, + other: contactsResult.contacts.filter((c: ContactInfo) => c.type === 'other').length }) // 获取头像URL - const usernames = contactsResult.contacts.map(c => c.username) + const usernames = contactsResult.contacts.map((c: ContactInfo) => c.username) if (usernames.length > 0) { const avatarResult = await window.electronAPI.chat.enrichSessionsContactInfo(usernames) if (avatarResult.success && avatarResult.contacts) { - contactsResult.contacts.forEach(contact => { + contactsResult.contacts.forEach((contact: ContactInfo) => { const enriched = avatarResult.contacts?.[contact.username] if (enriched?.avatarUrl) { contact.avatarUrl = enriched.avatarUrl diff --git a/src/pages/ExportPage.tsx b/src/pages/ExportPage.tsx index 67d89fc..c94f12f 100644 --- a/src/pages/ExportPage.tsx +++ b/src/pages/ExportPage.tsx @@ -189,7 +189,7 @@ function ExportPage() { }, [loadSessions]) useEffect(() => { - const removeListener = window.electronAPI.export.onProgress?.((payload) => { + const removeListener = window.electronAPI.export.onProgress?.((payload: { current: number; total: number; currentSession: string; phase: string }) => { setExportProgress({ current: payload.current, total: payload.total, diff --git a/src/pages/SettingsPage.tsx b/src/pages/SettingsPage.tsx index 771bf15..f4603b3 100644 --- a/src/pages/SettingsPage.tsx +++ b/src/pages/SettingsPage.tsx @@ -155,10 +155,10 @@ function SettingsPage() { }, [showExportFormatSelect, showExportDateRangeSelect, showExportExcelColumnsSelect, showExportConcurrencySelect]) useEffect(() => { - const removeDb = window.electronAPI.key.onDbKeyStatus((payload) => { + const removeDb = window.electronAPI.key.onDbKeyStatus((payload: { message: string; level: number }) => { setDbKeyStatus(payload.message) }) - const removeImage = window.electronAPI.key.onImageKeyStatus((payload) => { + const removeImage = window.electronAPI.key.onImageKeyStatus((payload: { message: string }) => { setImageKeyStatus(payload.message) }) return () => { @@ -270,7 +270,7 @@ function SettingsPage() { }, []) useEffect(() => { - const removeListener = window.electronAPI.whisper?.onDownloadProgress?.((payload) => { + const removeListener = window.electronAPI.whisper?.onDownloadProgress?.((payload: { modelName: string; downloadedBytes: number; totalBytes?: number; percent?: number }) => { if (typeof payload.percent === 'number') { setWhisperDownloadProgress(payload.percent) } diff --git a/src/pages/SnsPage.tsx b/src/pages/SnsPage.tsx index 8029dd1..e3efe81 100644 --- a/src/pages/SnsPage.tsx +++ b/src/pages/SnsPage.tsx @@ -165,8 +165,8 @@ export default function SnsPage() { scrollAdjustmentRef.current = postsContainerRef.current.scrollHeight; } - const existingIds = new Set(currentPosts.map(p => p.id)); - const uniqueNewer = result.timeline.filter(p => !existingIds.has(p.id)); + const existingIds = new Set(currentPosts.map((p: SnsPost) => p.id)); + const uniqueNewer = result.timeline.filter((p: SnsPost) => !existingIds.has(p.id)); if (uniqueNewer.length > 0) { setPosts(prev => [...uniqueNewer, ...prev]); @@ -253,7 +253,7 @@ export default function SnsPage() { })) setContacts(initialContacts) - const usernames = initialContacts.map(c => c.username) + const usernames = initialContacts.map((c: { username: string }) => c.username) const enriched = await window.electronAPI.chat.enrichSessionsContactInfo(usernames) if (enriched.success && enriched.contacts) { setContacts(prev => prev.map(c => { diff --git a/src/pages/WelcomePage.tsx b/src/pages/WelcomePage.tsx index 4955ef9..c68c64f 100644 --- a/src/pages/WelcomePage.tsx +++ b/src/pages/WelcomePage.tsx @@ -106,10 +106,10 @@ function WelcomePage({ standalone = false }: WelcomePageProps) { } useEffect(() => { - const removeDb = window.electronAPI.key.onDbKeyStatus((payload) => { + const removeDb = window.electronAPI.key.onDbKeyStatus((payload: { message: string; level: number }) => { setDbKeyStatus(payload.message) }) - const removeImage = window.electronAPI.key.onImageKeyStatus((payload) => { + const removeImage = window.electronAPI.key.onImageKeyStatus((payload: { message: string }) => { setImageKeyStatus(payload.message) }) return () => {