Skip to content

Commit 4d12f4b

Browse files
committed
add IconKind tray menu item ("Show Percentage Icons" main menu item removed)
1 parent 1d9cb54 commit 4d12f4b

File tree

6 files changed

+72
-57
lines changed

6 files changed

+72
-57
lines changed

OpenHardwareMonitor/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
[assembly: AssemblyCompany("HardwareMonitor")]
88
[assembly: AssemblyProduct("OpenHardwareMonitor")]
99
[assembly: AssemblyCopyright("Copyright © 2022 Sergiy Egoshyn")]
10-
[assembly: AssemblyVersion("2025.2.*")]
10+
[assembly: AssemblyVersion("3.0.*")]

OpenHardwareMonitor/UI/MainForm.Designer.cs

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

OpenHardwareMonitor/UI/MainForm.cs

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,6 @@ public MainForm()
152152
UserOption showHiddenSensors = new("hiddenMenuItem", false, hiddenMenuItem, _settings);
153153
showHiddenSensors.Changed += delegate { treeModel.ForceVisible = showHiddenSensors.Value; };
154154

155-
UserOption showPercentageIcons = new("showPercentageIcons", false, percentageIconsMenuItem, _settings);
156-
showPercentageIcons.Changed += delegate { _systemTray.ShowPercentageIcons = showPercentageIcons.Value; };
157-
158155
UserOption showValue = new("valueMenuItem", true, valueMenuItem, _settings);
159156
showValue.Changed += delegate { treeView.Columns[1].IsVisible = showValue.Value; };
160157

@@ -415,44 +412,21 @@ public MainForm()
415412

416413
_sensorValuesTimeWindow.Changed += (_, _) =>
417414
{
418-
TimeSpan timeWindow = TimeSpan.Zero;
419-
switch (_sensorValuesTimeWindow.Value)
415+
TimeSpan timeWindow = _sensorValuesTimeWindow.Value switch
420416
{
421-
case 0:
422-
timeWindow = new TimeSpan(0, 0, 30);
423-
break;
424-
case 1:
425-
timeWindow = new TimeSpan(0, 1, 0);
426-
break;
427-
case 2:
428-
timeWindow = new TimeSpan(0, 2, 0);
429-
break;
430-
case 3:
431-
timeWindow = new TimeSpan(0, 5, 0);
432-
break;
433-
case 4:
434-
timeWindow = new TimeSpan(0, 10, 0);
435-
break;
436-
case 5:
437-
timeWindow = new TimeSpan(0, 30, 0);
438-
break;
439-
case 6:
440-
timeWindow = new TimeSpan(1, 0, 0);
441-
break;
442-
case 7:
443-
timeWindow = new TimeSpan(2, 0, 0);
444-
break;
445-
case 8:
446-
timeWindow = new TimeSpan(6, 0, 0);
447-
break;
448-
case 9:
449-
timeWindow = new TimeSpan(12, 0, 0);
450-
break;
451-
case 10:
452-
timeWindow = new TimeSpan(24, 0, 0);
453-
break;
454-
}
455-
417+
0 => new TimeSpan(0, 0, 30),
418+
1 => new TimeSpan(0, 1, 0),
419+
2 => new TimeSpan(0, 2, 0),
420+
3 => new TimeSpan(0, 5, 0),
421+
4 => new TimeSpan(0, 10, 0),
422+
5 => new TimeSpan(0, 30, 0),
423+
6 => new TimeSpan(1, 0, 0),
424+
7 => new TimeSpan(2, 0, 0),
425+
8 => new TimeSpan(6, 0, 0),
426+
9 => new TimeSpan(12, 0, 0),
427+
10 => new TimeSpan(24, 0, 0),
428+
_ => TimeSpan.Zero,
429+
};
456430
_computer.Accept(new SensorVisitor(delegate(ISensor s) { s.ValuesTimeWindow = timeWindow; }));
457431
};
458432

