mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-13 04:28: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
|
// 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;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue