1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
import { app, ipcMain } from 'electron';
import path from 'path';
import { autorun } from 'mobx';
const INDICATOR_TASKBAR = 'taskbar';
const FILE_EXTENSION = process.platform === 'win32' ? 'ico' : 'png';
let isTrayIconEnabled;
function getAsset(type, asset) {
return path.join(
__dirname, '..', '..', 'assets', 'images', type, process.platform, `${asset}.${FILE_EXTENSION}`,
);
}
export default (params) => {
autorun(() => {
isTrayIconEnabled = params.settings.get('enableSystemTray');
if (!isTrayIconEnabled) {
params.trayIcon.hide();
} else if (isTrayIconEnabled) {
params.trayIcon.show();
}
});
ipcMain.on('updateAppIndicator', (event, args) => {
// Update badge
if (process.platform === 'darwin'
&& typeof (args.indicator) === 'string') {
app.dock.setBadge(args.indicator);
}
if ((process.platform === 'darwin'
|| process.platform === 'linux')
&& typeof (args.indicator) === 'number'
) {
app.setBadgeCount(args.indicator);
}
if (process.platform === 'win32') {
if (typeof args.indicator === 'number'
&& args.indicator !== 0) {
params.mainWindow.setOverlayIcon(
getAsset('taskbar', `${INDICATOR_TASKBAR}-${(args.indicator >= 10 ? 10 : args.indicator)}`),
'',
);
} else if (typeof args.indicator === 'string') {
params.mainWindow.setOverlayIcon(
getAsset('taskbar', `${INDICATOR_TASKBAR}-alert`),
'',
);
} else {
params.mainWindow.setOverlayIcon(null, '');
}
}
// Update Tray
params.trayIcon.setIndicator(args.indicator);
});
};
|