From 28e949bee4e428987d1e8ef2cd0d76bea071b31f Mon Sep 17 00:00:00 2001
From: Serge <5920850+seerge@users.noreply.github.com>
Date: Thu, 15 Jun 2023 12:21:48 +0200
Subject: [PATCH] Power modes fix
---
app/AppConfig.cs | 12 +++++++++++-
app/GHelper.csproj | 2 +-
app/NativeMethods.cs | 22 +++++++++++++++++++---
3 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/app/AppConfig.cs b/app/AppConfig.cs
index 061721b0..a148bee3 100644
--- a/app/AppConfig.cs
+++ b/app/AppConfig.cs
@@ -14,8 +14,18 @@ public static class AppConfig
static AppConfig()
{
+ string startupPath = Application.StartupPath.Trim('\\');
string appPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\GHelper";
- configFile = appPath + "\\config.json";
+ string configName = "\\config.json";
+
+ if (File.Exists(startupPath + configName))
+ {
+ configFile = startupPath + configName;
+ } else
+ {
+ configFile = appPath + configName;
+ }
+
if (!System.IO.Directory.Exists(appPath))
System.IO.Directory.CreateDirectory(appPath);
diff --git a/app/GHelper.csproj b/app/GHelper.csproj
index 30ab929b..1f12a432 100644
--- a/app/GHelper.csproj
+++ b/app/GHelper.csproj
@@ -16,7 +16,7 @@
AnyCPU
False
True
- 0.85
+ 0.86
diff --git a/app/NativeMethods.cs b/app/NativeMethods.cs
index 32f4e546..36d26f55 100644
--- a/app/NativeMethods.cs
+++ b/app/NativeMethods.cs
@@ -804,9 +804,25 @@ public class NativeMethods
public static void SetPowerScheme(string scheme)
{
- PowerSetActiveScheme(IntPtr.Zero, new Guid(scheme));
- PowerSetActiveOverlayScheme(new Guid(scheme));
- Logger.WriteLine(scheme);
+ List overlays = new() {
+ "00000000-0000-0000-0000-000000000000",
+ "ded574b5-45a0-4f42-8737-46345c09c238",
+ "961cc777-2547-4f9d-8174-7d86181b8a7a",
+ "3af9B8d9-7c97-431d-ad78-34a8bfea439f"
+ };
+
+ if (overlays.Contains(scheme))
+ {
+ PowerSetActiveOverlayScheme(new Guid(scheme));
+ Logger.WriteLine("Power mode:" + scheme);
+ }
+ else
+ {
+ PowerSetActiveScheme(IntPtr.Zero, new Guid(scheme));
+ Logger.WriteLine("Power plan:" + scheme);
+ }
+
+
}
public static void SetPowerScheme(int mode)