mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-04 20:00:00 +08:00
fix: init message api err
This commit is contained in:
parent
f3bbd4ed44
commit
0ea4dd4e3a
@ -1,21 +0,0 @@
|
|||||||
import { App } from 'antd'
|
|
||||||
import { useEffect } from 'react'
|
|
||||||
|
|
||||||
import { initMessageApi } from './TopView/toast'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* MessageInitializer component
|
|
||||||
* This component initializes the message API from App.useApp() hook
|
|
||||||
* It should be rendered inside the AntdProvider (which wraps App component)
|
|
||||||
* so that the message API can inherit the correct theme (dark/light mode)
|
|
||||||
*/
|
|
||||||
export const MessageInitializer = () => {
|
|
||||||
const { message } = App.useApp()
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
// Initialize the message API for use in toast.ts
|
|
||||||
initMessageApi(message)
|
|
||||||
}, [message])
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
@ -2,12 +2,12 @@
|
|||||||
import TopViewMinappContainer from '@renderer/components/MinApp/TopViewMinappContainer'
|
import TopViewMinappContainer from '@renderer/components/MinApp/TopViewMinappContainer'
|
||||||
import { useAppInit } from '@renderer/hooks/useAppInit'
|
import { useAppInit } from '@renderer/hooks/useAppInit'
|
||||||
import { useShortcuts } from '@renderer/hooks/useShortcuts'
|
import { useShortcuts } from '@renderer/hooks/useShortcuts'
|
||||||
import { Modal } from 'antd'
|
import { message, Modal } from 'antd'
|
||||||
import type { PropsWithChildren } from 'react'
|
import type { PropsWithChildren } from 'react'
|
||||||
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
||||||
|
|
||||||
import { Box } from '../Layout'
|
import { Box } from '../Layout'
|
||||||
import { getToastUtilities } from './toast'
|
import { getToastUtilities, initMessageApi } from './toast'
|
||||||
|
|
||||||
let onPop = () => {}
|
let onPop = () => {}
|
||||||
let onShow = ({ element, id }: { element: React.FC | React.ReactNode; id: string }) => {
|
let onShow = ({ element, id }: { element: React.FC | React.ReactNode; id: string }) => {
|
||||||
@ -36,6 +36,7 @@ const TopViewContainer: React.FC<Props> = ({ children }) => {
|
|||||||
elementsRef.current = elements
|
elementsRef.current = elements
|
||||||
|
|
||||||
const [modal, modalContextHolder] = Modal.useModal()
|
const [modal, modalContextHolder] = Modal.useModal()
|
||||||
|
const [messageApi, messageContextHolder] = message.useMessage()
|
||||||
const { shortcuts } = useShortcuts()
|
const { shortcuts } = useShortcuts()
|
||||||
const enableQuitFullScreen = shortcuts.find((item) => item.key === 'exit_fullscreen')?.enabled
|
const enableQuitFullScreen = shortcuts.find((item) => item.key === 'exit_fullscreen')?.enabled
|
||||||
|
|
||||||
@ -43,8 +44,9 @@ const TopViewContainer: React.FC<Props> = ({ children }) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
window.modal = modal
|
window.modal = modal
|
||||||
|
initMessageApi(messageApi)
|
||||||
window.toast = getToastUtilities()
|
window.toast = getToastUtilities()
|
||||||
}, [modal])
|
}, [messageApi, modal])
|
||||||
|
|
||||||
onPop = () => {
|
onPop = () => {
|
||||||
const views = [...elementsRef.current]
|
const views = [...elementsRef.current]
|
||||||
@ -97,6 +99,7 @@ const TopViewContainer: React.FC<Props> = ({ children }) => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{children}
|
{children}
|
||||||
|
{messageContextHolder}
|
||||||
{modalContextHolder}
|
{modalContextHolder}
|
||||||
<TopViewMinappContainer />
|
<TopViewMinappContainer />
|
||||||
{elements.map(({ element: Element, id }) => (
|
{elements.map(({ element: Element, id }) => (
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import { MessageInitializer } from '@renderer/components/MessageInitializer'
|
|
||||||
import { useSettings } from '@renderer/hooks/useSettings'
|
import { useSettings } from '@renderer/hooks/useSettings'
|
||||||
import type { LanguageVarious } from '@renderer/types'
|
import type { LanguageVarious } from '@renderer/types'
|
||||||
import { App, ConfigProvider, theme } from 'antd'
|
import { ConfigProvider, theme } from 'antd'
|
||||||
import deDE from 'antd/locale/de_DE'
|
import deDE from 'antd/locale/de_DE'
|
||||||
import elGR from 'antd/locale/el_GR'
|
import elGR from 'antd/locale/el_GR'
|
||||||
import enUS from 'antd/locale/en_US'
|
import enUS from 'antd/locale/en_US'
|
||||||
@ -115,15 +114,7 @@ const AntdProvider: FC<PropsWithChildren> = ({ children }) => {
|
|||||||
motionDurationMid: '100ms'
|
motionDurationMid: '100ms'
|
||||||
}
|
}
|
||||||
}}>
|
}}>
|
||||||
<App
|
{children}
|
||||||
message={{
|
|
||||||
top: 20,
|
|
||||||
maxCount: 3,
|
|
||||||
duration: 3
|
|
||||||
}}>
|
|
||||||
<MessageInitializer />
|
|
||||||
{children}
|
|
||||||
</App>
|
|
||||||
</ConfigProvider>
|
</ConfigProvider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user