@@ -22,7 +22,10 @@ public partial class TaskbarUsageResources
22
22
private readonly static PrivateFontCollection PrivateFontCollection = new ( ) ;
23
23
24
24
private static Timer UpdateTimer ;
25
- private readonly Image _iconImage ;
25
+ private Image _iconImage ;
26
+
27
+ private string assetsPath ;
28
+ private string iconImagePath ;
26
29
27
30
28
31
static TaskbarUsageResources ( )
@@ -37,12 +40,15 @@ public TaskbarUsageResources()
37
40
{
38
41
InitializeComponent ( ) ;
39
42
UpdateSetupStartupProgramMenuFLyoutItemTextProperty ( ) ;
43
+ UpdateSetupColorMenuFlyoutItemTextProperty ( ) ;
40
44
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 ) ;
43
47
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 ) ;
46
52
47
53
_iconImage = Image . FromFile ( iconImagePath ) . GetThumbnailImage ( TrayIconSize , TrayIconSize , null , IntPtr . Zero ) ;
48
54
Update ( ) ;
@@ -65,15 +71,23 @@ private void UpdateSetupStartupProgramMenuFLyoutItemTextProperty()
65
71
else MenuFlyoutItemSetupStartupProgram . Text = "Add to Startup" ;
66
72
}
67
73
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
+
68
81
[ LibraryImport ( "user32.dll" ) ]
69
82
[ return : MarshalAs ( UnmanagedType . Bool ) ]
70
83
private static partial bool DestroyIcon ( IntPtr handle ) ;
71
84
72
85
private void Update ( )
73
86
{
74
87
var lastUsageTarget = Configuration . GetValue < string > ( "LastUsageTarget" ) ?? "CPU" ;
88
+ var isWhiteIcon = Configuration . GetValue < bool > ( "WhiteIcon" ) ;
75
89
76
- float usage = 0f ;
90
+ float usage = 0f ;
77
91
if ( lastUsageTarget == "CPU" ) usage = HardwareMonitor . GetAverageCpuUsage ( ) ;
78
92
else if ( lastUsageTarget == "GPU" ) usage = HardwareMonitor . GetCurrentGpuUsage ( ) ;
79
93
string usageText = GenerateUsageText ( usage ) ;
@@ -93,7 +107,7 @@ private void Update()
93
107
LineAlignment = StringAlignment . Center
94
108
} ;
95
109
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 ) ;
97
111
98
112
try
99
113
{
@@ -168,4 +182,17 @@ private void OnSetupStartupProgramMenuFlyoutItemClicked(XamlUICommand sender, Ex
168
182
StartupHelper . SetupStartupProgram ( ) ;
169
183
UpdateSetupStartupProgramMenuFLyoutItemTextProperty ( ) ;
170
184
}
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
+ }
171
198
}
0 commit comments