From 29df9b277d761750d2409e2a82b2b310118962db Mon Sep 17 00:00:00 2001 From: Guillermo Rauch Date: Thu, 7 Jul 2016 13:48:43 -0700 Subject: [PATCH] add basic notification system --- notify.html | 5 +++++ notify.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 notify.html create mode 100644 notify.js diff --git a/notify.html b/notify.html new file mode 100644 index 00000000..6dd8af4e --- /dev/null +++ b/notify.html @@ -0,0 +1,5 @@ + diff --git a/notify.js b/notify.js new file mode 100644 index 00000000..ecd97d67 --- /dev/null +++ b/notify.js @@ -0,0 +1,29 @@ +const { app, BrowserWindow } = require('electron'); +const isDev = require('electron-is-dev'); +const { resolve } = require('path'); + +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 :'( + +app.on('ready', () => { + const win_ = new BrowserWindow({ + show: false + }); + const url = 'file://' + resolve( + isDev ? __dirname : app.getAppPath(), + 'notify.html' + ); + win_.loadURL(url); + win = win_; +}); + +module.exports = function notify (title, body) { + if (win) { + win.webContents.send('notification', { title, body }); + } + // TODO: buffer ? +};