Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
seerge committed Dec 21, 2024
1 parent 0dafb9d commit 17121a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 33 deletions.
14 changes: 2 additions & 12 deletions app/Mode/ModeControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,9 @@ public void SetPerformanceMode(int mode = -1, bool notify = false)

if (!AppConfig.Is("skip_powermode"))
{
var powerMode = AppConfig.GetModeString("powermode");
if (!PowerNative.IsHighPerformance(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 (powerMode is not null)
PowerNative.SetPowerMode(powerMode);
if (AppConfig.GetModeString("powermode") is not null)
PowerNative.SetPowerMode(AppConfig.GetModeString("powermode"));
else
PowerNative.SetPowerMode(Modes.GetBase(mode));
}
Expand Down
34 changes: 13 additions & 21 deletions app/Mode/PowerNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,30 +141,33 @@ public static void SetCPUBoost(int boost = 0)
Logger.WriteLine("Boost " + boost);
}

public static bool IsHighPerformance(string scheme) => scheme == PLAN_HIGH_PERFORMANCE;

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

public static void SetPowerMode(string scheme)
{

if (IsHighPerformance(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 @@ -179,25 +182,13 @@ public static void SetPowerMode(string scheme)

}

public static void SetBalancedPowerPlan()
{
Guid activeSchemeGuid = GetActiveScheme();
string balanced = PLAN_BALANCED;

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)
public static void SetPowerPlan(string scheme = PLAN_BALANCED)
{
// Skipping power modes
if (overlays.Contains(scheme)) return;
if (GetActiveScheme().ToString() == scheme) return;

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

Expand Down Expand Up @@ -343,7 +334,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 17121a2

Please sign in to comment.