/** * 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; }