Prevent crash when tray icon no longer available (due to apt)
This commit is contained in:
parent
5165eb3bd4
commit
6bcd434585
1 changed files with 11 additions and 4 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue