本文整理汇总了TypeScript中electron.Notification.on方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Notification.on方法的具体用法?TypeScript Notification.on怎么用?TypeScript Notification.on使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类electron.Notification
的用法示例。
在下文中一共展示了Notification.on方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Notification
(_event: ElectronEvent, {id, title, body, icon, silent}: NotificationEvent) => {
const notification = new Notification({
title,
body,
hasReply: true,
icon: nativeImage.createFromDataURL(icon),
silent
});
notifications.set(id, notification);
notification.on('click', () => {
mainWindow.show();
sendAction('notification-callback', {callbackName: 'onclick', id});
notifications.delete(id);
});
notification.on('reply', (_event, reply: string) => {
// We use onclick event used by messenger to go to the right convo
sendBackgroundAction('notification-reply-callback', {callbackName: 'onclick', id, reply});
notifications.delete(id);
});
notification.on('close', () => {
sendAction('notification-callback', {callbackName: 'onclose', id});
notifications.delete(id);
});
notification.show();
}
示例2: async
watcher.on(actions.notify, async (store, action) => {
const {
title = "itch",
body,
icon = DEFAULT_ICON,
onClick,
} = action.payload;
if (Notification.isSupported()) {
const n = new Notification({
title,
subtitle: null,
body,
icon: icon ? nativeImage.createFromPath(icon) : null,
actions: null,
});
if (onClick) {
n.on("click", e => {
store.dispatch(actions.focusWindow({ window: "root" }));
store.dispatch(onClick);
});
}
n.show();
} else {
logger.warn(`Cannot show notification: ${body}`);
}
});