diff --git a/app/Extra.cs b/app/Extra.cs index 74721dbc..a97fb967 100644 --- a/app/Extra.cs +++ b/app/Extra.cs @@ -56,6 +56,7 @@ namespace GHelper break; case "fne": customActions[""] = "Calculator"; + customActions["ghelper"] = Properties.Strings.OpenGHelper; break; } diff --git a/app/HardwareControl.cs b/app/HardwareControl.cs index 62ee6683..0d89898b 100644 --- a/app/HardwareControl.cs +++ b/app/HardwareControl.cs @@ -18,8 +18,13 @@ public static class HardwareControl public static float? cpuTemp = -1; public static decimal? batteryRate = 0; public static decimal batteryHealth = -1; + public static decimal batteryCapacity = -1; + public static decimal? designCapacity; public static decimal? fullCapacity; + public static decimal? chargeCapacity; + + public static int? gpuTemp = null; public static string? cpuFan; @@ -106,9 +111,12 @@ public static class HardwareControl } - public static decimal GetBatteryRate() + public static void GetBatteryStatus() { + batteryRate = 0; + chargeCapacity = 0; + try { ManagementScope scope = new ManagementScope("root\\WMI"); @@ -117,26 +125,29 @@ public static class HardwareControl using ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query); foreach (ManagementObject obj in searcher.Get().Cast()) { + + chargeCapacity = Convert.ToDecimal(obj["RemainingCapacity"]); + decimal chargeRate = Convert.ToDecimal(obj["ChargeRate"]); decimal dischargeRate = Convert.ToDecimal(obj["DischargeRate"]); + if (chargeRate > 0) - return chargeRate; + batteryRate = chargeRate / 1000; else - return -dischargeRate; - } + batteryRate = -dischargeRate / 1000; - return 0; + } } catch (Exception ex) { Logger.WriteLine("Discharge Reading: " + ex.Message); - return 0; } } public static void ReadFullChargeCapacity() { + if (fullCapacity > 0) return; try { @@ -159,6 +170,8 @@ public static class HardwareControl public static void ReadDesignCapacity() { + if (designCapacity > 0) return; + try { ManagementScope scope = new ManagementScope("root\\WMI"); @@ -253,7 +266,15 @@ public static class HardwareControl if (gpuTemp is null || gpuTemp < 0) gpuTemp = Program.acpi.DeviceGet(AsusACPI.Temp_GPU); - batteryRate = GetBatteryRate() / 1000; + ReadFullChargeCapacity(); + GetBatteryStatus(); + + if (fullCapacity > 0 && chargeCapacity > 0) + { + batteryCapacity = Math.Min(100, ((decimal)chargeCapacity / (decimal)fullCapacity) * 100); + } + + } public static bool IsUsedGPU(int threshold = 10) diff --git a/app/Input/InputDispatcher.cs b/app/Input/InputDispatcher.cs index f4134ccb..b896838c 100644 --- a/app/Input/InputDispatcher.cs +++ b/app/Input/InputDispatcher.cs @@ -520,7 +520,7 @@ namespace GHelper.Input break; case 107: // FN+F10 AsusUSB.TouchpadToggle(); - Thread.Sleep(50); + Thread.Sleep(200); Program.toast.RunToast(GetTouchpadState() ? "On" : "Off", ToastIcon.Touchpad); break; case 108: // FN+F11 diff --git a/app/Properties/Strings.Designer.cs b/app/Properties/Strings.Designer.cs index 802c84bf..4862ed01 100644 --- a/app/Properties/Strings.Designer.cs +++ b/app/Properties/Strings.Designer.cs @@ -429,6 +429,15 @@ namespace GHelper.Properties { } } + /// + /// Looks up a localized string similar to Charge. + /// + internal static string BatteryCharge { + get { + return ResourceManager.GetString("BatteryCharge", resourceCulture); + } + } + /// /// Looks up a localized string similar to Battery Charge Limit. /// @@ -437,7 +446,7 @@ namespace GHelper.Properties { return ResourceManager.GetString("BatteryChargeLimit", resourceCulture); } } - + /// /// Looks up a localized string similar to Battery Health. /// @@ -1150,7 +1159,7 @@ namespace GHelper.Properties { return ResourceManager.GetString("NoNewUpdates", resourceCulture); } } - + /// /// Looks up a localized string similar to Not Connected. /// @@ -1456,7 +1465,7 @@ namespace GHelper.Properties { return ResourceManager.GetString("ToggleAura", resourceCulture); } } - + /// /// Looks up a localized string similar to Auto Toggle Clamshell Mode. /// diff --git a/app/Properties/Strings.resx b/app/Properties/Strings.resx index 5973ed37..65ff5a29 100644 --- a/app/Properties/Strings.resx +++ b/app/Properties/Strings.resx @@ -240,6 +240,9 @@ Balanced + + Charge + Battery Charge Limit diff --git a/app/Settings.Designer.cs b/app/Settings.Designer.cs index 6a753c1b..933a7781 100644 --- a/app/Settings.Designer.cs +++ b/app/Settings.Designer.cs @@ -47,8 +47,9 @@ namespace GHelper labelBatteryTitle = new Label(); panelFooter = new Panel(); tableButtons = new TableLayoutPanel(); - buttonUpdates = new RButton(); + labelVersion = new Label(); buttonQuit = new RButton(); + buttonUpdates = new RButton(); checkStartup = new CheckBox(); panelPerformance = new Panel(); tablePerf = new TableLayoutPanel(); @@ -95,8 +96,8 @@ namespace GHelper panelKeyboardTitle = new Panel(); pictureKeyboard = new PictureBox(); labelKeyboard = new Label(); - labelVersion = new Label(); panelVersion = new Panel(); + labelCharge = new Label(); panelPeripherals = new Panel(); tableLayoutPeripherals = new TableLayoutPanel(); buttonPeripheral3 = new RButton(); @@ -365,8 +366,9 @@ namespace GHelper tableButtons.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33.3333321F)); tableButtons.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33.3333321F)); tableButtons.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 27F)); - tableButtons.Controls.Add(buttonUpdates, 0, 0); + tableButtons.Controls.Add(labelVersion, 0, 0); tableButtons.Controls.Add(buttonQuit, 2, 0); + tableButtons.Controls.Add(buttonUpdates, 1, 0); tableButtons.Dock = DockStyle.Top; tableButtons.Location = new Point(20, 20); tableButtons.Margin = new Padding(4); @@ -376,26 +378,20 @@ namespace GHelper tableButtons.Size = new Size(787, 60); tableButtons.TabIndex = 25; // - // buttonUpdates + // labelVersion // - buttonUpdates.AccessibleName = "BIOS and Driver Updates"; - buttonUpdates.Activated = false; - buttonUpdates.BackColor = SystemColors.ControlLight; - buttonUpdates.BorderColor = Color.Transparent; - buttonUpdates.BorderRadius = 2; - buttonUpdates.Dock = DockStyle.Top; - buttonUpdates.FlatStyle = FlatStyle.Flat; - buttonUpdates.Image = Properties.Resources.icons8_software_32_white; - buttonUpdates.ImageAlign = ContentAlignment.MiddleRight; - buttonUpdates.Location = new Point(4, 6); - buttonUpdates.Margin = new Padding(4, 6, 4, 6); - buttonUpdates.Name = "buttonUpdates"; - buttonUpdates.Secondary = true; - buttonUpdates.Size = new Size(254, 48); - buttonUpdates.TabIndex = 24; - buttonUpdates.Text = "Updates"; - buttonUpdates.TextImageRelation = TextImageRelation.ImageBeforeText; - buttonUpdates.UseVisualStyleBackColor = false; + labelVersion.Cursor = Cursors.Hand; + labelVersion.Dock = DockStyle.Fill; + labelVersion.Font = new Font("Segoe UI", 9F, FontStyle.Underline, GraphicsUnit.Point); + labelVersion.ForeColor = SystemColors.ControlDark; + labelVersion.Location = new Point(0, 0); + labelVersion.Margin = new Padding(0); + labelVersion.Name = "labelVersion"; + labelVersion.Padding = new Padding(5); + labelVersion.Size = new Size(262, 60); + labelVersion.TabIndex = 37; + labelVersion.Text = "v.0"; + labelVersion.TextAlign = ContentAlignment.MiddleLeft; // // buttonQuit // @@ -418,6 +414,27 @@ namespace GHelper buttonQuit.TextImageRelation = TextImageRelation.ImageBeforeText; buttonQuit.UseVisualStyleBackColor = false; // + // buttonUpdates + // + buttonUpdates.AccessibleName = "BIOS and Driver Updates"; + buttonUpdates.Activated = false; + buttonUpdates.BackColor = SystemColors.ControlLight; + buttonUpdates.BorderColor = Color.Transparent; + buttonUpdates.BorderRadius = 2; + buttonUpdates.Dock = DockStyle.Top; + buttonUpdates.FlatStyle = FlatStyle.Flat; + buttonUpdates.Image = Properties.Resources.icons8_software_32_white; + buttonUpdates.ImageAlign = ContentAlignment.MiddleRight; + buttonUpdates.Location = new Point(266, 6); + buttonUpdates.Margin = new Padding(4, 6, 4, 6); + buttonUpdates.Name = "buttonUpdates"; + buttonUpdates.Secondary = true; + buttonUpdates.Size = new Size(254, 48); + buttonUpdates.TabIndex = 24; + buttonUpdates.Text = "Updates"; + buttonUpdates.TextImageRelation = TextImageRelation.ImageBeforeText; + buttonUpdates.UseVisualStyleBackColor = false; + // // checkStartup // checkStartup.AutoSize = true; @@ -1169,23 +1186,9 @@ namespace GHelper labelKeyboard.TabIndex = 34; labelKeyboard.Text = "Laptop Keyboard"; // - // labelVersion - // - labelVersion.Anchor = AnchorStyles.Top | AnchorStyles.Right; - labelVersion.Cursor = Cursors.Hand; - labelVersion.Font = new Font("Segoe UI", 9F, FontStyle.Underline, GraphicsUnit.Point); - labelVersion.ForeColor = SystemColors.ControlDark; - labelVersion.Location = new Point(502, 13); - labelVersion.Margin = new Padding(11, 0, 11, 0); - labelVersion.Name = "labelVersion"; - labelVersion.Size = new Size(300, 32); - labelVersion.TabIndex = 37; - labelVersion.Text = "v.0"; - labelVersion.TextAlign = ContentAlignment.TopRight; - // // panelVersion // - panelVersion.Controls.Add(labelVersion); + panelVersion.Controls.Add(labelCharge); panelVersion.Controls.Add(checkStartup); panelVersion.Dock = DockStyle.Top; panelVersion.Location = new Point(11, 1379); @@ -1194,6 +1197,18 @@ namespace GHelper panelVersion.Size = new Size(827, 56); panelVersion.TabIndex = 6; // + // labelCharge + // + labelCharge.Anchor = AnchorStyles.Top | AnchorStyles.Right; + labelCharge.ForeColor = SystemColors.ControlDark; + labelCharge.Location = new Point(476, 10); + labelCharge.Margin = new Padding(8, 0, 8, 0); + labelCharge.Name = "labelCharge"; + labelCharge.Size = new Size(324, 36); + labelCharge.TabIndex = 40; + labelCharge.Text = " "; + labelCharge.TextAlign = ContentAlignment.TopRight; + // // panelPeripherals // panelPeripherals.AutoSize = true; @@ -1482,7 +1497,6 @@ namespace GHelper private Label labelVersion; private RButton buttonStopGPU; private TableLayoutPanel tableButtons; - private RButton buttonUpdates; private Panel panelPeripherals; private TableLayoutPanel tableLayoutPeripherals; private Panel panelPeripheralsTile; @@ -1492,5 +1506,7 @@ namespace GHelper private RButton buttonPeripheral3; private RButton buttonPeripheral1; private RButton buttonKeyboard; + private RButton buttonUpdates; + private Label labelCharge; } } \ No newline at end of file diff --git a/app/Settings.cs b/app/Settings.cs index 6289c6c5..240f528b 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -178,9 +178,13 @@ namespace GHelper sensorTimer.Elapsed += OnTimedEvent; sensorTimer.Enabled = true; + panelBattery.MouseEnter += PanelBattery_MouseEnter; + labelCharge.MouseEnter += PanelBattery_MouseEnter; labelBattery.MouseEnter += PanelBattery_MouseEnter; labelBatteryTitle.MouseEnter += PanelBattery_MouseEnter; + panelBattery.MouseLeave += PanelBattery_MouseLeave; + labelCharge.MouseLeave += PanelBattery_MouseLeave; labelBattery.MouseLeave += PanelBattery_MouseLeave; labelBatteryTitle.MouseLeave += PanelBattery_MouseLeave; @@ -229,7 +233,7 @@ namespace GHelper if (HardwareControl.batteryHealth != -1) { - labelBattery.Text = Properties.Strings.BatteryHealth + ": " + Math.Round(HardwareControl.batteryHealth, 1) + "%"; + labelCharge.Text = Properties.Strings.BatteryHealth + ": " + Math.Round(HardwareControl.batteryHealth, 1) + "%"; } } @@ -822,6 +826,7 @@ namespace GHelper string cpuTemp = ""; string gpuTemp = ""; string battery = ""; + string charge = ""; HardwareControl.ReadSensors(); Task.Run((Action)PeripheralsProvider.RefreshBatteryForAllDevices); @@ -829,6 +834,9 @@ namespace GHelper if (HardwareControl.cpuTemp > 0) cpuTemp = ": " + Math.Round((decimal)HardwareControl.cpuTemp).ToString() + "°C"; + if (HardwareControl.batteryCapacity > 0) + charge = Properties.Strings.BatteryCharge + ": " + Math.Round(HardwareControl.batteryCapacity, 1) + "% "; + if (HardwareControl.batteryRate < 0) battery = Properties.Strings.Discharging + ": " + Math.Round(-(decimal)HardwareControl.batteryRate, 1).ToString() + "W"; else if (HardwareControl.batteryRate > 0) @@ -847,7 +855,8 @@ namespace GHelper if (HardwareControl.midFan is not null) labelMidFan.Text = "Mid " + HardwareControl.midFan; - if (!batteryMouseOver) labelBattery.Text = battery; + labelBattery.Text = battery; + if (!batteryMouseOver) labelCharge.Text = charge; }); string trayTip = "CPU" + cpuTemp + " " + HardwareControl.cpuFan; diff --git a/app/Settings.resx b/app/Settings.resx index a395bffc..af32865e 100644 --- a/app/Settings.resx +++ b/app/Settings.resx @@ -18,7 +18,7 @@ System.Resources.ResXResourceReader, System.Windows.Forms, ... System.Resources.ResXResourceWriter, System.Windows.Forms, ... this is my long stringthis is a comment - Blue + Blue [base64 mime encoded serialized .NET Framework object]