diff options
Diffstat (limited to 'src/lib/Tray.js')
-rw-r--r-- | src/lib/Tray.js | 55 |
1 files changed, 42 insertions, 13 deletions
diff --git a/src/lib/Tray.js b/src/lib/Tray.js index f5970f7e7..c629e212d 100644 --- a/src/lib/Tray.js +++ b/src/lib/Tray.js | |||
@@ -1,8 +1,14 @@ | |||
1 | import { | 1 | import { |
2 | app, Menu, nativeImage, nativeTheme, systemPreferences, Tray, ipcMain, | 2 | app, |
3 | Menu, | ||
4 | nativeImage, | ||
5 | nativeTheme, | ||
6 | systemPreferences, | ||
7 | Tray, | ||
8 | ipcMain, | ||
3 | } from 'electron'; | 9 | } from 'electron'; |
4 | import { join } from 'path'; | 10 | import { join } from 'path'; |
5 | import macosVersion from 'macos-version'; | 11 | import { isMacOSVersionGreaterThanOrEqualTo } from 'macos-version'; |
6 | import { isMac, isWindows, isLinux } from '../environment'; | 12 | import { isMac, isWindows, isLinux } from '../environment'; |
7 | 13 | ||
8 | const FILE_EXTENSION = isWindows ? 'ico' : 'png'; | 14 | const FILE_EXTENSION = isWindows ? 'ico' : 'png'; |
@@ -64,7 +70,9 @@ export default class TrayIcon { | |||
64 | 70 | ||
65 | if (appSettings.type === 'app') { | 71 | if (appSettings.type === 'app') { |
66 | const { isAppMuted } = appSettings.data; | 72 | const { isAppMuted } = appSettings.data; |
67 | this.trayMenuTemplate[1].label = isAppMuted ? 'Enable Notifications && Audio' : 'Disable Notifications && Audio'; | 73 | this.trayMenuTemplate[1].label = isAppMuted |
74 | ? 'Enable Notifications && Audio' | ||
75 | : 'Disable Notifications && Audio'; | ||
68 | this.trayMenu = Menu.buildFromTemplate(this.trayMenuTemplate); | 76 | this.trayMenu = Menu.buildFromTemplate(this.trayMenuTemplate); |
69 | if (isLinux) { | 77 | if (isLinux) { |
70 | this.trayIcon.setContextMenu(this.trayMenu); | 78 | this.trayIcon.setContextMenu(this.trayMenu); |
@@ -107,9 +115,12 @@ export default class TrayIcon { | |||
107 | } | 115 | } |
108 | 116 | ||
109 | if (isMac) { | 117 | if (isMac) { |
110 | this.themeChangeSubscriberId = systemPreferences.subscribeNotification('AppleInterfaceThemeChangedNotification', () => { | 118 | this.themeChangeSubscriberId = systemPreferences.subscribeNotification( |
111 | this._refreshIcon(); | 119 | 'AppleInterfaceThemeChangedNotification', |
112 | }); | 120 | () => { |
121 | this._refreshIcon(); | ||
122 | }, | ||
123 | ); | ||
113 | } | 124 | } |
114 | } | 125 | } |
115 | 126 | ||
@@ -149,7 +160,8 @@ export default class TrayIcon { | |||
149 | _getAssetFromIndicator(indicator) { | 160 | _getAssetFromIndicator(indicator) { |
150 | if (indicator === '•') { | 161 | if (indicator === '•') { |
151 | return INDICATOR_TRAY_INDIRECT; | 162 | return INDICATOR_TRAY_INDIRECT; |
152 | } if (indicator !== 0) { | 163 | } |
164 | if (indicator !== 0) { | ||
153 | return INDICATOR_TRAY_UNREAD; | 165 | return INDICATOR_TRAY_UNREAD; |
154 | } | 166 | } |
155 | return INDICATOR_TRAY_PLAIN; | 167 | return INDICATOR_TRAY_PLAIN; |
@@ -158,11 +170,16 @@ export default class TrayIcon { | |||
158 | _refreshIcon() { | 170 | _refreshIcon() { |
159 | if (!this.trayIcon) return; | 171 | if (!this.trayIcon) return; |
160 | 172 | ||
161 | this.trayIcon.setImage(this._getAsset('tray', this._getAssetFromIndicator(this.indicator))); | 173 | this.trayIcon.setImage( |
174 | this._getAsset('tray', this._getAssetFromIndicator(this.indicator)), | ||
175 | ); | ||
162 | 176 | ||
163 | if (isMac) { | 177 | if (isMac) { |
164 | this.trayIcon.setPressedImage( | 178 | this.trayIcon.setPressedImage( |
165 | this._getAsset('tray', `${this._getAssetFromIndicator(this.indicator)}-active`), | 179 | this._getAsset( |
180 | 'tray', | ||
181 | `${this._getAssetFromIndicator(this.indicator)}-active`, | ||
182 | ), | ||
166 | ); | 183 | ); |
167 | } | 184 | } |
168 | } | 185 | } |
@@ -170,12 +187,24 @@ export default class TrayIcon { | |||
170 | _getAsset(type, asset) { | 187 | _getAsset(type, asset) { |
171 | let { platform } = process; | 188 | let { platform } = process; |
172 | 189 | ||
173 | if (isMac && (nativeTheme.shouldUseDarkColors || macosVersion.isGreaterThanOrEqualTo('11'))) { | 190 | if ( |
191 | isMac && | ||
192 | (nativeTheme.shouldUseDarkColors || | ||
193 | isMacOSVersionGreaterThanOrEqualTo('11')) | ||
194 | ) { | ||
174 | platform = `${platform}-dark`; | 195 | platform = `${platform}-dark`; |
175 | } | 196 | } |
176 | 197 | ||
177 | return nativeImage.createFromPath(join( | 198 | return nativeImage.createFromPath( |
178 | __dirname, '..', 'assets', 'images', type, platform, `${asset}.${FILE_EXTENSION}`, | 199 | join( |
179 | )); | 200 | __dirname, |
201 | '..', | ||
202 | 'assets', | ||
203 | 'images', | ||
204 | type, | ||
205 | platform, | ||
206 | `${asset}.${FILE_EXTENSION}`, | ||
207 | ), | ||
208 | ); | ||
180 | } | 209 | } |
181 | } | 210 | } |