mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-12-28 09:51:06 -06:00
85a21ec4e8
* Electron-65 - Added more logs * Electron-65 - Removed some logs as per the review * Electron-65 - Removed unused log variables
54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
const electron = require('electron');
|
|
const app = electron.app;
|
|
const nativeImage = electron.nativeImage;
|
|
|
|
const { isMac } = require('./utils/misc.js');
|
|
const windowMgr = require('./windowMgr.js');
|
|
const maxCount = 1e8;
|
|
const log = require('./log.js');
|
|
const logLevels = require('./enums/logLevels.js');
|
|
|
|
function show(count) {
|
|
if (typeof count !== 'number') {
|
|
log.send(logLevels.WARN, 'badgeCount: invalid func arg, must be a number: ' + count);
|
|
return;
|
|
}
|
|
|
|
if (isMac) {
|
|
// too big of a number here and setBadgeCount crashes
|
|
app.setBadgeCount(Math.min(maxCount, count));
|
|
return;
|
|
}
|
|
|
|
// handle ms windows...
|
|
const mainWindow = windowMgr.getMainWindow();
|
|
|
|
if (mainWindow) {
|
|
if (count > 0) {
|
|
// get badge img from renderer process, will return
|
|
// img dataUrl in setDataUrl func.
|
|
mainWindow.send('createBadgeDataUrl', { count: count });
|
|
} else {
|
|
// clear badge count icon
|
|
mainWindow.setOverlayIcon(null, '');
|
|
}
|
|
}
|
|
}
|
|
|
|
function setDataUrl(dataUrl, count) {
|
|
const mainWindow = windowMgr.getMainWindow();
|
|
if (mainWindow && dataUrl && count) {
|
|
let img = nativeImage.createFromDataURL(dataUrl);
|
|
// for accessibility screen readers
|
|
const desc = 'Symphony has ' + count + ' unread messages';
|
|
mainWindow.setOverlayIcon(img, desc);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
show: show,
|
|
setDataUrl: setDataUrl
|
|
}
|