Prevent crash when tray icon no longer available (due to apt)

This commit is contained in:
Scott Nonnenberg 2019-02-19 17:35:35 -08:00
parent 5165eb3bd4
commit 6bcd434585

View file

@ -1,5 +1,6 @@
const path = require('path');
const fs = require('fs');
const { app, Menu, Tray } = require('electron');
let trayContextMenu = null;
@ -78,14 +79,20 @@ function createTrayIcon(getMainWindow, messages) {
};
tray.updateIcon = unreadCount => {
let image;
if (unreadCount > 0) {
const filename = `${String(unreadCount >= 10 ? 10 : unreadCount)}.png`;
tray.setImage(
path.join(__dirname, '..', 'images', 'alert', iconSize, filename)
);
image = path.join(__dirname, '..', 'images', 'alert', iconSize, filename);
} else {
tray.setImage(iconNoNewMessages);
image = iconNoNewMessages;
}
if (!fs.existsSync(image)) {
console.log('tray.updateIcon: Image for tray update does not exist!');
return;
}
tray.setImage(image);
};
tray.on('click', tray.showWindow);