[MM-34594] Only show dock badge when the setting is enabled (#1538)

* [MM-34594] Only show dock badge when the setting is enabled

* Fixed a potential crash
This commit is contained in:
Devin Binnie
2021-04-19 14:33:04 -04:00
committed by GitHub
parent dcec274d30
commit c461770274
3 changed files with 14 additions and 5 deletions

View File

@@ -32,7 +32,7 @@ const emitBadge = (expired, mentions, unreads) => {
status.emitter.emit(UPDATE_BADGE, expired, mentions, unreads); status.emitter.emit(UPDATE_BADGE, expired, mentions, unreads);
}; };
const emitStatus = () => { export const emitStatus = () => {
const expired = anyExpired(); const expired = anyExpired();
const mentions = totalMentions(); const mentions = totalMentions();
const unreads = anyUnreads(); const unreads = anyUnreads();

View File

@@ -10,6 +10,8 @@ import * as AppState from './appState';
const MAX_WIN_COUNT = 99; const MAX_WIN_COUNT = 99;
let showUnreadBadgeSetting;
function showBadgeWindows(sessionExpired, showUnreadBadge, mentionCount) { function showBadgeWindows(sessionExpired, showUnreadBadge, mentionCount) {
let description = 'You have no unread messages'; let description = 'You have no unread messages';
let text; let text;
@@ -19,7 +21,7 @@ function showBadgeWindows(sessionExpired, showUnreadBadge, mentionCount) {
} else if (mentionCount > 0) { } else if (mentionCount > 0) {
text = (mentionCount > MAX_WIN_COUNT) ? `${MAX_WIN_COUNT}+` : mentionCount.toString(); text = (mentionCount > MAX_WIN_COUNT) ? `${MAX_WIN_COUNT}+` : mentionCount.toString();
description = `You have unread mentions (${mentionCount})`; description = `You have unread mentions (${mentionCount})`;
} else if (showUnreadBadge) { } else if (showUnreadBadge && showUnreadBadgeSetting) {
text = '•'; text = '•';
description = 'You have unread channels'; description = 'You have unread channels';
} }
@@ -32,7 +34,7 @@ function showBadgeOSX(sessionExpired, showUnreadBadge, mentionCount) {
badge = '•'; badge = '•';
} else if (mentionCount > 0) { } else if (mentionCount > 0) {
badge = mentionCount.toString(); badge = mentionCount.toString();
} else if (showUnreadBadge) { } else if (showUnreadBadge && showUnreadBadgeSetting) {
badge = '•'; badge = '•';
} }
app.dock.setBadge(badge); app.dock.setBadge(badge);
@@ -59,6 +61,11 @@ function showBadge(sessionExpired, mentionCount, showUnreadBadge) {
} }
} }
export function setUnreadBadgeSetting(showUnreadBadge) {
showUnreadBadgeSetting = showUnreadBadge;
AppState.emitStatus();
}
export function setupBadge() { export function setupBadge() {
AppState.on(UPDATE_BADGE, showBadge); AppState.on(UPDATE_BADGE, showBadge);
} }

View File

@@ -55,7 +55,7 @@ import {getLocalURLString, getLocalPreload} from './utils';
import {destroyTray, refreshTrayImages, setTrayMenu, setupTray} from './tray/tray'; import {destroyTray, refreshTrayImages, setTrayMenu, setupTray} from './tray/tray';
import {AuthManager} from './authManager'; import {AuthManager} from './authManager';
import {CertificateManager} from './certificateManager'; import {CertificateManager} from './certificateManager';
import {setupBadge} from './badge'; import {setupBadge, setUnreadBadgeSetting} from './badge';
if (process.env.NODE_ENV !== 'production' && module.hot) { if (process.env.NODE_ENV !== 'production' && module.hot) {
module.hot.accept(); module.hot.accept();
@@ -247,6 +247,7 @@ function handleConfigUpdate(newConfig) {
log.error('error:', err); log.error('error:', err);
}); });
WindowManager.setConfig(newConfig.data); WindowManager.setConfig(newConfig.data);
setUnreadBadgeSetting(newConfig.data && newConfig.data.showUnreadBadge);
} }
ipcMain.emit('update-menu', true, config); ipcMain.emit('update-menu', true, config);
@@ -255,6 +256,7 @@ function handleConfigUpdate(newConfig) {
function handleConfigSynchronize() { function handleConfigSynchronize() {
// TODO: send this to server manager // TODO: send this to server manager
WindowManager.setConfig(config.data); WindowManager.setConfig(config.data);
setUnreadBadgeSetting(config.data.showUnreadBadge);
if (app.isReady()) { if (app.isReady()) {
WindowManager.sendToRenderer(RELOAD_CONFIGURATION); WindowManager.sendToRenderer(RELOAD_CONFIGURATION);
} }
@@ -514,7 +516,7 @@ function initializeAfterAppReady() {
if (shouldShowTrayIcon()) { if (shouldShowTrayIcon()) {
setupTray(config.trayIconTheme); setupTray(config.trayIconTheme);
} }
setupBadge(); setupBadge(config.showUnreadBadge);
session.defaultSession.on('will-download', (event, item, webContents) => { session.defaultSession.on('will-download', (event, item, webContents) => {
const filename = item.getFilename(); const filename = item.getFilename();