@@ -122,23 +122,20 @@ private void ExecuteInUiThread(Action action) {
122122
123123 private string GetTrayIconText ( ) {
124124 return Settings . TrayIconMode switch {
125- Enums . TrayIconMode . MemoryUsageValue => ! Settings . ShowVirtualMemory
126- ? $ "Memory used:\n Physical: { computer . Memory . Physical . Used } "
127- : $ "Memory used:\n Physical: { computer . Memory . Physical . Used } \n Virtual: { computer . Memory . Virtual . Used } ",
128125 Enums . TrayIconMode . MemoryAvailable => ! Settings . ShowVirtualMemory
129126 ? $ "Memory available:\n Physical: { computer . Memory . Physical . Free } "
130127 : $ "Memory available:\n Physical: { computer . Memory . Physical . Free } \n Virtual: { computer . Memory . Virtual . Free } ",
131128 _ => ! Settings . ShowVirtualMemory
132- ? $ "Memory usage :\n Physical: { computer . Memory . Physical . Used . Percentage } % "
133- : $ "Memory usage :\n Physical: { computer . Memory . Physical . Used . Percentage } % \n Virtual: { computer . Memory . Virtual . Used . Percentage } % ",
129+ ? $ "Memory used :\n Physical: { computer . Memory . Physical . Used } "
130+ : $ "Memory used :\n Physical: { computer . Memory . Physical . Used } \n Virtual: { computer . Memory . Virtual . Used } ",
134131 } ;
135132 }
136133
137134 private void Update ( bool fetchMemoryState ) {
138135
139136 if ( fetchMemoryState && ! computer . UpdateMemoryState ( ) ) return ;
140137
141- UpdateIcon ( ) ;
138+ UpdateIcon ( fetchMemoryState ) ;
142139
143140 if ( statusMenuLabel . Visible )
144141 ExecuteInUiThread ( ( ) => { UpdateStatusMenuItem ( false ) ; } ) ;
@@ -153,42 +150,42 @@ private void SafeSetTrayIcon(Icon icon) {
153150
154151 private void UpdateIcon ( bool force = false ) {
155152
156- string newIconValue = null ;
157- switch ( Settings . TrayIconMode ) {
158- case Enums . TrayIconMode . MemoryUsageValue :
159- newIconValue = computer . Memory . Physical . Used . Value . ToTrayValue ( ) ;
160- break ;
161- case Enums . TrayIconMode . MemoryAvailable :
162- newIconValue = computer . Memory . Physical . Free . Value . ToTrayValue ( ) ;
163- break ;
164- case Enums . TrayIconMode . Image :
165- case Enums . TrayIconMode . MemoryUsagePercent :
166- default :
167- if ( Settings . TrayIconMode == Enums . TrayIconMode . MemoryUsagePercent )
168- newIconValue = $ "{ computer . Memory . Physical . Used . Percentage : 0} ";
169- break ;
170- }
171-
153+ string newIconValue = Settings . TrayIconMode switch {
154+ Enums . TrayIconMode . MemoryAvailable => computer . Memory . Physical . Free . Value . ToTrayValue ( ) ,
155+ Enums . TrayIconMode . MemoryUsageValue => computer . Memory . Physical . Used . Value . ToTrayValue ( ) ,
156+ _ => $ "{ computer . Memory . Physical . Used . Percentage : 0} ",
157+ } ;
172158 if ( ! force && string . Equals ( iconValue , newIconValue , StringComparison . OrdinalIgnoreCase ) )
173159 return ;
174-
175160 iconValue = newIconValue ;
176-
177- if ( string . IsNullOrEmpty ( iconValue ) && optimizationProgressPercentage == 0 ) {
178- SafeSetTrayIcon ( imageIcon ) ;
179- }
180- else {
181- try {
182- SafeSetTrayIcon ( optimizationProgressPercentage > 0
183- ? iconFactory . CreatePercentagePieIcon ( optimizationProgressPercentage )
184- : iconFactory . CreateTransparentIcon ( iconValue ) ) ;
161+ try {
162+ if ( optimizationProgressPercentage > 0 ) {
163+ SafeSetTrayIcon ( iconFactory . CreatePercentagePieIcon ( optimizationProgressPercentage ) ) ;
185164 }
186- catch {
187- SafeSetTrayIcon ( imageIcon ) ;
165+ else {
166+ switch ( Settings . TrayIconMode ) {
167+ case Enums . TrayIconMode . Image :
168+ SafeSetTrayIcon ( imageIcon ) ;
169+ break ;
170+ case Enums . TrayIconMode . MemoryUsageBar :
171+ SafeSetTrayIcon ( iconFactory . CreatePercentageIcon ( computer . Memory . Physical . Used . Percentage ) ) ;
172+ break ;
173+ case Enums . TrayIconMode . MemoryUsagePie :
174+ SafeSetTrayIcon ( iconFactory . CreatePercentagePieIcon ( ( byte ) computer . Memory . Physical . Used . Percentage ) ) ;
175+ break ;
176+ case Enums . TrayIconMode . MemoryUsagePercent :
177+ case Enums . TrayIconMode . MemoryUsageValue :
178+ case Enums . TrayIconMode . MemoryAvailable :
179+ SafeSetTrayIcon ( iconFactory . CreateTransparentIcon ( iconValue ) ) ;
180+ break ;
181+ }
188182 }
189183 }
184+ catch {
185+ SafeSetTrayIcon ( imageIcon ) ;
186+ }
190187 }
191-
188+
192189 private void OnOptimizeProgressUpdate ( byte value , string step ) {
193190 var stepsCount = GetEnabledMemoryAreasCount ( ) ;
194191 if ( value > stepsCount )
@@ -522,9 +519,11 @@ private void AddMenuItems() {
522519 iconTypeMenu = new ToolStripMenuItem ( "Icon type" ) {
523520 DropDownItems = {
524521 new ToolStripMenuItem ( "Image" , null , ( _ , _ ) => { SetIconType ( Enums . TrayIconMode . Image ) ; } ) ,
522+ new ToolStripMenuItem ( "Memory usage (Bar)" , null , ( _ , _ ) => { SetIconType ( Enums . TrayIconMode . MemoryUsageBar ) ; } ) ,
523+ new ToolStripMenuItem ( "Memory usage (Pie)" , null , ( _ , _ ) => { SetIconType ( Enums . TrayIconMode . MemoryUsagePie ) ; } ) ,
525524 new ToolStripMenuItem ( "Memory usage (%)" , null , ( _ , _ ) => { SetIconType ( Enums . TrayIconMode . MemoryUsagePercent ) ; } ) ,
525+ new ToolStripMenuItem ( "Memory usage (Value)" , null , ( _ , _ ) => { SetIconType ( Enums . TrayIconMode . MemoryUsageValue ) ; } ) ,
526526 new ToolStripMenuItem ( "Memory available" , null , ( _ , _ ) => { SetIconType ( Enums . TrayIconMode . MemoryAvailable ) ; } ) ,
527- new ToolStripMenuItem ( "Memory usage" , null , ( _ , _ ) => { SetIconType ( Enums . TrayIconMode . MemoryUsageValue ) ; } ) ,
528527 }
529528 } ;
530529 iconTypeMenu . DropDown . Closing += OnContextMenuStripClosing ;
0 commit comments