Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: show the unread count on the task bar (Fixes #4788) #4831

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions app/badge_count_overlay.js
@@ -0,0 +1,38 @@
// Copyright 2018-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only

const electron = require('electron');
const path = require('path');

const MAX_BADGE_COUNT = 9;

const createBadgeCountOverlay = getMainWindow => ({
update: unreadCount => {
const mainWindow = getMainWindow();
if (!mainWindow) {
return;
}

let unreadCountText = unreadCount ? `${unreadCount}` : '';
let overlayIcon = null;

if (unreadCount > 0) {
if (unreadCount > MAX_BADGE_COUNT) {
unreadCountText = `${MAX_BADGE_COUNT}plus`;
}

const overlayIconImagePath = path.join(
__dirname,
'..',
'images',
`badge_count_${unreadCountText}.png`
);

overlayIcon = electron.nativeImage.createFromPath(overlayIconImagePath);
}

mainWindow.setOverlayIcon(overlayIcon, unreadCountText);
},
});

module.exports = createBadgeCountOverlay;
Binary file added images/badge_count_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/badge_count_2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/badge_count_3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/badge_count_4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/badge_count_5.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/badge_count_6.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/badge_count_7.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/badge_count_8.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/badge_count_9.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/badge_count_9plus.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 15 additions & 6 deletions main.js
Expand Up @@ -66,6 +66,8 @@ const startInTray = process.argv.some(arg => arg === '--start-in-tray');
const usingTrayIcon =
startInTray || process.argv.some(arg => arg === '--use-tray-icon');

let badgeCountOverlay = null;

const config = require('./app/config');

// Very important to put before the single instance check, since it is based on the
Expand All @@ -85,6 +87,7 @@ const attachmentChannel = require('./app/attachment_channel');
const bounce = require('./ts/services/bounce');
const updater = require('./ts/updater/index');
const createTrayIcon = require('./app/tray_icon');
const createBadgeCountOverlay = require('./app/badge_count_overlay');
const dockIcon = require('./app/dock_icon');
const ephemeralConfig = require('./app/ephemeral_config');
const logging = require('./app/logging');
Expand Down Expand Up @@ -1032,6 +1035,10 @@ app.on('ready', async () => {
tray = createTrayIcon(getMainWindow, locale.messages);
}

if (process.platform === 'win32') {
badgeCountOverlay = createBadgeCountOverlay(getMainWindow);
}

setupMenu();

ensureFilePermissions(['config.json', 'sql/db.sqlite']);
Expand Down Expand Up @@ -1166,6 +1173,14 @@ app.on('will-finish-launching', () => {

ipc.on('set-badge-count', (event, count) => {
app.badgeCount = count;

if (tray) {
tray.updateIcon(count);
}

if (badgeCountOverlay) {
badgeCountOverlay.update(count);
}
});

ipc.on('remove-setup-menu-items', () => {
Expand Down Expand Up @@ -1221,12 +1236,6 @@ ipc.on('close-about', () => {
}
});

ipc.on('update-tray-icon', (event, unreadCount) => {
if (tray) {
tray.updateIcon(unreadCount);
}
});

// Debug Log-related IPC calls

ipc.on('show-debug-log', showDebugLogWindow);
Expand Down
3 changes: 0 additions & 3 deletions preload.js
Expand Up @@ -121,9 +121,6 @@ try {
window.closeAbout = () => ipc.send('close-about');
window.readyForUpdates = () => ipc.send('ready-for-updates');

window.updateTrayIcon = unreadCount =>
ipc.send('update-tray-icon', unreadCount);

ipc.on('set-up-as-new-device', () => {
Whisper.events.trigger('setupAsNewDevice');
});
Expand Down
4 changes: 1 addition & 3 deletions ts/ConversationController.ts
Expand Up @@ -103,13 +103,11 @@ export function start(): void {
window.storage.put('unreadCount', newUnreadCount);

if (newUnreadCount > 0) {
window.setBadgeCount(newUnreadCount);
window.document.title = `${window.getTitle()} (${newUnreadCount})`;
} else {
window.setBadgeCount(0);
window.document.title = window.getTitle();
}
window.updateTrayIcon(newUnreadCount);
window.setBadgeCount(newUnreadCount);
},
}))();

Expand Down
1 change: 0 additions & 1 deletion ts/window.d.ts
Expand Up @@ -188,7 +188,6 @@ declare global {
systemTheme: WhatIsThis;
textsecure: TextSecureType;
unregisterForActive: (handler: WhatIsThis) => void;
updateTrayIcon: (count: number) => void;

Backbone: typeof Backbone;
Signal: {
Expand Down