Files
metona-ai-desktop/src/components/ToastContainer.tsx
T
thzxx f4532a2bb2 refactor: 移除多余依赖,统一 MUI 为唯一 UI 库
- 移除 radix-ui、clsx、tailwind-merge、class-variance-authority、react-router-dom

- 前后端全面适配 MUI 组件,清理残留 Tailwind 工具类引用

- 优化 Agent Loop 引擎、IPC 处理器、Provider Adapter 等后端模块

- 新增 Agent 网络工具通用设计文档 v2
2026-07-05 19:15:48 +08:00

74 lines
2.1 KiB
TypeScript

/**
* ToastContainer — Toast 通知容器
*
* 配置 metona-toast 并监听主进程通知桥接。
*
* @see docs/MetonaAI-Desktop UI UX 设计集成方案.html — MetonaToast 集成方案
*/
import { useEffect } from 'react';
/**
* Toast 容器组件
*
* 在 App 根组件中渲染,负责:
* 1. 配置 MeToast 全局参数
* 2. 监听主进程 toast:show 事件
* 3. 桥接到 MeToast 显示
*/
export function ToastContainer(): null {
useEffect(() => {
// 动态导入 metona-toast 并配置
import('metona-toast').then((mod) => {
const MeToast = mod.default;
// 全局配置(设计规范指定的参数)
MeToast.configure({
position: 'top-right',
duration: 4000,
max: 6,
theme: 'auto',
animation: 'slide',
pauseOnHover: true,
closeOnClick: true,
showProgress: true,
draggable: true,
locale: 'zh-CN',
});
// 安装插件
try {
MeToast.use('keyboard'); // ESC 关闭所有
MeToast.use('persistence'); // 配置持久化
MeToast.use('accessibility'); // 屏幕阅读器
} catch (err) {
console.error('[Toast]', 'Failed to install plugin:', err);
}
}).catch((err) => {
console.error('[Toast]', 'Failed to load metona-toast:', err);
});
// 监听主进程通知桥接
if (window.metona?.toast?.onShow) {
const unsubscribe = window.metona.toast.onShow(async (data) => {
try {
const MeToast = (await import('metona-toast')).default;
const { type, message, options } = data;
switch (type) {
case 'success': MeToast.success(message, options); break;
case 'error': MeToast.error(message, options); break;
case 'warning': MeToast.warning(message, options); break;
case 'info': MeToast.info(message, options); break;
default: MeToast.info(message, options);
}
} catch (err) {
console.error('[Toast]', 'Failed to show toast:', err);
}
});
return unsubscribe;
}
}, []);
return null;
}