diff options
author | 2017-10-27 14:00:05 -0400 | |
---|---|---|
committer | 2017-10-27 14:00:05 -0400 | |
commit | c007ee31bbe56d44b69b4122c715caabe68efcb5 (patch) | |
tree | 6f82a8cad1bf28655f7abca2c39599eac59c39d0 /src/lib/Tray.js | |
parent | Merge pull request #152 from meetfranz/chore/travis-setup (diff) | |
download | ferdium-app-c007ee31bbe56d44b69b4122c715caabe68efcb5.tar.gz ferdium-app-c007ee31bbe56d44b69b4122c715caabe68efcb5.tar.zst ferdium-app-c007ee31bbe56d44b69b4122c715caabe68efcb5.zip |
Change tray icon on mac theme change
Diffstat (limited to 'src/lib/Tray.js')
-rw-r--r-- | src/lib/Tray.js | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/lib/Tray.js b/src/lib/Tray.js index 525ce592e..2efe71a71 100644 --- a/src/lib/Tray.js +++ b/src/lib/Tray.js | |||
@@ -7,6 +7,8 @@ const INDICATOR_TRAY_UNREAD = 'tray-unread'; | |||
7 | 7 | ||
8 | export default class TrayIcon { | 8 | export default class TrayIcon { |
9 | trayIcon = null; | 9 | trayIcon = null; |
10 | indicator = 0; | ||
11 | themeChangeSubscriberId = null; | ||
10 | 12 | ||
11 | show() { | 13 | show() { |
12 | if (this.trayIcon) return; | 14 | if (this.trayIcon) return; |
@@ -32,28 +34,43 @@ export default class TrayIcon { | |||
32 | this.trayIcon.on('click', () => { | 34 | this.trayIcon.on('click', () => { |
33 | app.mainWindow.show(); | 35 | app.mainWindow.show(); |
34 | }); | 36 | }); |
37 | |||
38 | if (process.platform === 'darwin') { | ||
39 | this.themeChangeSubscriberId = systemPreferences.subscribeNotification('AppleInterfaceThemeChangedNotification', () => { | ||
40 | this._refreshIcon(); | ||
41 | }); | ||
42 | } | ||
35 | } | 43 | } |
36 | 44 | ||
37 | hide() { | 45 | hide() { |
38 | if (this.trayIcon) { | 46 | if (!this.trayIcon) return; |
39 | this.trayIcon.destroy(); | 47 | |
40 | 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; | ||
41 | } | 54 | } |
42 | } | 55 | } |
43 | 56 | ||
44 | setIndicator(indicator) { | 57 | setIndicator(indicator) { |
58 | this.indicator = indicator; | ||
59 | this._refreshIcon(); | ||
60 | } | ||
61 | |||
62 | _refreshIcon() { | ||
45 | if (!this.trayIcon) return; | 63 | if (!this.trayIcon) return; |
46 | 64 | ||
47 | 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)); |
48 | 66 | ||
49 | if (process.platform === 'darwin') { | 67 | if (process.platform === 'darwin') { |
50 | this.trayIcon.setPressedImage( | 68 | this.trayIcon.setPressedImage( |
51 | 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`), |
52 | ); | 70 | ); |
53 | } | 71 | } |
54 | } | 72 | } |
55 | 73 | ||
56 | |||
57 | _getAsset(type, asset) { | 74 | _getAsset(type, asset) { |
58 | let platform = process.platform; | 75 | let platform = process.platform; |
59 | 76 | ||