Skip to content

Commit

Permalink
Max performance (#3511)
Browse files Browse the repository at this point in the history
* Added High Performance power plan option

* Cleanup

* Cleanup

* Renamed High Performance Plan
  • Loading branch information
seerge authored Dec 23, 2024
1 parent c233e9a commit 5e72564
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
6 changes: 0 additions & 6 deletions app/Mode/ModeControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@ public void SetPerformanceMode(int mode = -1, bool notify = false)

if (!AppConfig.Is("skip_powermode"))
{
// Power plan from config or defaulting to balanced
if (AppConfig.GetModeString("scheme") is not null)
PowerNative.SetPowerPlan(AppConfig.GetModeString("scheme"));
else
PowerNative.SetBalancedPowerPlan();

// Windows power mode
if (AppConfig.GetModeString("powermode") is not null)
PowerNative.SetPowerMode(AppConfig.GetModeString("powermode"));
Expand Down
44 changes: 25 additions & 19 deletions app/Mode/PowerNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,22 @@ static extern UInt32 PowerSetActiveScheme(IntPtr RootPowerKey,
const string POWER_SILENT = "961cc777-2547-4f9d-8174-7d86181b8a7a";
const string POWER_BALANCED = "00000000-0000-0000-0000-000000000000";
const string POWER_TURBO = "ded574b5-45a0-4f42-8737-46345c09c238";
const string POWER_BETTERPERFORMANCE = "ded574b5-45a0-4f42-8737-46345c09c238";

const string PLAN_BALANCED = "381b4222-f694-41f0-9685-ff5bb260df2e";
const string PLAN_HIGH_PERFORMANCE = "8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c";

static List<string> overlays = new() {
POWER_BALANCED,
POWER_TURBO,
POWER_SILENT,
POWER_BETTERPERFORMANCE
};

public static Dictionary<string, string> powerModes = new Dictionary<string, string>
{
{ POWER_SILENT, "Best Power Efficiency" },
{ POWER_BALANCED, "Balanced" },
{ POWER_TURBO, "Best Performance" },
{ PLAN_HIGH_PERFORMANCE, "High Performance Plan"},
};
static Guid GetActiveScheme()
{
Expand Down Expand Up @@ -141,19 +143,31 @@ public static void SetCPUBoost(int boost = 0)

public static string GetPowerMode()
{
if (GetActiveScheme().ToString() == PLAN_HIGH_PERFORMANCE) return PLAN_HIGH_PERFORMANCE;
PowerGetEffectiveOverlayScheme(out Guid activeScheme);
return activeScheme.ToString();
}

public static void SetPowerMode(string scheme)
{

if (scheme == PLAN_HIGH_PERFORMANCE)
{
SetPowerPlan(scheme);
return;
}
else
{
// Power plan from config or defaulting to balanced
SetPowerPlan(AppConfig.GetModeString("scheme"));
}

if (!overlays.Contains(scheme)) return;

Guid guidScheme = new Guid(scheme);

uint status = PowerGetEffectiveOverlayScheme(out Guid activeScheme);

if (GetBatterySaverStatus())
{
Logger.WriteLine("Battery Saver detected");
Expand All @@ -168,26 +182,17 @@ public static void SetPowerMode(string scheme)

}

public static void SetBalancedPowerPlan()
{
Guid activeSchemeGuid = GetActiveScheme();
string balanced = "381b4222-f694-41f0-9685-ff5bb260df2e";

if (activeSchemeGuid.ToString() != balanced && !AppConfig.Is("skip_power_plan"))
{
Logger.WriteLine($"Changing power plan from {activeSchemeGuid.ToString()} to Balanced");
SetPowerPlan(balanced);
}
}

public static void SetPowerPlan(string scheme)
{
// Skipping power modes
if (overlays.Contains(scheme)) return;

Guid guidScheme = new Guid(scheme);
uint status = PowerSetActiveScheme(IntPtr.Zero, guidScheme);
Logger.WriteLine("Power Plan " + scheme + ":" + (status == 0 ? "OK" : status));
if (scheme is null) scheme = PLAN_BALANCED;
var activeScheme = GetActiveScheme().ToString();
if (activeScheme == scheme) return;

uint status = PowerSetActiveScheme(IntPtr.Zero, new Guid(scheme));
Logger.WriteLine($"Power Plan {activeScheme} -> {scheme} :" + (status == 0 ? "OK" : status));
}

public static string GetDefaultPowerMode(int mode)
Expand Down Expand Up @@ -332,7 +337,8 @@ public static bool GetBatterySaverStatus()
{
GetSystemPowerStatus(sps);
return (sps.SystemStatusFlag > 0);
} catch (Exception ex)
}
catch (Exception ex)
{
return false;
}
Expand Down

0 comments on commit 5e72564

Please sign in to comment.