mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Merge branch 'main' into notification-feature
This commit is contained in:
105
Settings.cs
105
Settings.cs
@@ -1,6 +1,4 @@
|
||||
using Microsoft.VisualBasic.ApplicationServices;
|
||||
using System.Diagnostics;
|
||||
using System.Management;
|
||||
using System.Diagnostics;
|
||||
using System.Timers;
|
||||
using System.Windows.Forms;
|
||||
using Windows.UI.Notifications;
|
||||
@@ -8,6 +6,7 @@ using Microsoft.Toolkit.Uwp.Notifications;
|
||||
|
||||
namespace GHelper
|
||||
{
|
||||
|
||||
public partial class SettingsForm : Form
|
||||
{
|
||||
|
||||
@@ -90,7 +89,7 @@ namespace GHelper
|
||||
|
||||
Color color = Color.FromArgb(255, 255, 255);
|
||||
|
||||
if (mode == -1)
|
||||
if (mode == -1)
|
||||
mode = 0;
|
||||
|
||||
if (colorCode != -1)
|
||||
@@ -101,7 +100,7 @@ namespace GHelper
|
||||
SetAuraMode(mode, false);
|
||||
|
||||
Aura.Mode = mode;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -116,9 +115,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
|
||||
@@ -126,13 +127,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);
|
||||
}
|
||||
@@ -185,7 +189,8 @@ namespace GHelper
|
||||
{
|
||||
if (overdrive > 0)
|
||||
Program.wmi.DeviceSet(ASUSWmi.ScreenOverdrive, overdrive);
|
||||
} catch
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.WriteLine("Screen Overdrive not supported");
|
||||
}
|
||||
@@ -228,7 +233,8 @@ namespace GHelper
|
||||
try
|
||||
{
|
||||
overdrive = Program.wmi.DeviceGet(ASUSWmi.ScreenOverdrive);
|
||||
} catch
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.WriteLine("Screen Overdrive not supported");
|
||||
}
|
||||
@@ -291,22 +297,54 @@ namespace GHelper
|
||||
|
||||
private static void SetTimer()
|
||||
{
|
||||
aTimer = new System.Timers.Timer(1000);
|
||||
aTimer = new System.Timers.Timer(500);
|
||||
aTimer.Elapsed += OnTimedEvent;
|
||||
aTimer.AutoReset = true;
|
||||
aTimer.Enabled = false;
|
||||
}
|
||||
|
||||
private static void OnTimedEvent(Object source, ElapsedEventArgs e)
|
||||
private static void RefreshSensors()
|
||||
{
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
private static void OnTimedEvent(Object? source, ElapsedEventArgs? e)
|
||||
{
|
||||
RefreshSensors();
|
||||
aTimer.Interval = 2000;
|
||||
}
|
||||
|
||||
private void SettingsForm_VisibleChanged(object? sender, EventArgs e)
|
||||
@@ -318,17 +356,23 @@ namespace GHelper
|
||||
this.Left = Screen.FromControl(this).Bounds.Width - 10 - this.Width;
|
||||
this.Top = Screen.FromControl(this).WorkingArea.Height - 10 - this.Height;
|
||||
this.Activate();
|
||||
|
||||
aTimer.Interval = 500;
|
||||
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;
|
||||
@@ -343,32 +387,32 @@ namespace GHelper
|
||||
{
|
||||
case ASUSWmi.PerformanceSilent:
|
||||
buttonSilent.FlatAppearance.BorderSize = buttonActive;
|
||||
perfName = "Silent";
|
||||
break;
|
||||
case ASUSWmi.PerformanceTurbo:
|
||||
buttonTurbo.FlatAppearance.BorderSize = buttonActive;
|
||||
perfName = "Turbo";
|
||||
break;
|
||||
default:
|
||||
buttonBalanced.FlatAppearance.BorderSize = buttonActive;
|
||||
PerformanceMode = ASUSWmi.PerformanceBalanced;
|
||||
perfName = "Balanced";
|
||||
break;
|
||||
}
|
||||
|
||||
labelPerf.Text = "Performance Mode: " + mode[PerformanceMode];
|
||||
|
||||
string notifTitle = "Performance Mode Changed";
|
||||
string notifBody = "Switched to: " + mode[PerformanceMode];
|
||||
|
||||
Program.config.setConfig("performance_mode", PerformanceMode);
|
||||
try
|
||||
{
|
||||
Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, PerformanceMode);
|
||||
if(notify)
|
||||
sendNotification(notifTitle, notifBody);
|
||||
} catch
|
||||
{
|
||||
labelPerf.Text = "Performance Mode: not supported";
|
||||
}
|
||||
|
||||
if(notify)
|
||||
sendNotification(notifTitle, notifBody);
|
||||
}
|
||||
|
||||
|
||||
@@ -405,6 +449,8 @@ namespace GHelper
|
||||
else
|
||||
SetScreen(60, 0);
|
||||
|
||||
InitScreen();
|
||||
|
||||
}
|
||||
|
||||
public void AutoGPUMode(int Plugged = 1)
|
||||
@@ -425,18 +471,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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -613,12 +653,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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user