Battery health is now a tooltip similarly to the other tooltips. Is only refreshed once every 15 Minutes at most, and only if the user hovers over the battery panel.

This commit is contained in:
IceStormNG
2023-07-20 16:32:42 +02:00
parent 584bd155d6
commit fc53159a51
3 changed files with 81 additions and 31 deletions

View File

@@ -13,7 +13,7 @@ public static class HardwareControl
public static float? cpuTemp = -1;
public static decimal? batteryRate = 0;
public static decimal batteryWear = -1;
public static decimal batteryHealth = -1;
public static decimal? designCapacity;
public static decimal? fullCapacity;
public static int? gpuTemp = null;
@@ -145,8 +145,13 @@ public static class HardwareControl
}
}
public static void RefreshBatteryHealth()
{
batteryHealth = GetBatteryHealth() * 100;
}
public static decimal GetBatteryWear()
public static decimal GetBatteryHealth()
{
if (designCapacity is null)
{
@@ -159,10 +164,10 @@ public static class HardwareControl
return -1;
}
decimal batteryHealth = (decimal)fullCapacity / (decimal)designCapacity;
Logger.WriteLine("Design Capacity: " + designCapacity + "mWh, Full Charge Capacity: " + fullCapacity + "mWh, Health: " + batteryHealth + "%");
decimal health = (decimal)fullCapacity / (decimal)designCapacity;
Logger.WriteLine("Design Capacity: " + designCapacity + "mWh, Full Charge Capacity: " + fullCapacity + "mWh, Health: " + health + "%");
return batteryHealth;
return health;
}
public static void ReadSensors()
@@ -204,7 +209,6 @@ public static class HardwareControl
gpuTemp = Program.acpi.DeviceGet(AsusACPI.Temp_GPU);
batteryRate = GetBatteryRate() / 1000;
batteryWear = GetBatteryWear() * 100;
}
public static bool IsUsedGPU(int threshold = 10)

View File

@@ -157,7 +157,7 @@ namespace GHelper
tableLayoutMatrix.Controls.Add(buttonMatrix, 2, 0);
tableLayoutMatrix.Dock = DockStyle.Top;
tableLayoutMatrix.Location = new Point(15, 45);
tableLayoutMatrix.Margin = new Padding(6, 6, 6, 6);
tableLayoutMatrix.Margin = new Padding(6);
tableLayoutMatrix.Name = "tableLayoutMatrix";
tableLayoutMatrix.RowCount = 1;
tableLayoutMatrix.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
@@ -266,17 +266,18 @@ namespace GHelper
panelBattery.Location = new Point(8, 805);
panelBattery.Margin = new Padding(0);
panelBattery.Name = "panelBattery";
panelBattery.Padding = new Padding(15, 15, 15, 15);
panelBattery.Size = new Size(606, 114);
panelBattery.Padding = new Padding(15, 15, 15, 5);
panelBattery.Size = new Size(606, 104);
panelBattery.TabIndex = 5;
//
// labelBatteryHealth
//
labelBatteryHealth.Anchor = AnchorStyles.Top | AnchorStyles.Right;
labelBatteryHealth.Location = new Point(377, 78);
labelBatteryHealth.ForeColor = SystemColors.GrayText;
labelBatteryHealth.Location = new Point(377, 75);
labelBatteryHealth.Margin = new Padding(4, 0, 4, 0);
labelBatteryHealth.Name = "labelBatteryHealth";
labelBatteryHealth.Size = new Size(213, 21);
labelBatteryHealth.Size = new Size(213, 24);
labelBatteryHealth.TabIndex = 40;
labelBatteryHealth.Text = " ";
labelBatteryHealth.TextAlign = ContentAlignment.TopRight;
@@ -347,10 +348,10 @@ namespace GHelper
panelFooter.Controls.Add(buttonQuit);
panelFooter.Controls.Add(checkStartup);
panelFooter.Dock = DockStyle.Top;
panelFooter.Location = new Point(8, 961);
panelFooter.Location = new Point(8, 951);
panelFooter.Margin = new Padding(0);
panelFooter.Name = "panelFooter";
panelFooter.Padding = new Padding(15, 15, 15, 15);
panelFooter.Padding = new Padding(15);
panelFooter.Size = new Size(606, 69);
panelFooter.TabIndex = 7;
//
@@ -411,7 +412,7 @@ namespace GHelper
panelPerformance.Location = new Point(8, 8);
panelPerformance.Margin = new Padding(0);
panelPerformance.Name = "panelPerformance";
panelPerformance.Padding = new Padding(15, 15, 15, 15);
panelPerformance.Padding = new Padding(15);
panelPerformance.Size = new Size(606, 156);
panelPerformance.TabIndex = 0;
//
@@ -971,7 +972,7 @@ namespace GHelper
panelKeyboard.Location = new Point(8, 568);
panelKeyboard.Margin = new Padding(0);
panelKeyboard.Name = "panelKeyboard";
panelKeyboard.Padding = new Padding(15, 15, 15, 15);
panelKeyboard.Padding = new Padding(15);
panelKeyboard.Size = new Size(606, 107);
panelKeyboard.TabIndex = 3;
//
@@ -988,7 +989,7 @@ namespace GHelper
tableLayoutKeyboard.Controls.Add(comboKeyboard, 0, 0);
tableLayoutKeyboard.Dock = DockStyle.Top;
tableLayoutKeyboard.Location = new Point(15, 45);
tableLayoutKeyboard.Margin = new Padding(6, 6, 6, 6);
tableLayoutKeyboard.Margin = new Padding(6);
tableLayoutKeyboard.Name = "tableLayoutKeyboard";
tableLayoutKeyboard.RowCount = 1;
tableLayoutKeyboard.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
@@ -1034,7 +1035,7 @@ namespace GHelper
//
pictureColor2.Anchor = AnchorStyles.Top | AnchorStyles.Right;
pictureColor2.Location = new Point(141, 9);
pictureColor2.Margin = new Padding(6, 6, 6, 6);
pictureColor2.Margin = new Padding(6);
pictureColor2.Name = "pictureColor2";
pictureColor2.Size = new Size(15, 15);
pictureColor2.TabIndex = 41;
@@ -1044,7 +1045,7 @@ namespace GHelper
//
pictureColor.Anchor = AnchorStyles.Top | AnchorStyles.Right;
pictureColor.Location = new Point(160, 9);
pictureColor.Margin = new Padding(6, 6, 6, 6);
pictureColor.Margin = new Padding(6);
pictureColor.Name = "pictureColor";
pictureColor.Size = new Size(15, 15);
pictureColor.TabIndex = 40;
@@ -1146,7 +1147,7 @@ namespace GHelper
panelVersion.Controls.Add(labelVersion);
panelVersion.Controls.Add(labelModel);
panelVersion.Dock = DockStyle.Top;
panelVersion.Location = new Point(8, 919);
panelVersion.Location = new Point(8, 909);
panelVersion.Name = "panelVersion";
panelVersion.Size = new Size(606, 42);
panelVersion.TabIndex = 6;
@@ -1172,7 +1173,7 @@ namespace GHelper
MinimizeBox = false;
MinimumSize = new Size(624, 56);
Name = "SettingsForm";
Padding = new Padding(8, 8, 8, 8);
Padding = new Padding(8);
ShowIcon = false;
StartPosition = FormStartPosition.CenterScreen;
Text = "G-Helper";

