Skip to content

Commit

Permalink
Add a workaround for a notifications bug in Electron
Browse files Browse the repository at this point in the history
  • Loading branch information
CvX committed Jan 27, 2019
1 parent c5dfe70 commit c3923e3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ app.on('before-quit', () => {
config.set('lastWindowState', mainWindow.getNormalBounds());
});

const notifications = new Map();

ipcMain.on('notification', (event, {id, title, body, icon, silent}) => {
const notification = new Notification({
title,
Expand All @@ -422,18 +424,26 @@ ipcMain.on('notification', (event, {id, title, body, icon, silent}) => {
silent
});

notifications.set(id, notification);

notification.on('click', () => {
mainWindow.show();
sendAction('notification-callback', {callbackName: 'onclick', id});

notifications.delete(id);
});

notification.on('reply', (event, reply) => {
// We use onclick event used by messenger to go to the right convo
sendBackgroundAction('notification-reply-callback', {callbackName: 'onclick', id, reply});

notifications.delete(id);
});

notification.on('close', () => {
sendAction('notification-callback', {callbackName: 'onclose', id});

notifications.delete(id);
});

notification.show();
Expand Down

0 comments on commit c3923e3

Please sign in to comment.