diff options
Diffstat (limited to 'src/electron/ipc-api/appIndicator.js')
-rw-r--r-- | src/electron/ipc-api/appIndicator.js | 45 |
1 files changed, 13 insertions, 32 deletions
diff --git a/src/electron/ipc-api/appIndicator.js b/src/electron/ipc-api/appIndicator.js index 576234d25..d31819068 100644 --- a/src/electron/ipc-api/appIndicator.js +++ b/src/electron/ipc-api/appIndicator.js | |||
@@ -1,12 +1,11 @@ | |||
1 | import { app, ipcMain, Tray, Menu } from 'electron'; | 1 | import { app, ipcMain } from 'electron'; |
2 | import path from 'path'; | 2 | import path from 'path'; |
3 | import { autorun } from 'mobx'; | ||
3 | 4 | ||
4 | const INDICATOR_TRAY_PLAIN = 'tray'; | ||
5 | const INDICATOR_TRAY_UNREAD = 'tray-unread'; | ||
6 | const INDICATOR_TASKBAR = 'taskbar'; | 5 | const INDICATOR_TASKBAR = 'taskbar'; |
7 | |||
8 | const FILE_EXTENSION = process.platform === 'win32' ? 'ico' : 'png'; | 6 | const FILE_EXTENSION = process.platform === 'win32' ? 'ico' : 'png'; |
9 | let trayIcon; | 7 | |
8 | let isTrayIconEnabled; | ||
10 | 9 | ||
11 | function getAsset(type, asset) { | 10 | function getAsset(type, asset) { |
12 | return path.join( | 11 | return path.join( |
@@ -15,26 +14,14 @@ function getAsset(type, asset) { | |||
15 | } | 14 | } |
16 | 15 | ||
17 | export default (params) => { | 16 | export default (params) => { |
18 | trayIcon = new Tray(getAsset('tray', INDICATOR_TRAY_PLAIN)); | 17 | autorun(() => { |
19 | const trayMenuTemplate = [ | 18 | isTrayIconEnabled = params.settings.get('enableSystemTray'); |
20 | { | ||
21 | label: 'Show Franz', | ||
22 | click() { | ||
23 | params.mainWindow.show(); | ||
24 | }, | ||
25 | }, { | ||
26 | label: 'Quit Franz', | ||
27 | click() { | ||
28 | app.quit(); | ||
29 | }, | ||
30 | }, | ||
31 | ]; | ||
32 | |||
33 | const trayMenu = Menu.buildFromTemplate(trayMenuTemplate); | ||
34 | trayIcon.setContextMenu(trayMenu); | ||
35 | 19 | ||
36 | trayIcon.on('click', () => { | 20 | if (!isTrayIconEnabled) { |
37 | params.mainWindow.show(); | 21 | params.trayIcon.hide(); |
22 | } else if (isTrayIconEnabled) { | ||
23 | params.trayIcon.show(); | ||
24 | } | ||
38 | }); | 25 | }); |
39 | 26 | ||
40 | ipcMain.on('updateAppIndicator', (event, args) => { | 27 | ipcMain.on('updateAppIndicator', (event, args) => { |
@@ -68,13 +55,7 @@ export default (params) => { | |||
68 | } | 55 | } |
69 | } | 56 | } |
70 | 57 | ||
71 | // Update system tray | 58 | // Update Tray |
72 | trayIcon.setImage(getAsset('tray', args.indicator !== 0 ? INDICATOR_TRAY_UNREAD : INDICATOR_TRAY_PLAIN)); | 59 | params.trayIcon.setIndicator(args.indicator); |
73 | |||
74 | if (process.platform === 'darwin') { | ||
75 | trayIcon.setPressedImage( | ||
76 | getAsset('tray', `${args.indicator !== 0 ? INDICATOR_TRAY_UNREAD : INDICATOR_TRAY_PLAIN}-active`), | ||
77 | ); | ||
78 | } | ||
79 | }); | 60 | }); |
80 | }; | 61 | }; |