diff options
Diffstat (limited to 'src/lib/Tray.js')
-rw-r--r-- | src/lib/Tray.js | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/lib/Tray.js b/src/lib/Tray.js index 631342b24..ca6131c0c 100644 --- a/src/lib/Tray.js +++ b/src/lib/Tray.js | |||
@@ -1,16 +1,10 @@ | |||
1 | import { app, Tray, Menu } from 'electron'; | 1 | import { app, Tray, Menu, systemPreferences } from 'electron'; |
2 | import path from 'path'; | 2 | import path from 'path'; |
3 | 3 | ||
4 | const FILE_EXTENSION = process.platform === 'win32' ? 'ico' : 'png'; | 4 | const FILE_EXTENSION = process.platform === 'win32' ? 'ico' : 'png'; |
5 | const INDICATOR_TRAY_PLAIN = 'tray'; | 5 | const INDICATOR_TRAY_PLAIN = 'tray'; |
6 | const INDICATOR_TRAY_UNREAD = 'tray-unread'; | 6 | const INDICATOR_TRAY_UNREAD = 'tray-unread'; |
7 | 7 | ||
8 | function getAsset(type, asset) { | ||
9 | return path.join( | ||
10 | __dirname, '..', 'assets', 'images', type, process.platform, `${asset}.${FILE_EXTENSION}`, | ||
11 | ); | ||
12 | } | ||
13 | |||
14 | export default class TrayIcon { | 8 | export default class TrayIcon { |
15 | mainWindow = null; | 9 | mainWindow = null; |
16 | trayIcon = null; | 10 | trayIcon = null; |
@@ -20,7 +14,7 @@ export default class TrayIcon { | |||
20 | } | 14 | } |
21 | 15 | ||
22 | show() { | 16 | show() { |
23 | this.trayIcon = new Tray(getAsset('tray', INDICATOR_TRAY_PLAIN)); | 17 | this.trayIcon = new Tray(this._getAsset('tray', INDICATOR_TRAY_PLAIN)); |
24 | const trayMenuTemplate = [ | 18 | const trayMenuTemplate = [ |
25 | { | 19 | { |
26 | label: 'Show Franz', | 20 | label: 'Show Franz', |
@@ -53,12 +47,25 @@ export default class TrayIcon { | |||
53 | setIndicator(indicator) { | 47 | setIndicator(indicator) { |
54 | if (!this.trayIcon) return; | 48 | if (!this.trayIcon) return; |
55 | 49 | ||
56 | this.trayIcon.setImage(getAsset('tray', indicator !== 0 ? INDICATOR_TRAY_UNREAD : INDICATOR_TRAY_PLAIN)); | 50 | this.trayIcon.setImage(this._getAsset('tray', indicator !== 0 ? INDICATOR_TRAY_UNREAD : INDICATOR_TRAY_PLAIN)); |
57 | 51 | ||
58 | if (process.platform === 'darwin') { | 52 | if (process.platform === 'darwin') { |
59 | this.trayIcon.setPressedImage( | 53 | this.trayIcon.setPressedImage( |
60 | getAsset('tray', `${indicator !== 0 ? INDICATOR_TRAY_UNREAD : INDICATOR_TRAY_PLAIN}-active`), | 54 | this._getAsset('tray', `${indicator !== 0 ? INDICATOR_TRAY_UNREAD : INDICATOR_TRAY_PLAIN}-active`), |
61 | ); | 55 | ); |
62 | } | 56 | } |
63 | } | 57 | } |
58 | |||
59 | |||
60 | _getAsset(type, asset) { | ||
61 | let platform = process.platform; | ||
62 | |||
63 | if (platform === 'darwin' && systemPreferences.isDarkMode()) { | ||
64 | platform = `${platform}-dark`; | ||
65 | } | ||
66 | |||
67 | return path.join( | ||
68 | __dirname, '..', 'assets', 'images', type, platform, `${asset}.${FILE_EXTENSION}`, | ||
69 | ); | ||
70 | } | ||
64 | } | 71 | } |