修复通知内部分组件显示异常;修复结束引导后无法正确连接后端服务的问题;优化了图片密钥的解析速度

This commit is contained in:
cc
2026-02-28 19:26:54 +08:00
parent d49cf08e21
commit b31ab46d11
8 changed files with 88 additions and 383 deletions

View File

@@ -257,7 +257,8 @@ export function GlobalSessionMonitor() {
const handleActiveSessionRefresh = async (sessionId: string) => {
// 从 ChatPage 复制/调整的逻辑,以保持集中
const state = useChatStore.getState()
const lastMsg = state.messages[state.messages.length - 1]
const msgs = state.messages || []
const lastMsg = msgs[msgs.length - 1]
const minTime = lastMsg?.createTime || 0
try {

View File

@@ -48,18 +48,26 @@
backdrop-filter: none !important;
-webkit-backdrop-filter: none !important;
// 确保背景完全不透明(通知是独立窗口,透明背景会穿透)
background: var(--bg-secondary-solid, var(--bg-secondary, #2c2c2c));
color: var(--text-primary, #ffffff);
// 独立通知窗口:默认使用浅色模式硬编码值,确保不依赖 <html> 上的主题属性
background: #ffffff;
color: #3d3d3d;
--text-primary: #3d3d3d;
--text-secondary: #666666;
--text-tertiary: #999999;
--border-light: rgba(0, 0, 0, 0.08);
// 色模式强制完全不透明白色背景
[data-mode="light"] &,
:not([data-mode]) & {
background: #ffffff !important;
// 色模式覆盖
[data-mode="dark"] & {
background: var(--bg-secondary-solid, #282420);
color: var(--text-primary, #F0EEE9);
--text-primary: #F0EEE9;
--text-secondary: #b3b0aa;
--text-tertiary: #807d78;
--border-light: rgba(255, 255, 255, 0.1);
}
box-shadow: none !important; // NO SHADOW
border: 1px solid var(--border-light, rgba(255, 255, 255, 0.1));
border: 1px solid var(--border-light);
display: flex;
padding: 16px;

View File

@@ -767,7 +767,7 @@ function ChatPage(_props: ChatPageProps) {
setIsRefreshingMessages(true)
// 找出当前已渲染消息中的最大时间戳(使用 getState 获取最新状态,避免闭包过时导致重复)
const currentMessages = useChatStore.getState().messages
const currentMessages = useChatStore.getState().messages || []
const lastMsg = currentMessages[currentMessages.length - 1]
const minTime = lastMsg?.createTime || 0
@@ -781,7 +781,7 @@ function ChatPage(_props: ChatPageProps) {
if (result.success && result.messages && result.messages.length > 0) {
// 过滤去重:必须对比实时的状态,防止在 handleRefreshMessages 运行期间导致的冲突
const latestMessages = useChatStore.getState().messages
const latestMessages = useChatStore.getState().messages || []
const existingKeys = new Set(latestMessages.map(getMessageKey))
const newOnes = result.messages.filter(m => !existingKeys.has(getMessageKey(m)))
@@ -822,7 +822,7 @@ function ChatPage(_props: ChatPageProps) {
return
}
// 使用实时状态进行去重对比
const latestMessages = useChatStore.getState().messages
const latestMessages = useChatStore.getState().messages || []
const existing = new Set(latestMessages.map(getMessageKey))
const lastMsg = latestMessages[latestMessages.length - 1]
const lastTime = lastMsg?.createTime ?? 0
@@ -1740,7 +1740,7 @@ function ChatPage(_props: ChatPageProps) {
// Range selection with Shift key
if (isShiftKey && lastSelectedIdRef.current !== null && lastSelectedIdRef.current !== localId) {
const currentMsgs = useChatStore.getState().messages
const currentMsgs = useChatStore.getState().messages || []
const idx1 = currentMsgs.findIndex(m => m.localId === lastSelectedIdRef.current)
const idx2 = currentMsgs.findIndex(m => m.localId === localId)
@@ -1810,7 +1810,7 @@ function ChatPage(_props: ChatPageProps) {
const dbPathHint = (msg as any)._db_path
const result = await (window as any).electronAPI.chat.deleteMessage(currentSessionId, msg.localId, msg.createTime, dbPathHint)
if (result.success) {
const currentMessages = useChatStore.getState().messages
const currentMessages = useChatStore.getState().messages || []
const newMessages = currentMessages.filter(m => m.localId !== msg.localId)
useChatStore.getState().setMessages(newMessages)
} else {
@@ -1871,7 +1871,7 @@ function ChatPage(_props: ChatPageProps) {
try {
const result = await (window as any).electronAPI.chat.updateMessage(currentSessionId, editingMessage.message.localId, editingMessage.message.createTime, finalContent)
if (result.success) {
const currentMessages = useChatStore.getState().messages
const currentMessages = useChatStore.getState().messages || []
const newMessages = currentMessages.map(m => {
if (m.localId === editingMessage.message.localId) {
return { ...m, parsedContent: finalContent, content: finalContent, rawContent: finalContent }
@@ -1913,7 +1913,7 @@ function ChatPage(_props: ChatPageProps) {
cancelDeleteRef.current = false
try {
const currentMessages = useChatStore.getState().messages
const currentMessages = useChatStore.getState().messages || []
const selectedIds = Array.from(selectedMessages)
const deletedIds = new Set<number>()
@@ -1937,7 +1937,7 @@ function ChatPage(_props: ChatPageProps) {
setDeleteProgress({ current: i + 1, total: selectedIds.length })
}
const finalMessages = useChatStore.getState().messages.filter(m => !deletedIds.has(m.localId))
const finalMessages = (useChatStore.getState().messages || []).filter(m => !deletedIds.has(m.localId))
useChatStore.getState().setMessages(finalMessages)
setIsSelectionMode(false)
@@ -2126,7 +2126,7 @@ function ChatPage(_props: ChatPageProps) {
<div className="empty-sessions">
<MessageSquare />
<p></p>
<p className="hint"></p>
<p className="hint"></p>
</div>
)}
</div>
@@ -2329,7 +2329,7 @@ function ChatPage(_props: ChatPageProps) {
</div>
)}
{messages.map((msg, index) => {
{(messages || []).map((msg, index) => {
const prevMsg = index > 0 ? messages[index - 1] : undefined
const showDateDivider = shouldShowDateDivider(msg, prevMsg)

View File

@@ -1,11 +1,9 @@
import { useEffect, useState, useRef } from 'react'
import { NotificationToast, type NotificationData } from '../components/NotificationToast'
import { useThemeStore } from '../stores/themeStore'
import '../components/NotificationToast.scss'
import './NotificationWindow.scss'
export default function NotificationWindow() {
const { currentTheme, themeMode } = useThemeStore()
const [notification, setNotification] = useState<NotificationData | null>(null)
const [prevNotification, setPrevNotification] = useState<NotificationData | null>(null)
@@ -19,12 +17,6 @@ export default function NotificationWindow() {
const notificationRef = useRef<NotificationData | null>(null)
// 应用主题到通知窗口
useEffect(() => {
document.documentElement.setAttribute('data-theme', currentTheme)
document.documentElement.setAttribute('data-mode', themeMode)
}, [currentTheme, themeMode])
useEffect(() => {
notificationRef.current = notification
}, [notification])

View File

@@ -86,15 +86,16 @@ export const useChatStore = create<ChatState>((set, get) => ({
if (m.localId && m.localId > 0) return `l:${m.localId}`
return `t:${m.createTime}:${m.sortSeq || 0}:${m.serverId || 0}`
}
const existingKeys = new Set(state.messages.map(getMsgKey))
const currentMessages = state.messages || []
const existingKeys = new Set(currentMessages.map(getMsgKey))
const filtered = newMessages.filter(m => !existingKeys.has(getMsgKey(m)))
if (filtered.length === 0) return state
return {
messages: prepend
? [...filtered, ...state.messages]
: [...state.messages, ...filtered]
? [...filtered, ...currentMessages]
: [...currentMessages, ...filtered]
}
}),