aboutsummaryrefslogtreecommitdiffstats
path: root/src/electron/ipc-api/appIndicator.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/electron/ipc-api/appIndicator.ts')
-rw-r--r--src/electron/ipc-api/appIndicator.ts83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/electron/ipc-api/appIndicator.ts b/src/electron/ipc-api/appIndicator.ts
new file mode 100644
index 000000000..5b5f2bac7
--- /dev/null
+++ b/src/electron/ipc-api/appIndicator.ts
@@ -0,0 +1,83 @@
1import { app, ipcMain } from 'electron';
2import { join } from 'path';
3import { autorun } from 'mobx';
4import { isMac, isWindows, isLinux } from '../../environment';
5
6const INDICATOR_TASKBAR = 'taskbar';
7const FILE_EXTENSION = isWindows ? 'ico' : 'png';
8
9let isTrayIconEnabled: boolean;
10
11function getAsset(type: 'tray' | 'taskbar', asset: string) {
12 return join(
13 __dirname,
14 '..',
15 '..',
16 'assets',
17 'images',
18 type,
19 process.platform,
20 `${asset}.${FILE_EXTENSION}`,
21 );
22}
23
24export default params => {
25 autorun(() => {
26 isTrayIconEnabled = params.settings.app.get('enableSystemTray');
27
28 if (!isTrayIconEnabled) {
29 params.trayIcon.hide();
30 } else if (isTrayIconEnabled) {
31 params.trayIcon.show();
32 }
33 });
34
35 ipcMain.on('updateAppIndicator', (_event, args) => {
36 // Flash TaskBar for windows, bounce Dock on Mac
37 if (!(app as any).mainWindow.isFocused()) {
38 if (params.settings.app.get('notifyTaskBarOnMessage')) {
39 if (isWindows) {
40 (app as any).mainWindow.flashFrame(true);
41 (app as any).mainWindow.once('focus', () =>
42 (app as any).mainWindow.flashFrame(false),
43 );
44 } else if (isMac) {
45 app.dock.bounce('informational');
46 }
47 }
48 }
49
50 // Update badge
51 if (isMac && typeof args.indicator === 'string') {
52 app.dock.setBadge(args.indicator);
53 }
54
55 if ((isMac || isLinux) && typeof args.indicator === 'number') {
56 app.badgeCount = args.indicator;
57 }
58
59 if (isWindows) {
60 if (typeof args.indicator === 'number' && args.indicator !== 0) {
61 params.mainWindow.setOverlayIcon(
62 getAsset(
63 'taskbar',
64 `${INDICATOR_TASKBAR}-${
65 args.indicator >= 10 ? 10 : args.indicator
66 }`,
67 ),
68 '',
69 );
70 } else if (typeof args.indicator === 'string') {
71 params.mainWindow.setOverlayIcon(
72 getAsset('taskbar', `${INDICATOR_TASKBAR}-alert`),
73 '',
74 );
75 } else {
76 params.mainWindow.setOverlayIcon(null, '');
77 }
78 }
79
80 // Update Tray
81 params.trayIcon.setIndicator(args.indicator);
82 });
83};