diff --git a/GHelper.csproj b/GHelper.csproj index 382b440b..3032eb4b 100644 --- a/GHelper.csproj +++ b/GHelper.csproj @@ -2,14 +2,16 @@ WinExe - net7.0-windows + net7.0-windows8.0 enable True enable True app.manifest GHelper.Program - Resources\standard.ico + favicon.ico + AnyCPU;x64 + 8.0 @@ -24,13 +26,14 @@ - + Always + diff --git a/GHelper.sln b/GHelper.sln index ebb557a1..0b83ab61 100644 --- a/GHelper.sln +++ b/GHelper.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.4.33403.182 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GHelper", "GHelper.csproj", "{D6138BB1-8FDB-4835-87EF-2FE41A3DD604}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GHelper", "GHelper.csproj", "{D6138BB1-8FDB-4835-87EF-2FE41A3DD604}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B6E44CC6-5D28-4CB9-8EE2-BE9D6238E2D6}" ProjectSection(SolutionItems) = preProject @@ -13,13 +13,19 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Debug|x64.ActiveCfg = Release|x64 + {D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Debug|x64.Build.0 = Release|x64 {D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Release|Any CPU.ActiveCfg = Release|Any CPU {D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Release|Any CPU.Build.0 = Release|Any CPU + {D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Release|x64.ActiveCfg = Release|x64 + {D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Program.cs b/Program.cs index bb5667c6..825e7718 100644 --- a/Program.cs +++ b/Program.cs @@ -4,6 +4,8 @@ using System.Management; using System.Runtime.InteropServices; using HidLibrary; using System.Text.Json; +using LibreHardwareMonitor.Hardware; +using System.Threading; public class ASUSWmi { @@ -224,6 +226,13 @@ public class NativeMethods [MarshalAs(UnmanagedType.LPStruct)] Guid PowerSettingGuid, int AcValueIndex); + [DllImport("PowrProf.dll", CharSet = CharSet.Unicode)] + static extern UInt32 PowerWriteACValueIndex(IntPtr RootPowerKey, + [MarshalAs(UnmanagedType.LPStruct)] Guid SchemeGuid, + [MarshalAs(UnmanagedType.LPStruct)] Guid SubGroupOfPowerSettingsGuid, + [MarshalAs(UnmanagedType.LPStruct)] Guid PowerSettingGuid, + int AcValueIndex); + [DllImport("PowrProf.dll", CharSet = CharSet.Unicode)] static extern UInt32 PowerReadACValueIndex(IntPtr RootPowerKey, [MarshalAs(UnmanagedType.LPStruct)] Guid SchemeGuid, @@ -232,14 +241,15 @@ public class NativeMethods out IntPtr AcValueIndex ); - - [DllImport("PowrProf.dll", CharSet = CharSet.Unicode)] - static extern UInt32 PowerWriteACValueIndex(IntPtr RootPowerKey, + static extern UInt32 PowerReadDCValueIndex(IntPtr RootPowerKey, [MarshalAs(UnmanagedType.LPStruct)] Guid SchemeGuid, [MarshalAs(UnmanagedType.LPStruct)] Guid SubGroupOfPowerSettingsGuid, [MarshalAs(UnmanagedType.LPStruct)] Guid PowerSettingGuid, - int AcValueIndex); + out IntPtr AcValueIndex + ); + + [DllImport("PowrProf.dll", CharSet = CharSet.Unicode)] static extern UInt32 PowerSetActiveScheme(IntPtr RootPowerKey, @@ -410,7 +420,7 @@ public class NativeMethods { Guid activeSchemeGuid = GetActiveScheme(); - var hr = PowerWriteACValueIndex( + var hrAC = PowerWriteACValueIndex( IntPtr.Zero, activeSchemeGuid, GUID_CPU, @@ -418,6 +428,17 @@ public class NativeMethods boost); PowerSetActiveScheme(IntPtr.Zero, activeSchemeGuid); + + var hrDC = PowerWriteDCValueIndex( + IntPtr.Zero, + activeSchemeGuid, + GUID_CPU, + GUID_BOOST, + boost); + + PowerSetActiveScheme(IntPtr.Zero, activeSchemeGuid); + + } } @@ -432,6 +453,7 @@ public class Aura public const int Breathe = 1; public const int Strobe = 2; public const int Rainbow = 3; + public const int Dingding = 10; public const int SpeedSlow = 0; public const int SpeedMedium = 1; @@ -489,6 +511,106 @@ public class Aura } +public class UpdateVisitor : IVisitor +{ + public void VisitComputer(IComputer computer) + { + computer.Traverse(this); + } + public void VisitHardware(IHardware hardware) + { + hardware.Update(); + foreach (IHardware subHardware in hardware.SubHardware) subHardware.Accept(this); + } + public void VisitSensor(ISensor sensor) { } + public void VisitParameter(IParameter parameter) { } +} + + +public class HardwareMonitor +{ + + Computer computer; + + public float? cpuTemp = -1; + public float? gpuTemp = -1; + public float? batteryDischarge = -1; + public float? batteryCharge = -1; + + public HardwareMonitor() + { + computer = new Computer + { + IsCpuEnabled = true, + IsGpuEnabled = true, + IsBatteryEnabled = true, + }; + + } + + public void ReadSensors() + { + + computer.Open(); + computer.Accept(new UpdateVisitor()); + + cpuTemp = -1; + gpuTemp = -1; + batteryDischarge = -1; + batteryCharge = -1; + + foreach (IHardware hardware in computer.Hardware) + { + //Debug.WriteLine("Hardware: {0}", hardware.Name); + //Debug.WriteLine("Hardware: {0}", hardware.HardwareType); + + foreach (ISensor sensor in hardware.Sensors) + { + if (sensor.SensorType == SensorType.Temperature) + { + if (hardware.HardwareType.ToString().Contains("Cpu") && sensor.Name.Contains("Core")) + { + cpuTemp = sensor.Value; + //Debug.WriteLine("\tSensor: {0}, value: {1}", sensor.Name, sensor.Value); + } + + if (hardware.HardwareType.ToString().Contains("Gpu") && sensor.Name.Contains("Core")) + { + gpuTemp = sensor.Value; + } + + //Debug.WriteLine("\tSensor: {0}, value: {1}", sensor.Name, sensor.Value); + + } + else if (sensor.SensorType == SensorType.Power) + { + if (sensor.Name.Contains("Discharge")) + { + batteryDischarge = sensor.Value; + } + + if (sensor.Name.Contains("Charge")) + { + batteryCharge = sensor.Value; + } + } + + + + } + } + + } + + public void StopReading() + { + computer.Close(); + } + +} + + + namespace GHelper { static class Program @@ -499,7 +621,10 @@ namespace GHelper public static AppConfig config; public static SettingsForm settingsForm; + public static ToastForm toastForm; + public static Startup scheduler; + public static HardwareMonitor hwmonitor; // The main entry point for the application public static void Main() @@ -534,10 +659,13 @@ namespace GHelper settingsForm.SetStartupCheck(scheduler.IsScheduled()); - bool isPlugged = (SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online); + bool isPlugged = (System.Windows.Forms.SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online); settingsForm.AutoGPUMode(isPlugged ? 1 : 0); settingsForm.AutoScreen(isPlugged ? 1 : 0); + hwmonitor = new HardwareMonitor(); + IntPtr dummy = settingsForm.Handle; + Application.Run(); } @@ -557,10 +685,12 @@ namespace GHelper { case 56: // Rog button case 174: // FN+F5 + settingsForm.BeginInvoke(delegate { settingsForm.CyclePerformanceMode(); }); + return; case 179: // FN+F4 settingsForm.BeginInvoke(delegate diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index a61a99ed..adae0f25 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -110,6 +110,16 @@ namespace GHelper.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap icons8_speed_96 { + get { + object obj = ResourceManager.GetObject("icons8-speed-96", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/Properties/Resources.resx b/Properties/Resources.resx index cff4ff34..b4dac885 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -142,4 +142,7 @@ ..\Resources\icons8-laptop-48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\icons8-speed-96.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/Resources/icons8-speed-96.png b/Resources/icons8-speed-96.png new file mode 100644 index 00000000..774bca1a Binary files /dev/null and b/Resources/icons8-speed-96.png differ diff --git a/Settings.Designer.cs b/Settings.Designer.cs index eb44b77b..860a8049 100644 --- a/Settings.Designer.cs +++ b/Settings.Designer.cs @@ -31,8 +31,7 @@ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SettingsForm)); this.checkStartup = new System.Windows.Forms.CheckBox(); this.trackBattery = new System.Windows.Forms.TrackBar(); - this.labelBattery = new System.Windows.Forms.Label(); - this.labelBatteryLimit = new System.Windows.Forms.Label(); + this.labelBatteryTitle = new System.Windows.Forms.Label(); this.pictureBattery = new System.Windows.Forms.PictureBox(); this.labelGPUFan = new System.Windows.Forms.Label(); this.tableGPU = new System.Windows.Forms.TableLayoutPanel(); @@ -62,6 +61,7 @@ this.comboKeyboard = new System.Windows.Forms.ComboBox(); this.buttonKeyboardColor = new System.Windows.Forms.Button(); this.pictureBox2 = new System.Windows.Forms.PictureBox(); + this.labelBattery = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.trackBattery)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBattery)).BeginInit(); this.tableGPU.SuspendLayout(); @@ -76,9 +76,8 @@ // // checkStartup // - this.checkStartup.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.checkStartup.AutoSize = true; - this.checkStartup.Location = new System.Drawing.Point(31, 1022); + this.checkStartup.Location = new System.Drawing.Point(40, 1007); this.checkStartup.Margin = new System.Windows.Forms.Padding(4, 2, 4, 2); this.checkStartup.Name = "checkStartup"; this.checkStartup.Size = new System.Drawing.Size(206, 36); @@ -92,7 +91,7 @@ this.trackBattery.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.trackBattery.LargeChange = 20; - this.trackBattery.Location = new System.Drawing.Point(20, 919); + this.trackBattery.Location = new System.Drawing.Point(20, 908); this.trackBattery.Margin = new System.Windows.Forms.Padding(4, 2, 4, 2); this.trackBattery.Maximum = 100; this.trackBattery.Minimum = 50; @@ -104,33 +103,22 @@ this.trackBattery.TickStyle = System.Windows.Forms.TickStyle.TopLeft; this.trackBattery.Value = 100; // - // labelBattery + // labelBatteryTitle // - this.labelBattery.AutoSize = true; - this.labelBattery.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); - this.labelBattery.Location = new System.Drawing.Point(77, 877); - this.labelBattery.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.labelBattery.Name = "labelBattery"; - this.labelBattery.Size = new System.Drawing.Size(248, 32); - this.labelBattery.TabIndex = 4; - this.labelBattery.Text = "Battery Charge Limit"; - // - // labelBatteryLimit - // - this.labelBatteryLimit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.labelBatteryLimit.AutoSize = true; - this.labelBatteryLimit.Location = new System.Drawing.Point(633, 874); - this.labelBatteryLimit.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.labelBatteryLimit.Name = "labelBatteryLimit"; - this.labelBatteryLimit.Size = new System.Drawing.Size(73, 32); - this.labelBatteryLimit.TabIndex = 5; - this.labelBatteryLimit.Text = "100%"; + this.labelBatteryTitle.AutoSize = true; + this.labelBatteryTitle.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.labelBatteryTitle.Location = new System.Drawing.Point(77, 871); + this.labelBatteryTitle.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelBatteryTitle.Name = "labelBatteryTitle"; + this.labelBatteryTitle.Size = new System.Drawing.Size(248, 32); + this.labelBatteryTitle.TabIndex = 4; + this.labelBatteryTitle.Text = "Battery Charge Limit"; // // pictureBattery // this.pictureBattery.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pictureBattery.BackgroundImage"))); this.pictureBattery.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.pictureBattery.Location = new System.Drawing.Point(33, 875); + this.pictureBattery.Location = new System.Drawing.Point(33, 868); this.pictureBattery.Margin = new System.Windows.Forms.Padding(4, 2, 4, 2); this.pictureBattery.Name = "pictureBattery"; this.pictureBattery.Size = new System.Drawing.Size(38, 38); @@ -140,13 +128,13 @@ // labelGPUFan // this.labelGPUFan.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.labelGPUFan.AutoSize = true; - this.labelGPUFan.Location = new System.Drawing.Point(546, 262); + this.labelGPUFan.Location = new System.Drawing.Point(425, 262); this.labelGPUFan.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.labelGPUFan.Name = "labelGPUFan"; - this.labelGPUFan.Size = new System.Drawing.Size(155, 32); + this.labelGPUFan.Size = new System.Drawing.Size(277, 32); this.labelGPUFan.TabIndex = 8; this.labelGPUFan.Text = "GPU Fan : 0%"; + this.labelGPUFan.TextAlign = System.Drawing.ContentAlignment.TopRight; // // tableGPU // @@ -235,13 +223,13 @@ // labelCPUFan // this.labelCPUFan.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.labelCPUFan.AutoSize = true; - this.labelCPUFan.Location = new System.Drawing.Point(546, 38); + this.labelCPUFan.Location = new System.Drawing.Point(425, 38); this.labelCPUFan.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.labelCPUFan.Name = "labelCPUFan"; - this.labelCPUFan.Size = new System.Drawing.Size(154, 32); + this.labelCPUFan.Size = new System.Drawing.Size(277, 32); this.labelCPUFan.TabIndex = 12; this.labelCPUFan.Text = "CPU Fan : 0%"; + this.labelCPUFan.TextAlign = System.Drawing.ContentAlignment.TopRight; // // tablePerf // @@ -346,7 +334,7 @@ // // buttonQuit // - this.buttonQuit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonQuit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.buttonQuit.BackColor = System.Drawing.SystemColors.ButtonFace; this.buttonQuit.Location = new System.Drawing.Point(591, 1011); this.buttonQuit.Margin = new System.Windows.Forms.Padding(4, 2, 4, 2); @@ -514,11 +502,23 @@ this.pictureBox2.TabIndex = 26; this.pictureBox2.TabStop = false; // + // labelBattery + // + this.labelBattery.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.labelBattery.Location = new System.Drawing.Point(491, 869); + this.labelBattery.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelBattery.Name = "labelBattery"; + this.labelBattery.Size = new System.Drawing.Size(211, 32); + this.labelBattery.TabIndex = 27; + this.labelBattery.Text = " "; + this.labelBattery.TextAlign = System.Drawing.ContentAlignment.TopRight; + // // SettingsForm // this.AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(744, 1085); + this.Controls.Add(this.labelBattery); this.Controls.Add(this.buttonKeyboardColor); this.Controls.Add(this.comboKeyboard); this.Controls.Add(this.pictureBox1); @@ -539,8 +539,7 @@ this.Controls.Add(this.labelGPUFan); this.Controls.Add(this.tableGPU); this.Controls.Add(this.pictureBattery); - this.Controls.Add(this.labelBatteryLimit); - this.Controls.Add(this.labelBattery); + this.Controls.Add(this.labelBatteryTitle); this.Controls.Add(this.trackBattery); this.Controls.Add(this.checkStartup); this.Controls.Add(this.pictureBox2); @@ -574,8 +573,7 @@ #endregion private CheckBox checkStartup; private TrackBar trackBattery; - private Label labelBattery; - private Label labelBatteryLimit; + private Label labelBatteryTitle; private PictureBox pictureBattery; private Label labelGPUFan; private TableLayoutPanel tableGPU; @@ -605,5 +603,6 @@ private ComboBox comboKeyboard; private Button buttonKeyboardColor; private PictureBox pictureBox2; + private Label labelBattery; } } \ No newline at end of file diff --git a/Settings.cs b/Settings.cs index dc9a2083..3e761c33 100644 --- a/Settings.cs +++ b/Settings.cs @@ -1,11 +1,9 @@ -using Microsoft.VisualBasic.ApplicationServices; -using System.Diagnostics; -using System.Management; +using System.Diagnostics; using System.Timers; -using System.Windows.Forms; namespace GHelper { + public partial class SettingsForm : Form { @@ -88,7 +86,7 @@ namespace GHelper Color color = Color.FromArgb(255, 255, 255); - if (mode == -1) + if (mode == -1) mode = 0; if (colorCode != -1) @@ -99,7 +97,7 @@ namespace GHelper SetAuraMode(mode, false); Aura.Mode = mode; - + } @@ -114,9 +112,11 @@ namespace GHelper buttonKeyboardColor.FlatAppearance.BorderColor = color; } - public void SetAuraMode (int mode = 0, bool apply = true) + public void SetAuraMode(int mode = 0, bool apply = true) { + //Debug.WriteLine(mode); + if (mode > 3) mode = 0; if (Aura.Mode == mode) return; // same mode @@ -124,13 +124,16 @@ namespace GHelper Aura.Mode = mode; Program.config.setConfig("aura_mode", mode); + comboKeyboard.SelectedValueChanged -= ComboKeyboard_SelectedValueChanged; + comboKeyboard.SelectedIndex = mode; + comboKeyboard.SelectedValueChanged += ComboKeyboard_SelectedValueChanged; + if (apply) Aura.ApplyAura(); - else - comboKeyboard.SelectedIndex = mode; + } - public void CycleAuraMode () + public void CycleAuraMode() { SetAuraMode(Program.config.getConfig("aura_mode") + 1); } @@ -183,7 +186,8 @@ namespace GHelper { if (overdrive > 0) Program.wmi.DeviceSet(ASUSWmi.ScreenOverdrive, overdrive); - } catch + } + catch { Debug.WriteLine("Screen Overdrive not supported"); } @@ -226,7 +230,8 @@ namespace GHelper try { overdrive = Program.wmi.DeviceGet(ASUSWmi.ScreenOverdrive); - } catch + } + catch { Debug.WriteLine("Screen Overdrive not supported"); } @@ -294,15 +299,40 @@ namespace GHelper aTimer.AutoReset = true; } - private static void OnTimedEvent(Object source, ElapsedEventArgs e) + private static void OnTimedEvent(Object? source, ElapsedEventArgs? e) { - var cpuFan = Math.Round(Program.wmi.DeviceGet(ASUSWmi.CPU_Fan) / 0.6); - var gpuFan = Math.Round(Program.wmi.DeviceGet(ASUSWmi.GPU_Fan) / 0.6); + string cpuFan = " Fan: " + Math.Round(Program.wmi.DeviceGet(ASUSWmi.CPU_Fan) / 0.6).ToString() + "%"; + string gpuFan = " Fan: " + Math.Round(Program.wmi.DeviceGet(ASUSWmi.GPU_Fan) / 0.6) + "%"; + + string cpuTemp = ""; + string gpuTemp = ""; + string battery = ""; + + try + { + Program.hwmonitor.ReadSensors(); + } catch + { + Debug.WriteLine("Failed reading sensors"); + } + + if (Program.hwmonitor.cpuTemp > 0) + cpuTemp = ": " + Math.Round((decimal)Program.hwmonitor.cpuTemp).ToString() + "°C - "; + + if (Program.hwmonitor.gpuTemp > 0) + gpuTemp = ": " + Math.Round((decimal)Program.hwmonitor.gpuTemp).ToString() + "°C - "; + + if (Program.hwmonitor.batteryDischarge > 0) + battery = "Discharging: " + Math.Round((decimal)Program.hwmonitor.batteryDischarge, 1).ToString() + "W"; + + if (Program.hwmonitor.batteryCharge > 0) + battery = "Charging: " + Math.Round((decimal)Program.hwmonitor.batteryCharge, 1).ToString() + "W"; Program.settingsForm.BeginInvoke(delegate { - Program.settingsForm.labelCPUFan.Text = "CPU Fan: " + cpuFan.ToString() + "%"; - Program.settingsForm.labelGPUFan.Text = "GPU Fan: " + gpuFan.ToString() + "%"; + Program.settingsForm.labelCPUFan.Text = "CPU" + cpuTemp + cpuFan; + Program.settingsForm.labelGPUFan.Text = "GPU" + gpuTemp + gpuFan; + Program.settingsForm.labelBattery.Text = battery; }); } @@ -317,16 +347,20 @@ namespace GHelper this.Top = Screen.FromControl(this).WorkingArea.Height - 10 - this.Height; this.Activate(); aTimer.Enabled = true; + } else { aTimer.Enabled = false; + Program.hwmonitor.StopReading(); } } public void SetPerformanceMode(int PerformanceMode = ASUSWmi.PerformanceBalanced, bool notify = false) { + string perfName; + buttonSilent.FlatAppearance.BorderSize = buttonInactive; buttonBalanced.FlatAppearance.BorderSize = buttonInactive; buttonTurbo.FlatAppearance.BorderSize = buttonInactive; @@ -335,25 +369,25 @@ namespace GHelper { case ASUSWmi.PerformanceSilent: buttonSilent.FlatAppearance.BorderSize = buttonActive; - labelPerf.Text = "Performance Mode: Silent"; + perfName = "Silent"; break; case ASUSWmi.PerformanceTurbo: buttonTurbo.FlatAppearance.BorderSize = buttonActive; - labelPerf.Text = "Performance Mode: Turbo"; + perfName = "Turbo"; break; default: buttonBalanced.FlatAppearance.BorderSize = buttonActive; - labelPerf.Text = "Performance Mode: Balanced"; PerformanceMode = ASUSWmi.PerformanceBalanced; + perfName = "Balanced"; break; } - Program.config.setConfig("performance_mode", PerformanceMode); try { Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, PerformanceMode); - } catch + } + catch { labelPerf.Text = "Performance Mode: not supported"; } @@ -376,6 +410,8 @@ namespace GHelper else SetScreen(60, 0); + InitScreen(); + } public void AutoGPUMode(int Plugged = 1) @@ -396,18 +432,12 @@ namespace GHelper if (eco == 1 && Plugged == 1) // Eco going Standard on plugged { Program.wmi.DeviceSet(ASUSWmi.GPUEco, 0); - - GPUMode = ASUSWmi.GPUModeStandard; - VisualiseGPUMode(GPUMode); - Program.config.setConfig("gpu_mode", GPUMode); + InitGPUMode(); } else if (eco == 0 && Plugged == 0) // Standard going Eco on plugged { Program.wmi.DeviceSet(ASUSWmi.GPUEco, 1); - - GPUMode = ASUSWmi.GPUModeEco; - VisualiseGPUMode(GPUMode); - Program.config.setConfig("gpu_mode", GPUMode); + InitGPUMode(); } } @@ -584,12 +614,13 @@ namespace GHelper if (limit < 50 || limit > 100) limit = 100; - labelBatteryLimit.Text = limit.ToString() + "%"; + labelBatteryTitle.Text = "Battery Charge Limit: " + limit.ToString() + "%"; trackBattery.Value = limit; try { Program.wmi.DeviceSet(ASUSWmi.BatteryLimit, limit); - } catch + } + catch { Debug.WriteLine("Can't set battery charge limit"); } diff --git a/ToastForm.Designer.cs b/ToastForm.Designer.cs new file mode 100644 index 00000000..b7bc2cf2 --- /dev/null +++ b/ToastForm.Designer.cs @@ -0,0 +1,85 @@ +namespace GHelper +{ + partial class ToastForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.pictureIcon = new System.Windows.Forms.PictureBox(); + this.labelMode = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.pictureIcon)).BeginInit(); + this.SuspendLayout(); + // + // pictureIcon + // + this.pictureIcon.BackgroundImage = global::GHelper.Properties.Resources.icons8_speed_96; + this.pictureIcon.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.pictureIcon.Location = new System.Drawing.Point(21, 21); + this.pictureIcon.Name = "pictureIcon"; + this.pictureIcon.Size = new System.Drawing.Size(82, 80); + this.pictureIcon.TabIndex = 0; + this.pictureIcon.TabStop = false; + // + // labelMode + // + this.labelMode.AutoSize = true; + this.labelMode.Font = new System.Drawing.Font("Segoe UI", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.labelMode.Location = new System.Drawing.Point(127, 32); + this.labelMode.Name = "labelMode"; + this.labelMode.Size = new System.Drawing.Size(195, 59); + this.labelMode.TabIndex = 1; + this.labelMode.Text = "Balanced"; + this.labelMode.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // ToastForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.SystemColors.ControlLightLight; + this.ClientSize = new System.Drawing.Size(356, 122); + this.Controls.Add(this.labelMode); + this.Controls.Add(this.pictureIcon); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.MaximizeBox = false; + this.MdiChildrenMinimizedAnchorBottom = false; + this.MinimizeBox = false; + this.Name = "ToastForm"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.Text = "ToastForm"; + this.TopMost = true; + ((System.ComponentModel.ISupportInitialize)(this.pictureIcon)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private PictureBox pictureIcon; + private Label labelMode; + } +} \ No newline at end of file diff --git a/ToastForm.cs b/ToastForm.cs new file mode 100644 index 00000000..e1f168fa --- /dev/null +++ b/ToastForm.cs @@ -0,0 +1,68 @@ +using System.Runtime.InteropServices; + + +namespace GHelper +{ + public partial class ToastForm : Form + { + + private System.Windows.Forms.Timer timer = default!; + + private const int SW_SHOWNOACTIVATE = 4; + private const int HWND_TOPMOST = -1; + private const uint SWP_NOACTIVATE = 0x0010; + + [DllImport("user32.dll", EntryPoint = "SetWindowPos")] + static extern bool SetWindowPos( + int hWnd, // Window handle + int hWndInsertAfter, // Placement-order handle + int X, // Horizontal position + int Y, // Vertical position + int cx, // Width + int cy, // Height + uint uFlags); // Window positioning flags + + [DllImport("user32.dll")] + static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); + + static void ShowInactiveTopmost(Form frm) + { + ShowWindow(frm.Handle, SW_SHOWNOACTIVATE); + SetWindowPos(frm.Handle.ToInt32(), HWND_TOPMOST, + frm.Left, frm.Top, frm.Width, frm.Height, + SWP_NOACTIVATE); + } + + public ToastForm() + { + InitializeComponent(); + } + + public void RunToast(string text) + { + + Top = Screen.FromControl(this).WorkingArea.Height - this.Height - 100; + Left = (Screen.FromControl(this).Bounds.Width - this.Width) / 2; + + ShowInactiveTopmost(this); + + labelMode.Text = text; + + timer = new System.Windows.Forms.Timer(); + timer.Tick += new EventHandler(timer_Tick); + timer.Enabled = true; + timer.Interval = 1000; + timer.Start(); + } + + private void ToastForm_Show(object? sender, EventArgs e) + { + } + + private void timer_Tick(object sender, EventArgs e) + { + timer.Stop(); + Close(); + } + } +} diff --git a/ToastForm.resx b/ToastForm.resx new file mode 100644 index 00000000..f298a7be --- /dev/null +++ b/ToastForm.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 00000000..c8038e99 Binary files /dev/null and b/favicon.ico differ diff --git a/screenshot.png b/screenshot.png index 3117a19a..292fd7b8 100644 Binary files a/screenshot.png and b/screenshot.png differ