feat(quick-replies): Reply from Mac notifications

This commit is contained in:
Ben Gotow 2016-10-25 11:36:15 -07:00
parent ded52ce101
commit 977b6a0889
3 changed files with 36 additions and 14 deletions

View file

@ -50,6 +50,7 @@
"moment-timezone": "0.5.4",
"mousetrap": "^1.5.3",
"nock": "^2",
"node-mac-notifier": "0.0.13",
"node-uuid": "^1.4",
"nslog": "^3",
"optimist": "0.4.0",

View file

@ -1,14 +0,0 @@
class NativeNotifications
constructor: ->
displayNotification: ({title, subtitle, body, tag, canReply, onActivate} = {}) =>
n = new Notification(title, {
silent: true
body: subtitle
tag: tag
})
n.onclick = onActivate
n
module.exports = new NativeNotifications

View file

@ -0,0 +1,35 @@
/* eslint global-require: 0 */
let MacNotifierNotification = null;
class NativeNotifications {
displayNotification({title, subtitle, body, tag, canReply, onActivate} = {}) {
let notif = null;
if (process.platform === 'darwin') {
MacNotifierNotification = MacNotifierNotification || require('node-mac-notifier');
notif = new MacNotifierNotification(title, {
bundleId: 'com.nylas.nylas-mail',
canReply: canReply,
subtitle: subtitle,
body: body,
id: tag,
});
notif.addEventListener('reply', ({response}) => {
onActivate({response, activationType: 'replied'});
});
notif.addEventListener('click', () => {
onActivate({response: null, activationType: 'clicked'});
});
} else {
notif = new Notification(title, {
silent: true,
body: subtitle,
tag: tag,
});
notif.onclick = onActivate;
}
return notif;
}
}
export default new NativeNotifications()