@@ -351,7 +360,7 @@
MeToast.info('自定义插件已安装(消息后追加计数)');
}
- // === v2.0 new features ===
+ // === 高级特性 ===
function demoResetTimer() {
const t=MeToast.info('这条消息不会自动消失(resetTimer)',{duration:3000,resetTimerOnUpdate:true,closeButton:true});
let n=0; const iv=setInterval(()=>{n++;if(n>8){clearInterval(iv);t.close();return;}t.update({message:'重置计时器 #'+n+' — 每次更新重置3秒'});},1000);
@@ -387,6 +396,25 @@
});
}
+ // === onError ===
+ function demoOnError() {
+ MeToast.configure({
+ onError: function(info) {
+ MeToast.error('⚠️ 捕获错误: ' + (info.hook || info.source), { duration: 3000, position: 'bottom-center' });
+ }
+ });
+ MeToast.info('已启用 onError 监控(钩子/定时器异常将被捕获)', { duration: 3000 });
+ // 触发一个钩子错误来演示
+ var badFn = function() { throw new Error('demo-error'); };
+ Toast.on('afterShow', badFn);
+ MeToast.success('这条消息会触发错误', { duration: 2000 });
+ setTimeout(function() { Toast.off('afterShow', badFn); }, 3000);
+ }
+ function demoOnErrorReset() {
+ MeToast.configure({ onError: null });
+ MeToast.info('onError 已重置为 null');
+ }
+
// === i18n ===
function switchLocale(loc) {
try{MeToast.i18n.switchLocale(loc);MeToast.configure({locale:loc});MeToast.success(loc==='zh-CN'?'已切换到中文':'Switched to English',{theme:'dark'});}
diff --git a/docs/metona-toast-docs.html b/docs/metona-toast-docs.html
index 55efa52..d1bfc3d 100644
--- a/docs/metona-toast-docs.html
+++ b/docs/metona-toast-docs.html
@@ -69,9 +69,9 @@
API 文档
-MetonaToast v2.0.1 完整 API 参考。所有基础通知方法(show/success/error/warning/info/loading)支持两种调用形式,均可传入任何 配置项 作为可选第二参数。
+MetonaToast v0.1.2 完整 API 参考。所有基础通知方法(show/success/error/warning/info/loading)支持两种调用形式,均可传入任何 配置项 作为可选第二参数。
show(message, opts?)
@@ -309,7 +309,7 @@ q.cancel(); // 中途取消
type: 'info',
});
-action(message, actions, opts?) v2.0
+action(message, actions, opts?)
Action Toast:内嵌操作按钮。默认 duration=0 不自动关闭,closeButton=true。
| 参数 | 类型 | 默认值 | 说明 |
@@ -331,7 +331,7 @@ q.cancel(); // 中途取消
]);
-group(name) v2.0
+group(name)
创建 Toast 分组,返回 GroupAPI 对象。该对象所有方法自动传入 group: name,按组管理。
| 参数 | 类型 | 说明 |
@@ -409,7 +409,7 @@ MeToast.use('accessibility');
全部配置项
-以下配置可用于 configure()、init() 或单个 Toast 方法的 opts 参数。带 v2.0 标识的为 v2.0 新增。
+以下配置可用于 configure()、init() 或单个 Toast 方法的 opts 参数。
| 配置项 | 类型 | 默认值 | 说明 |
| position | string | 'top-right' | 位置:top-left / top-center / top-right / bottom-left / bottom-center / bottom-right |
@@ -431,9 +431,10 @@ MeToast.use('accessibility'); className | string | '' | 附加到 Toast 元素上的 CSS 类名 |
| style | object | {} | 附加到 Toast 元素上的内联样式对象 |
| locale | string | 'zh-CN' | 语言代码(zh-CN / en-US 等) |
-| resetTimerOnUpdate v2.0 | boolean | false | 调用 update() 时重置 duration 倒计时 |
-| notifyWhenHidden v2.0 | boolean | false | 页面不可见时自动通过 Notification API 发送系统通知 |
-| render v2.0 | function | — | 自定义渲染函数 (toast) => htmlString,完全接管 DOM 构建 |
+ | resetTimerOnUpdate | boolean | false | 调用 update() 时重置 duration 倒计时 |
+ | notifyWhenHidden | boolean | false | 页面不可见时自动通过 Notification API 发送系统通知 |
+ | render | function | — | 自定义渲染函数 (toast) => htmlString,完全接管 DOM 构建 |
+ | onError | function | — | 全局错误回调 ({ hook, source, error, toast }) => void,钩子异常或定时器错误时触发 |
回调函数
@@ -442,7 +443,8 @@ MeToast.use('accessibility'); onShow | (toast: ToastInstance) => void | Toast DOM 创建并播放入场动画后 |
| onClose | (toast: ToastInstance) => void | Toast DOM 被移除后(离场动画完成时) |
| onClick | (toast: ToastInstance) => void | Toast 被点击时(closeOnClick 为 true 时还会自动关闭) |
-| onUpdate v2.0 | (toast: ToastInstance) => void | Toast 内容通过 update() 更新后 |
+| onUpdate | (toast: ToastInstance) => void | Toast 内容通过 update() 更新后 |
+| onError | ({ hook, source, error, toast }) => void | 钩子回调或定时器发生异常时(全局配置,适用于接入错误监控) |
动画列表
diff --git a/package.json b/package.json
index 67ef960..284f08f 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "marklite",
- "version": "0.4.1",
+ "version": "0.4.2",
"description": "Lightweight Markdown Editor for Windows",
"main": "./dist/main/index.js",
"scripts": {
@@ -29,7 +29,7 @@
"license": "MIT",
"dependencies": {
"@metona-team/metona-editor": "^0.1.10",
- "@metona-team/metona-toast": "^2.0.1",
+ "@metona-team/metona-toast": "^0.1.2",
"dexie": "^4.0.11",
"nanoid": "^5.1.5",
"react": "^18.3.1",
diff --git a/src/shared/constants.ts b/src/shared/constants.ts
index 48985ca..2d59ad3 100644
--- a/src/shared/constants.ts
+++ b/src/shared/constants.ts
@@ -1,5 +1,5 @@
// 共享常量 — 主进程和渲染进程共用
-export const APP_VERSION = 'v0.4.1'
+export const APP_VERSION = 'v0.4.2'
export const MAX_FILE_SIZE = 20 * 1024 * 1024 // 20MB
export const ALLOWED_EXTENSIONS = ['.md', '.markdown', '.txt'] as const
export const SKIP_DIRS = new Set([