Remember performance mode for plugged / battery

This commit is contained in:
seerge
2023-03-02 21:05:02 +01:00
parent ed579f25d6
commit b3636fd447
2 changed files with 28 additions and 17 deletions

View File

@@ -61,17 +61,11 @@ namespace GHelper
settingsForm.InitBoost(); settingsForm.InitBoost();
settingsForm.InitAura(); settingsForm.InitAura();
settingsForm.SetPerformanceMode(config.getConfig("performance_mode"));
settingsForm.SetBatteryChargeLimit(config.getConfig("charge_limit"));
settingsForm.VisualiseGPUAuto(config.getConfig("gpu_auto")); settingsForm.VisualiseGPUAuto(config.getConfig("gpu_auto"));
settingsForm.VisualiseScreenAuto(config.getConfig("screen_auto")); settingsForm.VisualiseScreenAuto(config.getConfig("screen_auto"));
settingsForm.SetStartupCheck(Startup.IsScheduled()); settingsForm.SetStartupCheck(Startup.IsScheduled());
bool isPlugged = (System.Windows.Forms.SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online); SetAutoModes();
settingsForm.AutoGPUMode(isPlugged ? 1 : 0);
settingsForm.AutoScreen(isPlugged ? 1 : 0);
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
@@ -81,13 +75,18 @@ namespace GHelper
} }
private static void SetAutoModes()
{
PowerLineStatus isPlugged = SystemInformation.PowerStatus.PowerLineStatus;
settingsForm.AutoGPUMode(isPlugged);
settingsForm.AutoScreen(isPlugged);
settingsForm.AutoPerformance(isPlugged);
settingsForm.SetBatteryChargeLimit(config.getConfig("charge_limit"));
}
private static void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e) private static void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
{ {
bool isPlugged = (System.Windows.Forms.SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online); SetAutoModes();
settingsForm.AutoGPUMode(isPlugged ? 1 : 0);
settingsForm.AutoScreen(isPlugged ? 1 : 0);
settingsForm.SetBatteryChargeLimit(config.getConfig("charge_limit"));
} }

View File

@@ -498,7 +498,9 @@ namespace GHelper
} }
Program.config.setConfig("performance_"+(int)SystemInformation.PowerStatus.PowerLineStatus, PerformanceMode);
Program.config.setConfig("performance_mode", PerformanceMode); Program.config.setConfig("performance_mode", PerformanceMode);
Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, PerformanceMode); Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, PerformanceMode);
if (Program.config.getConfig("auto_apply_" + PerformanceMode) == 1) if (Program.config.getConfig("auto_apply_" + PerformanceMode) == 1)
@@ -533,12 +535,22 @@ namespace GHelper
SetPerformanceMode(Program.config.getConfig("performance_mode") + 1, true); SetPerformanceMode(Program.config.getConfig("performance_mode") + 1, true);
} }
public void AutoScreen(int Plugged = 1) public void AutoPerformance(PowerLineStatus Plugged = PowerLineStatus.Online)
{
int mode = Program.config.getConfig("performance_"+(int)Plugged);
if (mode != -1)
SetPerformanceMode(mode, true);
else
SetPerformanceMode(Program.config.getConfig("performance_mode"));
}
public void AutoScreen(PowerLineStatus Plugged = PowerLineStatus.Online)
{ {
int ScreenAuto = Program.config.getConfig("screen_auto"); int ScreenAuto = Program.config.getConfig("screen_auto");
if (ScreenAuto != 1) return; if (ScreenAuto != 1) return;
if (Plugged == 1) if (Plugged == PowerLineStatus.Online)
SetScreen(1000, 1); SetScreen(1000, 1);
else else
SetScreen(60, 0); SetScreen(60, 0);
@@ -547,7 +559,7 @@ namespace GHelper
} }
public void AutoGPUMode(int Plugged = 1) public void AutoGPUMode(PowerLineStatus Plugged = PowerLineStatus.Online)
{ {
int GpuAuto = Program.config.getConfig("gpu_auto"); int GpuAuto = Program.config.getConfig("gpu_auto");
@@ -561,12 +573,12 @@ namespace GHelper
return; return;
else else
{ {
if (eco == 1 && Plugged == 1) // Eco going Standard on plugged if (eco == 1 && Plugged == PowerLineStatus.Online) // Eco going Standard on plugged
{ {
Program.wmi.DeviceSet(ASUSWmi.GPUEco, 0); Program.wmi.DeviceSet(ASUSWmi.GPUEco, 0);
InitGPUMode(); InitGPUMode();
} }
else if (eco == 0 && Plugged == 0) // Standard going Eco on plugged else if (eco == 0 && Plugged != PowerLineStatus.Online) // Standard going Eco on plugged
{ {
Program.wmi.DeviceSet(ASUSWmi.GPUEco, 1); Program.wmi.DeviceSet(ASUSWmi.GPUEco, 1);
InitGPUMode(); InitGPUMode();