From 6bba2c6ded435eaa73120ae1bdc456d69dd5809a Mon Sep 17 00:00:00 2001 From: Guillermo Rauch Date: Thu, 7 Jul 2016 15:17:11 -0700 Subject: [PATCH] notify: more robust notifications API --- notify.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/notify.js b/notify.js index ecd97d67..83171572 100644 --- a/notify.js +++ b/notify.js @@ -9,6 +9,8 @@ let win; // 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 @@ -18,12 +20,22 @@ app.on('ready', () => { 'notify.html' ); 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) { win.webContents.send('notification', { title, body }); + } else { + buffer.push([title, body]); } - // TODO: buffer ? -}; +} + +module.exports = notify;