notify: more robust notifications API

This commit is contained in:
Guillermo Rauch 2016-07-07 15:17:11 -07:00
parent e39143e4cd
commit 6bba2c6ded

View file

@ -9,6 +9,8 @@ let win;
// so we launch a window on which we can use the // so we launch a window on which we can use the
// HTML5 `Notification` API :'( // HTML5 `Notification` API :'(
let buffer = [];
app.on('ready', () => { app.on('ready', () => {
const win_ = new BrowserWindow({ const win_ = new BrowserWindow({
show: false show: false
@ -18,12 +20,22 @@ app.on('ready', () => {
'notify.html' 'notify.html'
); );
win_.loadURL(url); win_.loadURL(url);
win = win_; win_.webContents.on('dom-ready', () => {
console.log('ready');
win = win_;
buffer.forEach(([title, body]) => {
notify(title, body);
});
buffer = null;
});
}); });
module.exports = function notify (title, body) { function notify (title, body) {
if (win) { if (win) {
win.webContents.send('notification', { title, body }); win.webContents.send('notification', { title, body });
} else {
buffer.push([title, body]);
} }
// TODO: buffer ? }
};
module.exports = notify;