mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-24 18:50:56 +08:00
refactor: enhance notification handling based on page context
- Updated NotificationProvider to truncate long messages for better display. - Modified message sending logic in messageThunk to prevent notifications on the home page, improving user experience.
This commit is contained in:
parent
c49a262df6
commit
4f046a5510
@ -39,7 +39,8 @@ export const NotificationProvider: React.FC<{ children: React.ReactNode }> = ({
|
||||
return new Promise<void>((resolve) => {
|
||||
api.open({
|
||||
message: notification.title,
|
||||
description: notification.message,
|
||||
description:
|
||||
notification.message.length > 50 ? notification.message.slice(0, 47) + '...' : notification.message,
|
||||
duration: 3,
|
||||
placement: 'topRight',
|
||||
type: typeMap[notification.type] || 'info',
|
||||
|
||||
@ -36,6 +36,7 @@ import {
|
||||
} from '@renderer/utils/messageUtils/create'
|
||||
import { getMainTextContent } from '@renderer/utils/messageUtils/find'
|
||||
import { getTopicQueue, waitForTopicQueue } from '@renderer/utils/queue'
|
||||
import { isOnHomePage } from '@renderer/utils/window'
|
||||
import { t } from 'i18next'
|
||||
import { throttle } from 'lodash'
|
||||
|
||||
@ -589,15 +590,17 @@ const fetchAndProcessAssistantResponseImpl = async (
|
||||
status: error.status || error.code,
|
||||
requestId: error.request_id
|
||||
}
|
||||
await notificationService.send({
|
||||
id: uuid(),
|
||||
type: 'error',
|
||||
title: t('notification.assistant'),
|
||||
message: serializableError.message,
|
||||
silent: false,
|
||||
timestamp: Date.now(),
|
||||
source: 'assistant'
|
||||
})
|
||||
if (!isOnHomePage()) {
|
||||
await notificationService.send({
|
||||
id: uuid(),
|
||||
type: 'error',
|
||||
title: t('notification.assistant'),
|
||||
message: serializableError.message,
|
||||
silent: false,
|
||||
timestamp: Date.now(),
|
||||
source: 'assistant'
|
||||
})
|
||||
}
|
||||
|
||||
if (lastBlockId) {
|
||||
// 更改上一个block的状态为ERROR
|
||||
@ -646,15 +649,17 @@ const fetchAndProcessAssistantResponseImpl = async (
|
||||
}
|
||||
|
||||
const content = getMainTextContent(finalAssistantMsg)
|
||||
await notificationService.send({
|
||||
id: uuid(),
|
||||
type: 'success',
|
||||
title: t('notification.assistant'),
|
||||
message: content.length > 50 ? content.slice(0, 47) + '...' : content,
|
||||
silent: false,
|
||||
timestamp: Date.now(),
|
||||
source: 'assistant'
|
||||
})
|
||||
if (!isOnHomePage()) {
|
||||
await notificationService.send({
|
||||
id: uuid(),
|
||||
type: 'success',
|
||||
title: t('notification.assistant'),
|
||||
message: content.length > 50 ? content.slice(0, 47) + '...' : content,
|
||||
silent: false,
|
||||
timestamp: Date.now(),
|
||||
source: 'assistant'
|
||||
})
|
||||
}
|
||||
|
||||
// 更新topic的name
|
||||
autoRenameTopic(assistant, topicId)
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
export const isFocused = () => {
|
||||
return document.hasFocus()
|
||||
}
|
||||
|
||||
export const isOnHomePage = () => {
|
||||
return window.location.hash === '#/' || window.location.hash === '#' || window.location.hash === ''
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user