mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-13 04:28:41 -09:00
add basic notification system
This commit is contained in:
parent
0bb26b9c5b
commit
29df9b277d
2 changed files with 34 additions and 0 deletions
5
notify.html
Normal file
5
notify.html
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<script>
|
||||
require('electron').ipcRenderer.on('notification', (ev, { title, body }) => {
|
||||
new Notification(title, { body });
|
||||
});
|
||||
</script>
|
||||
29
notify.js
Normal file
29
notify.js
Normal file
|
|
@ -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 ?
|
||||
};
|
||||
Loading…
Reference in a new issue