UNPKG

electron-native-notification

Version:
44 lines (36 loc) 1.31 kB
<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <script type="text/javascript"> const { ipcRenderer, } = require('electron'); let activeNotifications = []; ipcRenderer.on('display-notification', (event, params) => { let notification = new Notification(params.title, params.opts); notification.onclick = () => ipcRenderer.send('display-notification-onclick', params.uuid); notification.onshow = () => ipcRenderer.send('display-notification-onshow', params.uuid); notification.onerror = (err) => ipcRenderer.send('display-notification-onerror', params.uuid, err); notification.onclose = () => { activeNotifications = activeNotifications.filter((item) => item.uuid !== params.uuid); ipcRenderer.send('display-notification-onclose', params.uuid); }; activeNotifications.push({ uuid: params.uuid, notification, }); }); ipcRenderer.on('close-notification', (event, { uuid }) => { for (const item of activeNotifications) { if (item.uuid === uuid) { item.notification.close(); } } }); </script> </body> </html>