diff options
Diffstat (limited to 'src/lib/Tray.js')
-rw-r--r-- | src/lib/Tray.js | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/src/lib/Tray.js b/src/lib/Tray.js index 67150971e..2efe71a71 100644 --- a/src/lib/Tray.js +++ b/src/lib/Tray.js | |||
@@ -6,12 +6,9 @@ const INDICATOR_TRAY_PLAIN = 'tray'; | |||
6 | const INDICATOR_TRAY_UNREAD = 'tray-unread'; | 6 | const INDICATOR_TRAY_UNREAD = 'tray-unread'; |
7 | 7 | ||
8 | export default class TrayIcon { | 8 | export default class TrayIcon { |
9 | mainWindow = null; | ||
10 | trayIcon = null; | 9 | trayIcon = null; |
11 | 10 | indicator = 0; | |
12 | constructor(mainWindow) { | 11 | themeChangeSubscriberId = null; |
13 | this.mainWindow = mainWindow; | ||
14 | } | ||
15 | 12 | ||
16 | show() { | 13 | show() { |
17 | if (this.trayIcon) return; | 14 | if (this.trayIcon) return; |
@@ -21,7 +18,7 @@ export default class TrayIcon { | |||
21 | { | 18 | { |
22 | label: 'Show Franz', | 19 | label: 'Show Franz', |
23 | click() { | 20 | click() { |
24 | this.mainWindow.show(); | 21 | app.mainWindow.show(); |
25 | }, | 22 | }, |
26 | }, { | 23 | }, { |
27 | label: 'Quit Franz', | 24 | label: 'Quit Franz', |
@@ -35,30 +32,45 @@ export default class TrayIcon { | |||
35 | this.trayIcon.setContextMenu(trayMenu); | 32 | this.trayIcon.setContextMenu(trayMenu); |
36 | 33 | ||
37 | this.trayIcon.on('click', () => { | 34 | this.trayIcon.on('click', () => { |
38 | this.mainWindow.show(); | 35 | app.mainWindow.show(); |
39 | }); | 36 | }); |
37 | |||
38 | if (process.platform === 'darwin') { | ||
39 | this.themeChangeSubscriberId = systemPreferences.subscribeNotification('AppleInterfaceThemeChangedNotification', () => { | ||
40 | this._refreshIcon(); | ||
41 | }); | ||
42 | } | ||
40 | } | 43 | } |
41 | 44 | ||
42 | hide() { | 45 | hide() { |
43 | if (this.trayIcon) { | 46 | if (!this.trayIcon) return; |
44 | this.trayIcon.destroy(); | 47 | |
45 | this.trayIcon = null; | 48 | this.trayIcon.destroy(); |
49 | this.trayIcon = null; | ||
50 | |||
51 | if (process.platform === 'darwin' && this.themeChangeSubscriberId) { | ||
52 | systemPreferences.unsubscribeNotification(this.themeChangeSubscriberId); | ||
53 | this.themeChangeSubscriberId = null; | ||
46 | } | 54 | } |
47 | } | 55 | } |
48 | 56 | ||
49 | setIndicator(indicator) { | 57 | setIndicator(indicator) { |
58 | this.indicator = indicator; | ||
59 | this._refreshIcon(); | ||
60 | } | ||
61 | |||
62 | _refreshIcon() { | ||
50 | if (!this.trayIcon) return; | 63 | if (!this.trayIcon) return; |
51 | 64 | ||
52 | this.trayIcon.setImage(this._getAsset('tray', indicator !== 0 ? INDICATOR_TRAY_UNREAD : INDICATOR_TRAY_PLAIN)); | 65 | this.trayIcon.setImage(this._getAsset('tray', this.indicator !== 0 ? INDICATOR_TRAY_UNREAD : INDICATOR_TRAY_PLAIN)); |
53 | 66 | ||
54 | if (process.platform === 'darwin') { | 67 | if (process.platform === 'darwin') { |
55 | this.trayIcon.setPressedImage( | 68 | this.trayIcon.setPressedImage( |
56 | this._getAsset('tray', `${indicator !== 0 ? INDICATOR_TRAY_UNREAD : INDICATOR_TRAY_PLAIN}-active`), | 69 | this._getAsset('tray', `${this.indicator !== 0 ? INDICATOR_TRAY_UNREAD : INDICATOR_TRAY_PLAIN}-active`), |
57 | ); | 70 | ); |
58 | } | 71 | } |
59 | } | 72 | } |
60 | 73 | ||
61 | |||
62 | _getAsset(type, asset) { | 74 | _getAsset(type, asset) { |
63 | let platform = process.platform; | 75 | let platform = process.platform; |
64 | 76 | ||