Skip to content

Commit

Permalink
fix(System tray): Add macOS dark theme system tray icon
Browse files Browse the repository at this point in the history
Fixes #1
  • Loading branch information
adlk committed Oct 19, 2017
1 parent c62f3fc commit 55805f1
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 10 deletions.
Binary file added src/assets/images/tray/darwin-dark/tray-active.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/tray/darwin-dark/tray-unread.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/tray/darwin-dark/tray.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/tray/darwin-dark/tray@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 17 additions & 10 deletions src/lib/Tray.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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',
Expand Down Expand Up @@ -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.