Skip to content
Permalink
Browse files
fix(System tray): Add macOS dark theme system tray icon
Fixes #1
  • Loading branch information
adlk committed Oct 19, 2017
1 parent c62f3fc commit 55805f1d8fba4d1e96dba3ef02ec56c5de349778
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,16 +1,10 @@
import { app, Tray, Menu } from 'electron';
import { app, Tray, Menu, systemPreferences } from 'electron';
import path from 'path';

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

function getAsset(type, asset) {
return path.join(
__dirname, '..', 'assets', 'images', type, process.platform, `${asset}.${FILE_EXTENSION}`,
);
}

export default class TrayIcon {
mainWindow = null;
trayIcon = null;
@@ -20,7 +14,7 @@ export default class TrayIcon {
}

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

this.trayIcon.setImage(getAsset('tray', indicator !== 0 ? INDICATOR_TRAY_UNREAD : INDICATOR_TRAY_PLAIN));
this.trayIcon.setImage(this._getAsset('tray', indicator !== 0 ? INDICATOR_TRAY_UNREAD : INDICATOR_TRAY_PLAIN));

if (process.platform === 'darwin') {
this.trayIcon.setPressedImage(
getAsset('tray', `${indicator !== 0 ? INDICATOR_TRAY_UNREAD : INDICATOR_TRAY_PLAIN}-active`),
this._getAsset('tray', `${indicator !== 0 ? INDICATOR_TRAY_UNREAD : INDICATOR_TRAY_PLAIN}-active`),
);
}
}


_getAsset(type, asset) {
let platform = process.platform;

if (platform === 'darwin' && systemPreferences.isDarkMode()) {
platform = `${platform}-dark`;
}

return path.join(
__dirname, '..', 'assets', 'images', type, platform, `${asset}.${FILE_EXTENSION}`,
);
}
}

0 comments on commit 55805f1

Please sign in to comment.