View File

@@ -9,6 +9,7 @@ using GHelper.Mode;
using GHelper.UI;
using System.Diagnostics;
using System.Timers;
using System.Windows.Forms;
namespace GHelper
{
@@ -32,6 +33,7 @@ namespace GHelper
public Updates? updates;
static long lastRefresh;
static long lastBatteryRefresh;
bool isGpuSection = true;
@@ -173,6 +175,15 @@ namespace GHelper
sensorTimer.Elapsed += OnTimedEvent;
sensorTimer.Enabled = true;
panelBattery.MouseEnter += PanelBattery_MouseEnter;
labelBatteryTitle.MouseEnter += PanelBattery_MouseEnter;
labelBatteryHealth.MouseEnter += PanelBattery_MouseEnter;
labelBattery.MouseEnter += PanelBattery_MouseEnter;
pictureBattery.MouseEnter += PanelBattery_MouseEnter;
sliderBattery.MouseEnter += PanelBattery_MouseEnter;
panelBattery.MouseLeave += PanelBattery_MouseLeave;
labelBatteryHealth.Text = String.Empty;
labelModel.Text = AppConfig.GetModelShort() + (ProcessHelper.IsUserAdministrator() ? "." : "");
TopMost = AppConfig.Is("topmost");
@@ -180,6 +191,51 @@ namespace GHelper
}
private void PanelBattery_MouseEnter(object? sender, EventArgs e)
{
ShowBatteryWear();
}
private void PanelBattery_MouseLeave(object? sender, EventArgs e)
{
labelBatteryHealth.Text = String.Empty;
}
private void PanelBattery_MouseMove(object? sender, MouseEventArgs e)
{
ShowBatteryWear();
}
private void ShowBatteryWear()
{
if (labelBatteryHealth.Text != String.Empty)
{
//Already visible. Nothing to do here.
return;
}
//Refresh again only after 15 Minutes since the last refresh
if (lastBatteryRefresh == 0 || Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastBatteryRefresh) > 15 * 60_000)
{
lastBatteryRefresh = DateTimeOffset.Now.ToUnixTimeMilliseconds();
HardwareControl.RefreshBatteryHealth();
}
string batteryHealth = "";
if (HardwareControl.batteryHealth == -1)
{
batteryHealth = Properties.Strings.BatteryHealth + ": " + "?";
}
else
{
batteryHealth = Properties.Strings.BatteryHealth + ": "
+ Math.Round((decimal)HardwareControl.batteryHealth, 1).ToString() + "%";
}
labelBatteryHealth.Text = batteryHealth;
}
private void SettingsForm_VisibleChanged(object? sender, EventArgs e)
{
sensorTimer.Enabled = this.Visible;
@@ -762,7 +818,6 @@ namespace GHelper
string cpuTemp = "";
string gpuTemp = "";
string battery = "";
string batteryHealth = "";
HardwareControl.ReadSensors();
@@ -775,15 +830,6 @@ namespace GHelper
battery = Properties.Strings.Charging + ": " + Math.Round((decimal)HardwareControl.batteryRate, 1).ToString() + "W";
if (HardwareControl.batteryWear == -1)
{
batteryHealth = Properties.Strings.BatteryHealth + ": " + "?";
}
else
{
batteryHealth = Properties.Strings.BatteryHealth + ": "
+ Math.Round((decimal)HardwareControl.batteryWear, 1).ToString() + "%";
}
if (HardwareControl.gpuTemp > 0)
{
@@ -799,7 +845,6 @@ namespace GHelper
labelMidFan.Text = "Mid" + HardwareControl.midFan;
labelBattery.Text = battery;
labelBatteryHealth.Text = batteryHealth;
});
string trayTip = "CPU" + cpuTemp + " " + HardwareControl.cpuFan;