fix(mac-notifier): Make macOS-only package optional

This commit is contained in:
Ben Gotow 2016-10-27 14:44:33 -07:00
parent e7c22eacbc
commit 85782c7b27
2 changed files with 11 additions and 3 deletions

View file

@ -51,7 +51,6 @@
"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",
@ -83,6 +82,9 @@
"underscore.string": "^3.0",
"windows-shortcuts": "emorikawa/windows-shortcuts#b0a0fc7"
},
"optionalDependencies": {
"node-mac-notifier": "0.0.13"
},
"packageDependencies": {},
"scripts": {
"flow": "flow; test $? -eq 0 -o $? -eq 2",

View file

@ -1,12 +1,18 @@
/* eslint global-require: 0 */
let MacNotifierNotification = null;
if (process.platform === 'darwin') {
try {
MacNotifierNotification = require('node-mac-notifier');
} catch (err) {
console.error("node-mac-notifier (a platform-specific optionalDependency) was not installed correctly! Check the Travis build log for errors.")
}
}
class NativeNotifications {
displayNotification({title, subtitle, body, tag, canReply, onActivate} = {}) {
let notif = null;
if (process.platform === 'darwin') {
MacNotifierNotification = MacNotifierNotification || require('node-mac-notifier');
if (MacNotifierNotification) {
notif = new MacNotifierNotification(title, {
bundleId: 'com.nylas.nylas-mail',
canReply: canReply,