diff --git a/app/Mode/ModeControl.cs b/app/Mode/ModeControl.cs index 8b9caf4d..fcd65bef 100644 --- a/app/Mode/ModeControl.cs +++ b/app/Mode/ModeControl.cs @@ -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")); diff --git a/app/Mode/PowerNative.cs b/app/Mode/PowerNative.cs index f6237e3a..267d64bd 100644 --- a/app/Mode/PowerNative.cs +++ b/app/Mode/PowerNative.cs @@ -75,13 +75,14 @@ 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 overlays = new() { POWER_BALANCED, POWER_TURBO, POWER_SILENT, - POWER_BETTERPERFORMANCE }; public static Dictionary powerModes = new Dictionary @@ -89,6 +90,7 @@ static extern UInt32 PowerSetActiveScheme(IntPtr RootPowerKey, { POWER_SILENT, "Best Power Efficiency" }, { POWER_BALANCED, "Balanced" }, { POWER_TURBO, "Best Performance" }, + { PLAN_HIGH_PERFORMANCE, "High Performance Plan"}, }; static Guid GetActiveScheme() { @@ -141,6 +143,7 @@ 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(); } @@ -148,12 +151,23 @@ public static string GetPowerMode() 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"); @@ -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) @@ -332,7 +337,8 @@ public static bool GetBatterySaverStatus() { GetSystemPowerStatus(sps); return (sps.SystemStatusFlag > 0); - } catch (Exception ex) + } + catch (Exception ex) { return false; }