@@ -22,7 +22,10 @@ public partial class TaskbarUsageResources
2222 private readonly static PrivateFontCollection PrivateFontCollection = new ( ) ;
2323
2424 private static Timer UpdateTimer ;
25- private readonly Image _iconImage ;
25+ private Image _iconImage ;
26+
27+ private string assetsPath ;
28+ private string iconImagePath ;
2629
2730
2831 static TaskbarUsageResources ( )
@@ -37,12 +40,15 @@ public TaskbarUsageResources()
3740 {
3841 InitializeComponent ( ) ;
3942 UpdateSetupStartupProgramMenuFLyoutItemTextProperty ( ) ;
43+ UpdateSetupColorMenuFlyoutItemTextProperty ( ) ;
4044
41- // TODO: add a setting to change the interval of the timer.
42- UpdateTimer = new ( UpdateTimerCallback , null , UpdateTimerInterval , Timeout . Infinite ) ;
45+ // TODO: add a setting to change the interval of the timer.
46+ UpdateTimer = new ( UpdateTimerCallback , null , UpdateTimerInterval , Timeout . Infinite ) ;
4347
44- var assetsPath = Path . Combine ( BinaryDirectory , "Assets" ) ;
45- var iconImagePath = Path . Combine ( assetsPath , "cpu.png" ) ;
48+ assetsPath = Path . Combine ( BinaryDirectory , "Assets" ) ;
49+ var isWhiteIcon = Configuration . GetValue < bool > ( "WhiteIcon" ) ;
50+ var _imageFileName = ( isWhiteIcon ? "Cpu_white.png" : "Cpu.png" ) ;
51+ iconImagePath = Path . Combine ( assetsPath , _imageFileName ) ;
4652
4753 _iconImage = Image . FromFile ( iconImagePath ) . GetThumbnailImage ( TrayIconSize , TrayIconSize , null , IntPtr . Zero ) ;
4854 Update ( ) ;
@@ -65,15 +71,23 @@ private void UpdateSetupStartupProgramMenuFLyoutItemTextProperty()
6571 else MenuFlyoutItemSetupStartupProgram . Text = "Add to Startup" ;
6672 }
6773
74+ private void UpdateSetupColorMenuFlyoutItemTextProperty ( )
75+ {
76+ var isWhiteIcon = Configuration . GetValue < bool > ( "WhiteIcon" ) ;
77+ MenuFlyoutItemSetupColor . Text = ( isWhiteIcon ) ? "Change to Black Icon" : "Change to White Icon" ;
78+
79+ }
80+
6881 [ LibraryImport ( "user32.dll" ) ]
6982 [ return : MarshalAs ( UnmanagedType . Bool ) ]
7083 private static partial bool DestroyIcon ( IntPtr handle ) ;
7184
7285 private void Update ( )
7386 {
7487 var lastUsageTarget = Configuration . GetValue < string > ( "LastUsageTarget" ) ?? "CPU" ;
88+ var isWhiteIcon = Configuration . GetValue < bool > ( "WhiteIcon" ) ;
7589
76- float usage = 0f ;
90+ float usage = 0f ;
7791 if ( lastUsageTarget == "CPU" ) usage = HardwareMonitor . GetAverageCpuUsage ( ) ;
7892 else if ( lastUsageTarget == "GPU" ) usage = HardwareMonitor . GetCurrentGpuUsage ( ) ;
7993 string usageText = GenerateUsageText ( usage ) ;
@@ -93,7 +107,7 @@ private void Update()
93107 LineAlignment = StringAlignment . Center
94108 } ;
95109 var rect = new RectangleF ( 0 , 2 , image . Width , image . Height ) ;
96- graphics . DrawString ( usageText , font , Brushes . Black , rect , stringFormat ) ;
110+ graphics . DrawString ( usageText , font , ( isWhiteIcon ) ? Brushes . White : Brushes . Black , rect , stringFormat ) ;
97111
98112 try
99113 {
@@ -168,4 +182,17 @@ private void OnSetupStartupProgramMenuFlyoutItemClicked(XamlUICommand sender, Ex
168182 StartupHelper . SetupStartupProgram ( ) ;
169183 UpdateSetupStartupProgramMenuFLyoutItemTextProperty ( ) ;
170184 }
185+
186+ private void OnSetupColorMenuFlyoutItemClicked ( XamlUICommand sender , ExecuteRequestedEventArgs args )
187+ {
188+ var isWhiteIcon = Configuration . GetValue < bool > ( "WhiteIcon" ) ;
189+ Configuration . SetValue ( "WhiteIcon" , ! isWhiteIcon ) ;
190+ isWhiteIcon = ! isWhiteIcon ;
191+ UpdateSetupColorMenuFlyoutItemTextProperty ( ) ;
192+
193+ var _imageFileName = ( isWhiteIcon ? "Cpu_white.png" : "Cpu.png" ) ;
194+ iconImagePath = Path . Combine ( assetsPath , _imageFileName ) ;
195+ _iconImage = Image . FromFile ( iconImagePath ) . GetThumbnailImage ( TrayIconSize , TrayIconSize , null , IntPtr . Zero ) ;
196+
197+ }
171198}
0 commit comments