Skip to content

Commit ae90c8d

Browse files
committed
Added change fps on battery
1 parent cfd62e8 commit ae90c8d

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

MaterialDesignThemes.Wpf/PaletteHelper.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,33 @@ public void ReplaceAccentColor(string name)
115115

116116
ReplaceAccentColor(swatch);
117117
}
118+
#region Pinvoke
119+
public struct PowerState
120+
{
121+
public ACLineStatus ACLineStatus;
122+
public BatteryFlag BatteryFlag;
123+
public Byte BatteryLifePercent;
124+
public Byte Reserved1;
125+
public Int32 BatteryLifeTime;
126+
public Int32 BatteryFullLifeTime;
127+
}
128+
[DllImport("Kernel32", EntryPoint = "GetSystemPowerStatus")]
129+
private static extern bool GetSystemPowerStatusRef(PowerState sps);
130+
131+
#endregion
132+
public static PowerState GetPowerState()
133+
{
134+
PowerState state = new PowerState();
135+
if (GetSystemPowerStatusRef(state))
136+
return state;
137+
138+
throw new ApplicationException("Unable to get power state");
139+
}
140+
// Note: Underlying type of byte to match Win32 header
141+
public enum ACLineStatus : byte
142+
{
143+
Offline = 0, Online = 1, Unknown = 255
144+
}
118145

119146
/// <summary>
120147
/// Replaces a certain entry anywhere in the parent dictionary and its merged dictionaries
@@ -126,7 +153,7 @@ public void ReplaceAccentColor(string name)
126153
private static bool ReplaceEntry(object entryName, object newValue, ResourceDictionary parentDictionary = null, bool animate = true)
127154
{
128155
const int DURATION_MS = 500; //Change the value if needed
129-
int ANIMATION_FPS = 60;
156+
int ANIMATION_FPS = GetPowerState().ACLineStatus == Online ? 20 : 60;
130157
if (parentDictionary == null)
131158
parentDictionary = Application.Current.Resources;
132159

0 commit comments

Comments
 (0)