diff --git a/app/notify.html b/app/notify.html deleted file mode 100644 index 6dd8af4e..00000000 --- a/app/notify.html +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/app/notify.ts b/app/notify.ts index 5c1e9ce3..c455fe55 100644 --- a/app/notify.ts +++ b/app/notify.ts @@ -1,44 +1,10 @@ -import {resolve} from 'path'; -import {app, BrowserWindow} from 'electron'; -import isDev from 'electron-is-dev'; +import {Notification} from 'electron'; +import {icon} from './config/paths'; -let win: BrowserWindow; - -// 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 :'( - -let buffer: string[][] = []; - -function notify(title: string, body = '', details: any = {}) { +export default function notify(title: string, body = '', details: any = {}) { console.log(`[Notification] ${title}: ${body}`); if (details.error) { console.error(details.error); } - if (win) { - win.webContents.send('notification', {title, body}); - } else { - buffer.push([title, body]); - } + new Notification({title, body, ...(process.platform === 'linux' && {icon})}).show(); } - -app.on('ready', () => { - const win_ = new BrowserWindow({ - show: false, - webPreferences: { - nodeIntegration: true - } - }); - const url = `file://${resolve(isDev ? __dirname : app.getAppPath(), 'notify.html')}`; - win_.loadURL(url); - win_.webContents.on('dom-ready', () => { - win = win_; - buffer.forEach(([title, body]) => { - notify(title, body); - }); - buffer = []; - }); -}); - -export default notify;