mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
notify: more robust notifications API
This commit is contained in:
parent
e39143e4cd
commit
6bba2c6ded
1 changed files with 16 additions and 4 deletions
20
notify.js
20
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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue