From ef503a1e29a540c7318efb5f2018efbf00706198 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Thu, 19 Oct 2017 11:15:25 +0200 Subject: Add option to disable system tray icon --- src/lib/Tray.js | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/lib/Tray.js (limited to 'src/lib/Tray.js') diff --git a/src/lib/Tray.js b/src/lib/Tray.js new file mode 100644 index 000000000..631342b24 --- /dev/null +++ b/src/lib/Tray.js @@ -0,0 +1,64 @@ +import { app, Tray, Menu } 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; + + constructor(mainWindow) { + this.mainWindow = mainWindow; + } + + show() { + this.trayIcon = new Tray(getAsset('tray', INDICATOR_TRAY_PLAIN)); + const trayMenuTemplate = [ + { + label: 'Show Franz', + click() { + this.mainWindow.show(); + }, + }, { + label: 'Quit Franz', + click() { + app.quit(); + }, + }, + ]; + + const trayMenu = Menu.buildFromTemplate(trayMenuTemplate); + this.trayIcon.setContextMenu(trayMenu); + + this.trayIcon.on('click', () => { + this.mainWindow.show(); + }); + } + + hide() { + if (this.trayIcon) { + this.trayIcon.destroy(); + this.trayIcon = null; + } + } + + setIndicator(indicator) { + if (!this.trayIcon) return; + + this.trayIcon.setImage(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`), + ); + } + } +} -- cgit v1.2.3-70-g09d2 From 55805f1d8fba4d1e96dba3ef02ec56c5de349778 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Thu, 19 Oct 2017 16:18:10 +0200 Subject: fix(System tray): Add macOS dark theme system tray icon Fixes #1 --- src/assets/images/tray/darwin-dark/tray-active.png | Bin 0 -> 396 bytes .../images/tray/darwin-dark/tray-active@2x.png | Bin 0 -> 1291 bytes .../images/tray/darwin-dark/tray-unread-active.png | Bin 0 -> 424 bytes .../tray/darwin-dark/tray-unread-active@2x.png | Bin 0 -> 1359 bytes src/assets/images/tray/darwin-dark/tray-unread.png | Bin 0 -> 424 bytes .../images/tray/darwin-dark/tray-unread@2x.png | Bin 0 -> 1359 bytes src/assets/images/tray/darwin-dark/tray.png | Bin 0 -> 396 bytes src/assets/images/tray/darwin-dark/tray@2x.png | Bin 0 -> 1291 bytes src/lib/Tray.js | 27 +++++++++++++-------- 9 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 src/assets/images/tray/darwin-dark/tray-active.png create mode 100644 src/assets/images/tray/darwin-dark/tray-active@2x.png create mode 100644 src/assets/images/tray/darwin-dark/tray-unread-active.png create mode 100644 src/assets/images/tray/darwin-dark/tray-unread-active@2x.png create mode 100644 src/assets/images/tray/darwin-dark/tray-unread.png create mode 100644 src/assets/images/tray/darwin-dark/tray-unread@2x.png create mode 100644 src/assets/images/tray/darwin-dark/tray.png create mode 100644 src/assets/images/tray/darwin-dark/tray@2x.png (limited to 'src/lib/Tray.js') diff --git a/src/assets/images/tray/darwin-dark/tray-active.png b/src/assets/images/tray/darwin-dark/tray-active.png new file mode 100644 index 000000000..489533dbf Binary files /dev/null and b/src/assets/images/tray/darwin-dark/tray-active.png differ diff --git a/src/assets/images/tray/darwin-dark/tray-active@2x.png b/src/assets/images/tray/darwin-dark/tray-active@2x.png new file mode 100644 index 000000000..76f212b52 Binary files /dev/null and b/src/assets/images/tray/darwin-dark/tray-active@2x.png differ diff --git a/src/assets/images/tray/darwin-dark/tray-unread-active.png b/src/assets/images/tray/darwin-dark/tray-unread-active.png new file mode 100644 index 000000000..e2fd1a822 Binary files /dev/null and b/src/assets/images/tray/darwin-dark/tray-unread-active.png differ diff --git a/src/assets/images/tray/darwin-dark/tray-unread-active@2x.png b/src/assets/images/tray/darwin-dark/tray-unread-active@2x.png new file mode 100644 index 000000000..9a64b3ef8 Binary files /dev/null and b/src/assets/images/tray/darwin-dark/tray-unread-active@2x.png differ diff --git a/src/assets/images/tray/darwin-dark/tray-unread.png b/src/assets/images/tray/darwin-dark/tray-unread.png new file mode 100644 index 000000000..e2fd1a822 Binary files /dev/null and b/src/assets/images/tray/darwin-dark/tray-unread.png differ diff --git a/src/assets/images/tray/darwin-dark/tray-unread@2x.png b/src/assets/images/tray/darwin-dark/tray-unread@2x.png new file mode 100644 index 000000000..9a64b3ef8 Binary files /dev/null and b/src/assets/images/tray/darwin-dark/tray-unread@2x.png differ diff --git a/src/assets/images/tray/darwin-dark/tray.png b/src/assets/images/tray/darwin-dark/tray.png new file mode 100644 index 000000000..489533dbf Binary files /dev/null and b/src/assets/images/tray/darwin-dark/tray.png differ diff --git a/src/assets/images/tray/darwin-dark/tray@2x.png b/src/assets/images/tray/darwin-dark/tray@2x.png new file mode 100644 index 000000000..76f212b52 Binary files /dev/null and b/src/assets/images/tray/darwin-dark/tray@2x.png differ 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 @@ -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}`, + ); + } } -- cgit v1.2.3-70-g09d2 From 5b9b0c76a0378fa06de22cb42efa1d9bf8cb02a3 Mon Sep 17 00:00:00 2001 From: Stefan Date: Tue, 24 Oct 2017 16:42:51 +0200 Subject: fix(Windows): Fix multiple system tray icons when opening/closing Franz --- src/lib/Tray.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/lib/Tray.js') diff --git a/src/lib/Tray.js b/src/lib/Tray.js index ca6131c0c..67150971e 100644 --- a/src/lib/Tray.js +++ b/src/lib/Tray.js @@ -14,6 +14,8 @@ export default class TrayIcon { } show() { + if (this.trayIcon) return; + this.trayIcon = new Tray(this._getAsset('tray', INDICATOR_TRAY_PLAIN)); const trayMenuTemplate = [ { -- cgit v1.2.3-70-g09d2