diff options
author | Stefan Malzner <stefan@adlk.io> | 2017-10-30 10:44:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-30 10:44:25 +0100 |
commit | e6ed06b6929a1394bfc6d8baf4f4a3d17f835f96 (patch) | |
tree | 8c9eac5db9a0196f36e98a893dd6d1dffb7001fc | |
parent | Merge pull request #153 from dannyqiu/fix-high-sierra-build (diff) | |
parent | Merge branch 'develop' into fix-theme-change (diff) | |
download | ferdium-app-e6ed06b6929a1394bfc6d8baf4f4a3d17f835f96.tar.gz ferdium-app-e6ed06b6929a1394bfc6d8baf4f4a3d17f835f96.tar.zst ferdium-app-e6ed06b6929a1394bfc6d8baf4f4a3d17f835f96.zip |
Merge pull request #155 from dannyqiu/fix-theme-change
Change tray icon on mac theme change
-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 | ||