mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
80 lines
2.3 KiB
C#
80 lines
2.3 KiB
C#
using System.Diagnostics;
|
|
|
|
namespace GHelper.Battery
|
|
{
|
|
internal class BatteryControl
|
|
{
|
|
|
|
public static void ToggleBatteryLimitFull()
|
|
{
|
|
if (AppConfig.Is("charge_full")) SetBatteryChargeLimit();
|
|
else SetBatteryLimitFull();
|
|
}
|
|
|
|
public static void SetBatteryLimitFull()
|
|
{
|
|
AppConfig.Set("charge_full", 1);
|
|
Program.acpi.DeviceSet(AsusACPI.BatteryLimit, 100, "BatteryLimit");
|
|
Program.settingsForm.VisualiseBatteryFull();
|
|
}
|
|
|
|
public static void UnSetBatteryLimitFull()
|
|
{
|
|
AppConfig.Set("charge_full", 0);
|
|
Program.settingsForm.Invoke(Program.settingsForm.VisualiseBatteryFull);
|
|
}
|
|
|
|
public static void AutoBattery(bool init = false)
|
|
{
|
|
if (AppConfig.Is("charge_full") && !init) SetBatteryLimitFull();
|
|
else SetBatteryChargeLimit();
|
|
}
|
|
|
|
public static void SetBatteryChargeLimit(int limit = -1)
|
|
{
|
|
|
|
if (limit < 0) limit = AppConfig.Get("charge_limit");
|
|
if (limit < 40 || limit > 100) return;
|
|
|
|
if (AppConfig.IsChargeLimit80())
|
|
{
|
|
limit = (limit <= 80) ? 80 : 100;
|
|
}
|
|
|
|
if (AppConfig.IsChargeLimit6080())
|
|
{
|
|
if (limit > 80) limit = 100;
|
|
else if (limit < 60) limit = 60;
|
|
}
|
|
|
|
Program.acpi.DeviceSet(AsusACPI.BatteryLimit, limit, "BatteryLimit");
|
|
|
|
AppConfig.Set("charge_limit", limit);
|
|
AppConfig.Set("charge_full", 0);
|
|
|
|
Program.settingsForm.VisualiseBattery(limit);
|
|
}
|
|
|
|
public static void BatteryReport()
|
|
{
|
|
var reportDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
|
|
|
try
|
|
{
|
|
var cmd = new Process();
|
|
cmd.StartInfo.WorkingDirectory = reportDir;
|
|
cmd.StartInfo.UseShellExecute = false;
|
|
cmd.StartInfo.CreateNoWindow = true;
|
|
cmd.StartInfo.FileName = "powershell";
|
|
cmd.StartInfo.Arguments = "powercfg /batteryreport; explorer battery-report.html";
|
|
cmd.Start();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.WriteLine(ex.Message);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|