Skip to content

Commit 55805f1

Browse files
committed
fix(System tray): Add macOS dark theme system tray icon
Fixes #1
1 parent c62f3fc commit 55805f1

File tree

9 files changed

+17
-10
lines changed

9 files changed

+17
-10
lines changed
396 Bytes
Loading
1.26 KB
Loading
424 Bytes
Loading
1.33 KB
Loading
424 Bytes
Loading
1.33 KB
Loading
396 Bytes
Loading
1.26 KB
Loading

src/lib/Tray.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
import { app, Tray, Menu } from 'electron';
1+
import { app, Tray, Menu, systemPreferences } from 'electron';
22
import path from 'path';
33

44
const FILE_EXTENSION = process.platform === 'win32' ? 'ico' : 'png';
55
const INDICATOR_TRAY_PLAIN = 'tray';
66
const INDICATOR_TRAY_UNREAD = 'tray-unread';
77

8-
function getAsset(type, asset) {
9-
return path.join(
10-
__dirname, '..', 'assets', 'images', type, process.platform, `${asset}.${FILE_EXTENSION}`,
11-
);
12-
}
13-
148
export default class TrayIcon {
159
mainWindow = null;
1610
trayIcon = null;
@@ -20,7 +14,7 @@ export default class TrayIcon {
2014
}
2115

2216
show() {
23-
this.trayIcon = new Tray(getAsset('tray', INDICATOR_TRAY_PLAIN));
17+
this.trayIcon = new Tray(this._getAsset('tray', INDICATOR_TRAY_PLAIN));
2418
const trayMenuTemplate = [
2519
{
2620
label: 'Show Franz',
@@ -53,12 +47,25 @@ export default class TrayIcon {
5347
setIndicator(indicator) {
5448
if (!this.trayIcon) return;
5549

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));
5751

5852
if (process.platform === 'darwin') {
5953
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`),
6155
);
6256
}
6357
}
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+
}
6471
}

0 commit comments

Comments
 (0)