@@ -22,7 +22,8 @@ internal class TrayApplicationContext : ApplicationContext {
2222 private readonly ComputerService computer ;
2323 private readonly StartupManager startupManager ;
2424 private readonly System . Windows . Forms . Timer autoUpdateTimer ;
25- private ToolStripLabel statusMenuLabel ;
25+ private ToolStripMenuItem statusMenuLabel ;
26+ private ToolStripLabel statusInfoMenuLabel ;
2627 private ToolStripMenuItem iconTypeMenu ;
2728 private ToolStripMenuItem iconDoubleClickMenu ;
2829 private ToolStripMenuItem autoOptimizationIntervalMenu ;
@@ -75,6 +76,9 @@ public TrayApplicationContext() {
7576 WinApiHelper . SetForegroundWindow ( process . MainWindowHandle ) ;
7677 }
7778 break ;
79+ case Enums . DoubleClickAction . ShowStatus :
80+ notifyIcon . ShowBalloonTip ( 10000 , null , GetStatusText ( ) , ToolTipIcon . None ) ;
81+ break ;
7882 case Enums . DoubleClickAction . None :
7983 default :
8084 break ;
@@ -267,13 +271,13 @@ private void UpdateAreasMenuItems() {
267271 }
268272 }
269273
270- private static void SetPriority ( Enums . Priority priority ) {
274+ private static void SetPriority ( ) {
271275 bool priorityBoostEnabled ;
272276 ProcessPriorityClass processPriorityClass ;
273277 ThreadPriority threadPriority ;
274278 ThreadPriorityLevel threadPriorityLevel ;
275279
276- switch ( priority ) {
280+ switch ( Settings . RunOnPriority ) {
277281 case Enums . Priority . Low :
278282 priorityBoostEnabled = false ;
279283 processPriorityClass = ProcessPriorityClass . Idle ;
@@ -341,7 +345,7 @@ private static void SetPriority(Enums.Priority priority) {
341345 }
342346
343347 private async Task MonitorComputer ( ) {
344- SetPriority ( Settings . RunOnPriority ) ;
348+ SetPriority ( ) ;
345349 while ( true ) {
346350 try {
347351 if ( IsBusy ) {
@@ -380,7 +384,7 @@ private void Optimize(Enums.OptimizationReason reason) {
380384 if ( IsBusy )
381385 return ;
382386 IsBusy = true ;
383- SetPriority ( Settings . RunOnPriority ) ;
387+ SetPriority ( ) ;
384388
385389 var tempPhysicalAvailable = computer . Memory . Physical . Free . Bytes ;
386390 var tempVirtualAvailable = computer . Memory . Virtual . Free . Bytes ;
@@ -422,16 +426,24 @@ private void AddMenuItems() {
422426 var menuImage = imageIcon . ToBitmap ( ) ;
423427 notifyIcon . ContextMenuStrip . Items . Add ( new ToolStripMenuItem ( "Optimize now" , menuImage , MenuItemOptimizeClick ) ) ;
424428 notifyIcon . ContextMenuStrip . Items . Add ( new ToolStripSeparator ( ) ) ;
425- statusMenuLabel = new ToolStripLabel ( ) { TextAlign = ContentAlignment . MiddleLeft } ;
426- notifyIcon . ContextMenuStrip . Items . Add ( statusMenuLabel ) ;
427- notifyIcon . ContextMenuStrip . Items . Add ( new ToolStripSeparator ( ) ) ;
429+
430+ statusInfoMenuLabel = new ToolStripLabel ( ) { TextAlign = ContentAlignment . MiddleLeft } ;
431+ statusMenuLabel = new ToolStripMenuItem ( "Status" ) { DropDownItems = { statusInfoMenuLabel } } ;
432+
428433 //auto-start
429434 notifyIcon . ContextMenuStrip . Items . Add ( new ToolStripMenuItem ( "Auto-start application" , null , ( sender , _ ) => {
430435 startupManager . Startup = ! startupManager . Startup ;
431436 ( ( ToolStripMenuItem ) sender ) . Checked = startupManager . Startup ;
432437 } ) {
433438 Checked = startupManager . Startup ,
434439 } ) ;
440+ notifyIcon . ContextMenuStrip . Items . Add ( new ToolStripMenuItem ( "Auto-update application" , null , ( sender , _ ) => {
441+ Settings . AutoUpdateApp = ! Settings . AutoUpdateApp ;
442+ autoUpdateTimer . Enabled = Settings . AutoUpdateApp ;
443+ } ) {
444+ Checked = Settings . AutoUpdateApp ,
445+ CheckOnClick = true ,
446+ } ) ;
435447 //auto-optimize
436448 autoOptimizationIntervalMenu = new ToolStripMenuItem ( "Optimize every" ) {
437449 DropDownItems = {
@@ -448,10 +460,9 @@ private void AddMenuItems() {
448460 }
449461 } ;
450462 autoOptimizationIntervalMenu . DropDown . Closing += OnContextMenuStripClosing ;
451- notifyIcon . ContextMenuStrip . Items . Add ( autoOptimizationIntervalMenu ) ;
452463 SetOptimizationIntervalType ( Settings . AutoOptimizationInterval ) ;
453464
454- autoOptimizeUsageMenu = new ToolStripMenuItem ( "Optimize when free memory is below" ) {
465+ autoOptimizeUsageMenu = new ToolStripMenuItem ( "Optimize if free below" ) {
455466 DropDownItems = {
456467 new ToolStripMenuItem ( "Never" , null , ( _ , _ ) => { SetOptimizationUsage ( 0 ) ; } ) ,
457468 }
@@ -461,7 +472,6 @@ private void AddMenuItems() {
461472 autoOptimizeUsageMenu . DropDownItems . Add ( new ToolStripMenuItem ( $ "{ i } %", null , ( _ , _ ) => { SetOptimizationUsage ( percent ) ; } ) ) ;
462473 }
463474 autoOptimizeUsageMenu . DropDown . Closing += OnContextMenuStripClosing ;
464- notifyIcon . ContextMenuStrip . Items . Add ( autoOptimizeUsageMenu ) ;
465475 SetOptimizationUsage ( Settings . AutoOptimizationMemoryUsage ) ;
466476
467477 #region Optimization types
@@ -492,7 +502,6 @@ private void AddMenuItems() {
492502 }
493503 optimizationTypesMenu . DropDown . Closing += OnContextMenuStripClosing ;
494504 UpdateAreasMenuItems ( ) ;
495- notifyIcon . ContextMenuStrip . Items . Add ( optimizationTypesMenu ) ;
496505 #endregion
497506
498507 //settings
@@ -508,6 +517,13 @@ private void AddMenuItems() {
508517 Checked = Settings . ShowVirtualMemory ,
509518 CheckOnClick = true ,
510519 } ) ;
520+ notifyIcon . ContextMenuStrip . Items . Add ( new ToolStripMenuItem ( "Run on low priority" , null , ( sender , _ ) => {
521+ Settings . RunOnPriority = Settings . RunOnPriority == Enums . Priority . Low ? Enums . Priority . Normal : Enums . Priority . Low ;
522+ SetPriority ( ) ;
523+ } ) {
524+ Checked = Settings . RunOnPriority == Enums . Priority . Low ,
525+ CheckOnClick = true ,
526+ } ) ;
511527
512528 updateIntervalMenu = new ToolStripMenuItem ( "Update interval" ) {
513529 DropDownItems = {
@@ -521,7 +537,6 @@ private void AddMenuItems() {
521537 }
522538 } ;
523539 updateIntervalMenu . DropDown . Closing += OnContextMenuStripClosing ;
524- notifyIcon . ContextMenuStrip . Items . Add ( updateIntervalMenu ) ;
525540 SetUpdateInterval ( Settings . UpdateIntervalSeconds ) ;
526541
527542 iconTypeMenu = new ToolStripMenuItem ( "Icon type" ) {
@@ -535,7 +550,6 @@ private void AddMenuItems() {
535550 }
536551 } ;
537552 iconTypeMenu . DropDown . Closing += OnContextMenuStripClosing ;
538- notifyIcon . ContextMenuStrip . Items . Add ( iconTypeMenu ) ;
539553 SetIconType ( Settings . TrayIconMode ) ;
540554
541555 iconDoubleClickMenu = new ToolStripMenuItem ( "Icon double click action" ) {
@@ -544,33 +558,42 @@ private void AddMenuItems() {
544558 new ToolStripMenuItem ( "Optimize" , null , ( _ , _ ) => { SetIconDoubleClickAction ( Enums . DoubleClickAction . Optimize ) ; } ) ,
545559 new ToolStripMenuItem ( "Task Manager" , null , ( _ , _ ) => { SetIconDoubleClickAction ( Enums . DoubleClickAction . TaskManager ) ; } ) ,
546560 new ToolStripMenuItem ( "Resource Monitor" , null , ( _ , _ ) => { SetIconDoubleClickAction ( Enums . DoubleClickAction . ResourceMonitor ) ; } ) ,
561+ new ToolStripMenuItem ( "Show status" , null , ( _ , _ ) => { SetIconDoubleClickAction ( Enums . DoubleClickAction . ShowStatus ) ; } ) ,
547562 }
548563 } ;
549564 iconDoubleClickMenu . DropDown . Closing += OnContextMenuStripClosing ;
550- notifyIcon . ContextMenuStrip . Items . Add ( iconDoubleClickMenu ) ;
551565 SetIconDoubleClickAction ( Settings . DoubleClickAction ) ;
552566
553- notifyIcon . ContextMenuStrip . Items . Add ( new ToolStripMenuItem ( "Icon color" , null , ( _ , _ ) => {
554- using ( var dialog = new ColorDialog ( ) ) {
555- dialog . Color = Settings . TrayIconValueColor ;
556- if ( dialog . ShowDialog ( ) != DialogResult . OK || Settings . TrayIconValueColor == dialog . Color ) return ;
557- iconFactory . Color = Settings . TrayIconValueColor = dialog . Color ;
558- UpdateIcon ( true ) ;
567+ notifyIcon . ContextMenuStrip . Items . Add ( new ToolStripMenuItem ( "Options" ) {
568+ DropDownItems = {
569+ autoOptimizationIntervalMenu ,
570+ autoOptimizeUsageMenu ,
571+ optimizationTypesMenu ,
572+ updateIntervalMenu ,
573+ iconTypeMenu ,
574+ iconDoubleClickMenu ,
575+ new ToolStripMenuItem ( "Icon color" , null , ( _ , _ ) => {
576+ using ( var dialog = new ColorDialog ( ) ) {
577+ dialog . Color = Settings . TrayIconValueColor ;
578+ if ( dialog . ShowDialog ( ) != DialogResult . OK || Settings . TrayIconValueColor == dialog . Color ) return ;
579+ iconFactory . Color = Settings . TrayIconValueColor = dialog . Color ;
580+ UpdateIcon ( true ) ;
581+ }
582+ } ) ,
559583 }
560- } ) ) ;
584+ } ) ;
585+ SetPriority ( ) ;
586+
561587 notifyIcon . ContextMenuStrip . Items . Add ( new ToolStripSeparator ( ) ) ;
562- //about
563- notifyIcon . ContextMenuStrip . Items . Add ( new ToolStripMenuItem ( "Auto update app" , null , ( sender , _ ) => {
564- Settings . AutoUpdateApp = ! Settings . AutoUpdateApp ;
565- autoUpdateTimer . Enabled = Settings . AutoUpdateApp ;
566- } ) {
567- Checked = Settings . AutoUpdateApp ,
568- CheckOnClick = true ,
588+ notifyIcon . ContextMenuStrip . Items . Add ( statusMenuLabel ) ;
589+ notifyIcon . ContextMenuStrip . Items . Add ( new ToolStripMenuItem ( "Help" ) {
590+ DropDownItems = {
591+ new ToolStripMenuItem ( "Check for updates" , null , ( _ , _ ) => { Updater . CheckForUpdates ( Updater . CheckUpdatesMode . AllMessages ) ; } ) ,
592+ new ToolStripMenuItem ( "Site" , null , ( _ , _ ) => { Updater . VisitAppSite ( ) ; } ) ,
593+ new ToolStripMenuItem ( "About" , null , ( _ , _ ) => { Updater . ShowAbout ( ) ; } ) ,
594+ }
569595 } ) ;
570- notifyIcon . ContextMenuStrip . Items . Add ( new ToolStripMenuItem ( "Check for updates" , null ,
571- ( _ , _ ) => { Updater . CheckForUpdates ( Updater . CheckUpdatesMode . AllMessages ) ; } ) ) ;
572- notifyIcon . ContextMenuStrip . Items . Add ( new ToolStripMenuItem ( "Site" , null , ( _ , _ ) => { Updater . VisitAppSite ( ) ; } ) ) ;
573- notifyIcon . ContextMenuStrip . Items . Add ( new ToolStripMenuItem ( "About" , null , ( _ , _ ) => { Updater . ShowAbout ( ) ; } ) ) ;
596+
574597 notifyIcon . ContextMenuStrip . Items . Add ( new ToolStripMenuItem ( "Exit" , null , ( _ , _ ) => { ExitThread ( ) ; } ) ) ;
575598 }
576599
@@ -620,18 +643,23 @@ private void OnContextMenuStripClosing(object sender, ToolStripDropDownClosingEv
620643 }
621644 }
622645
623- private void UpdateStatusMenuItem ( bool force ) {
624-
625- if ( ! force && ! statusMenuLabel . Visible ) return ;
626- string iconText = GetTrayIconText ( ) ;
646+ private string GetStatusText ( ) {
647+ string text = GetTrayIconText ( ) ;
627648 if ( lastRun != DateTimeOffset . MinValue ) {
628- iconText += $ "\n Last run: { lastRun : G} ";
649+ text += $ "\n Last run: { lastRun : G} ";
629650 }
630651 if ( nextAutoOptimizationByInterval != DateTimeOffset . MinValue ) {
631- iconText += $ "\n Next run: { nextAutoOptimizationByInterval : G} ";
652+ text += $ "\n Next run: { nextAutoOptimizationByInterval : G} ";
632653 }
633- if ( iconText != statusMenuLabel . Text )
634- statusMenuLabel . Text = iconText ;
654+ return text ;
655+ }
656+
657+ private void UpdateStatusMenuItem ( bool force ) {
658+
659+ if ( ! force && ! statusMenuLabel . Visible ) return ;
660+ string iconText = GetStatusText ( ) ;
661+ if ( iconText != statusInfoMenuLabel . Text )
662+ statusInfoMenuLabel . Text = iconText ;
635663 }
636664
637665 protected override void Dispose ( bool disposing ) {
0 commit comments