-
Notifications
You must be signed in to change notification settings - Fork 6
/
notifier.js
45 lines (43 loc) · 1.29 KB
/
notifier.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module.exports = function init(appName, cb) {
switch (require('os').type()) {
case 'Linux':
var proc = require('child_process')
var notifications = require('freedesktop-notifications')
try {
return notifications.init(inited)
} catch(e) {
// fallthrough
}
function inited(err) {
if (err) {
if (/was not provided/.test(err))
return cb(new Error('Notification daemon not available'))
else
return cb(err)
}
notifications.setAppName(appName)
cb(null, function (notif) {
var notification = notifications.createNotification({
summary: notif.title,
body: notif.message,
actions: {
default: 'Open'
},
icon: notif.icon,
// https://developer.gnome.org/notification-spec/#hints
'desktop-entry': 'ssb-patchwork-electron'
})
notification.on('action', function (action) {
proc.spawn('xdg-open', [notif.open], {stdio: 'inherit'}).unref()
});
notification.push()
})
}
default:
var notifier = require('node-notifier')
cb(null, function (notif) {
notif.name = appName
notifier.notify(notif)
})
}
}