Files
mattermostest/src/main/badge.ts
Devin Binnie 626fea84a5 [MM-41999] Add additional logging for debugging, allow users to change log level (#2031)
* Add debug logging switch

* Add tests

* Mock electron-log globally in jest

* New logs for debugging

* Switch to a dropdown to choose log levels

* Fix tests

* Update wording
2022-03-31 16:46:57 -04:00

76 lines
2.4 KiB
TypeScript

// Copyright (c) 2015-2016 Yuya Ochiai
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {app} from 'electron';
import log from 'electron-log';
import {UPDATE_BADGE} from 'common/communication';
import WindowManager from './windows/windowManager';
import * as AppState from './appState';
const MAX_WIN_COUNT = 99;
let showUnreadBadgeSetting: boolean;
export function showBadgeWindows(sessionExpired: boolean, mentionCount: number, showUnreadBadge: boolean) {
let description = 'You have no unread messages';
let text;
if (mentionCount > 0) {
text = (mentionCount > MAX_WIN_COUNT) ? `${MAX_WIN_COUNT}+` : mentionCount.toString();
description = `You have unread mentions (${mentionCount})`;
} else if (showUnreadBadge && showUnreadBadgeSetting) {
text = '•';
description = 'You have unread channels';
} else if (sessionExpired) {
text = '•';
description = 'Session Expired: Please sign in to continue receiving notifications.';
}
WindowManager.setOverlayIcon(text, description, mentionCount > 99);
}
export function showBadgeOSX(sessionExpired: boolean, mentionCount: number, showUnreadBadge: boolean) {
let badge = '';
if (mentionCount > 0) {
badge = mentionCount.toString();
} else if (showUnreadBadge && showUnreadBadgeSetting) {
badge = '•';
} else if (sessionExpired) {
badge = '•';
}
app.dock.setBadge(badge);
}
function showBadgeLinux(sessionExpired: boolean, mentionCount: number) {
if (app.isUnityRunning()) {
const countExpired = sessionExpired ? 1 : 0;
app.setBadgeCount(mentionCount + countExpired);
}
}
function showBadge(sessionExpired: boolean, mentionCount: number, showUnreadBadge: boolean) {
log.silly('Badge.showBadge', {sessionExpired, mentionCount, showUnreadBadge});
switch (process.platform) {
case 'win32':
showBadgeWindows(sessionExpired, mentionCount, showUnreadBadge);
break;
case 'darwin':
showBadgeOSX(sessionExpired, mentionCount, showUnreadBadge);
break;
case 'linux':
showBadgeLinux(sessionExpired, mentionCount);
break;
}
}
export function setUnreadBadgeSetting(showUnreadBadge: boolean) {
showUnreadBadgeSetting = showUnreadBadge;
AppState.updateBadge();
}
export function setupBadge() {
AppState.on(UPDATE_BADGE, showBadge);
}