@@ -467,6 +441,10 @@ public MainForm()
467441
WindowState = FormWindowState.Minimized;
468442
Show();
469443
}
444+
else
445+
{
446+
Timer_Tick(null, EventArgs.Empty);
447+
}
470448
}
471449
else
472450
{

OpenHardwareMonitor/UI/SensorNotifyIcon.cs

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,29 @@ namespace OpenHardwareMonitor.UI;
88

99
public class SensorNotifyIcon : IDisposable
1010
{
11+
private enum IconKind
12+
{
13+
Regular,
14+
Percent,
15+
Pie,
16+
}
17+
1118
private readonly NotifyIconAdv _notifyIcon;
1219
private IconFactory _iconFactory;
20+
private IconKind _iconKind;
1321

1422
public SensorNotifyIcon(SystemTray sensorSystemTray, ISensor sensor, PersistentSettings settings)
1523
{
1624
Sensor = sensor;
1725
_notifyIcon = new NotifyIconAdv();
1826
_iconFactory = new IconFactory();
1927
_iconFactory.Color = settings.GetValue(new Identifier(sensor.Identifier, "traycolor").ToString(), _iconFactory.Color);
28+
if (Enum.TryParse(settings.GetValue(new Identifier(sensor.Identifier, "iconKind").ToString(), IconKind.Regular.ToString()), out IconKind iconKind))
29+
_iconKind = iconKind;
30+
else
31+
{
32+
_iconKind = sensor.SensorType.ValueIsPercent() ? IconKind.Percent : IconKind.Regular;
33+
}
2034

2135
var contextMenuStrip = new ContextMenuStrip();
2236
contextMenuStrip.Renderer = new ThemedToolStripRenderer();
@@ -33,6 +47,27 @@ public SensorNotifyIcon(SystemTray sensorSystemTray, ISensor sensor, PersistentS
3347
sensorSystemTray.Remove(Sensor);
3448
};
3549
contextMenuStrip.Items.Add(removeItem);
50+
51+
if (sensor.SensorType.ValueIsPercent())
52+
{
53+
var iconKindItem = new ToolStripMenuItem("Icon Kind");
54+
iconKindItem.DropDownItems.Add(new ToolStripMenuItem("Value", null, (_, _) => { SetIconKind(IconKind.Regular); }) { Checked = _iconKind == IconKind.Regular });
55+
iconKindItem.DropDownItems.Add(new ToolStripMenuItem("Percent", null, (_, _) => { SetIconKind(IconKind.Percent); }) { Checked = _iconKind == IconKind.Percent });
56+
iconKindItem.DropDownItems.Add(new ToolStripMenuItem("Pie", null, (_, _) => { SetIconKind(IconKind.Pie); }) { Checked = _iconKind == IconKind.Pie });
57+
void SetIconKind(IconKind iconKind)
58+
{
59+
_iconKind = iconKind;
60+
for (int i = 0; i < iconKindItem.DropDownItems.Count; i++)
61+
{
62+
if (iconKindItem.DropDownItems[i] is not ToolStripMenuItem menuItem) continue;
63+
menuItem.Checked = (int)_iconKind == i;
64+
}
65+
settings.SetValue(new Identifier(sensor.Identifier, "iconKind").ToString(), (int)_iconKind);
66+
Update();
67+
}
68+
contextMenuStrip.Items.Add(iconKindItem);
69+
}
70+
3671
var colorItem = new ToolStripMenuItem("Change Color...");
3772
colorItem.Click += delegate
3873
{
@@ -129,17 +164,20 @@ private static string GetThroughputValue(float byteCount, byte preferredSufNum =
129164
return new string(result.Take(3).ToArray());
130165
}
131166

132-
public void Update(bool showPercentageIcons)
167+
public void Update()
133168
{
134169
Icon icon = _notifyIcon.Icon;
135170
switch (Sensor.SensorType)
136171
{
137172
case SensorType.Load:
138173
case SensorType.Control:
139174
case SensorType.Level:
140-
_notifyIcon.Icon = showPercentageIcons
141-
? _iconFactory.CreatePercentageIcon(Sensor.Value.GetValueOrDefault())
142-
: _iconFactory.CreateTransparentIcon(GetString());
175+
_notifyIcon.Icon = _iconKind switch
176+
{
177+
IconKind.Percent => _iconFactory.CreatePercentageIcon(Sensor.Value.GetValueOrDefault()),
178+
IconKind.Pie => _iconFactory.CreatePercentagePieIcon((byte)Sensor.Value.GetValueOrDefault()),
179+
_ => _iconFactory.CreateTransparentIcon(GetString()),
180+
};
143181
break;
144182
default:
145183
_notifyIcon.Icon = _iconFactory.CreateTransparentIcon(GetString());

OpenHardwareMonitor/UI/SystemTray.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ public class SystemTray : IDisposable
1414
private bool _mainIconEnabled;
1515
private readonly NotifyIconAdv _mainIcon;
1616

17-
public bool ShowPercentageIcons { get; set; }
18-
1917
public SystemTray(IComputer computer, PersistentSettings settings)
2018
{
2119
_settings = settings;
@@ -94,7 +92,7 @@ public void Dispose()
9492
public void Redraw()
9593
{
9694
foreach (SensorNotifyIcon icon in _sensorList)
97-
icon.Update(ShowPercentageIcons);
95+
icon.Update();
9896
}
9997

10098
public bool Contains(ISensor sensor) => _sensorList.Any(icon => icon.Sensor == sensor);

OpenHardwareMonitorLib/Hardware/ISensor.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ public enum SensorType
3131
Humidity // %
3232
}
3333

34+
public static class SensorTypeExtensions
35+
{
36+
public static bool ValueIsPercent(this SensorType sensorType) =>
37+
sensorType == SensorType.Load
38+
|| sensorType == SensorType.Control
39+
|| sensorType == SensorType.Level
40+
|| sensorType == SensorType.Humidity
41+
;
42+
}
43+
3444
/// <summary>
3545
/// Stores the readed value and the time in which it was recorded.
3646
/// </summary>

0 commit comments

Comments
 (0)