Add badge for unread messages to the tray icon (#1934)

This commit adds a badge to the tray icon that displays the number of
unread messages, if there is any. It is implemented by providing
alternative versions of the icon, that replace the default image when a
message is received.

The badge is rendered graphically as a red circle containing the number
of unread messages. Since a different icon file is needed for each
possible number of unread messages, but this number is clearly
unbounded, only the numbers from 1 to 9 are provided. If there are 10 or
more unread messages, a single badge (depicted as "9+") is used.

Resolves #1917
This commit is contained in:
Martino Pilia 2018-01-18 00:27:58 +01:00 committed by Scott Nonnenberg
parent 9ef8228ff8
commit 7034d8759d
24 changed files with 22 additions and 5 deletions

View File

@ -11,11 +11,10 @@ let tray = null;
function createTrayIcon(getMainWindow, messages) {
// A smaller icon is needed on macOS
tray = new Tray(
process.platform === 'darwin' ?
path.join(__dirname, '..', 'images', 'icon_16.png') :
path.join(__dirname, '..', 'images', 'icon_256.png')
);
const iconSize = process.platform === 'darwin' ? '16' : '256';
const iconNoNewMessages = path.join(__dirname, '..', 'images', `icon_${iconSize}.png`);
tray = new Tray(iconNoNewMessages);
tray.toggleWindowVisibility = () => {
const mainWindow = getMainWindow();
@ -57,6 +56,15 @@ function createTrayIcon(getMainWindow, messages) {
tray.setContextMenu(trayContextMenu);
};
tray.updateIcon = (unreadCount) => {
if (unreadCount > 0) {
const filename = `${String(unreadCount >= 10 ? 10 : unreadCount)}.png`;
tray.setImage(path.join(__dirname, '..', 'images', 'alert', iconSize, filename));
} else {
tray.setImage(iconNoNewMessages);
}
};
tray.on('click', tray.toggleWindowVisibility);
tray.setToolTip(messages.trayTooltip.message);

BIN
images/alert/16/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 939 B

BIN
images/alert/16/10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 950 B

BIN
images/alert/16/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 947 B

BIN
images/alert/16/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 932 B

BIN
images/alert/16/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 954 B

BIN
images/alert/16/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 948 B

BIN
images/alert/16/6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 959 B

BIN
images/alert/16/7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 945 B

BIN
images/alert/16/8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 933 B

BIN
images/alert/16/9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 948 B

BIN
images/alert/256/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
images/alert/256/10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
images/alert/256/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
images/alert/256/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
images/alert/256/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
images/alert/256/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
images/alert/256/6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
images/alert/256/7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
images/alert/256/8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
images/alert/256/9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -64,6 +64,7 @@
window.setBadgeCount(0);
window.document.title = window.config.title;
}
window.updateTrayIcon(newUnreadCount);
},
startPruning: function() {
var halfHour = 30 * 60 * 1000;

View File

@ -483,3 +483,8 @@ ipc.on('close-about', () => {
}
});
ipc.on('update-tray-icon', (event, unreadCount) => {
if (tray) {
tray.updateIcon(unreadCount);
}
});

View File

@ -34,6 +34,9 @@
window.closeAbout = function() {
ipc.send('close-about');
};
window.updateTrayIcon = function(unreadCount) {
ipc.send('update-tray-icon', unreadCount);
};
ipc.on('debug-log', function() {
Whisper.events.trigger('showDebugLog');