/
githubmirror
/
hyper
Обзор
Документация
Войти
/
githubmirror
/
hyper
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
3.0.2
app/notify.js
44 строки
1 KB
Sonny
Adding ability to send error object to notify() (#2955)
02 май 2018, 11:10
02 май 2018, 11:10
f64e3e0
Код
Авторство
О чём код?
const {resolve} = require('path'); const {app, BrowserWindow} = require('electron'); const isDev = require('electron-is-dev'); let win; // the hack of all hacks // electron doesn't have a built in notification thing, // so we launch a window on which we can use the // HTML5 `Notification` API :'( let buffer = []; app.on('ready', () => { const win_ = new BrowserWindow({ show: false }); const url = 'file://' + resolve(isDev ? __dirname : app.getAppPath(), 'notify.html'); win_.loadURL(url); win_.webContents.on('dom-ready', () => { win = win_; buffer.forEach(([title, body]) => { notify(title, body); }); buffer = null; }); }); function notify(title, body, details = {}) { //eslint-disable-next-line no-console console.log(`[Notification] ${title}: ${body}`); if (details.error) { //eslint-disable-next-line no-console console.error(details.error); } if (win) { win.webContents.send('notification', {title, body}); } else { buffer.push([title, body]); } } module.exports = notify;