1- import { app , Tray , Menu } from 'electron' ;
1+ import { app , Tray , Menu , systemPreferences } from 'electron' ;
22import path from 'path' ;
33
44const FILE_EXTENSION = process . platform === 'win32' ? 'ico' : 'png' ;
55const INDICATOR_TRAY_PLAIN = 'tray' ;
66const 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-
148export 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