@@ -115,6 +115,33 @@ public void ReplaceAccentColor(string name)
115
115
116
116
ReplaceAccentColor ( swatch ) ;
117
117
}
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
+ }
118
145
119
146
/// <summary>
120
147
/// Replaces a certain entry anywhere in the parent dictionary and its merged dictionaries
@@ -126,7 +153,7 @@ public void ReplaceAccentColor(string name)
126
153
private static bool ReplaceEntry ( object entryName , object newValue , ResourceDictionary parentDictionary = null , bool animate = true )
127
154
{
128
155
const int DURATION_MS = 500 ; //Change the value if needed
129
- int ANIMATION_FPS = 60 ;
156
+ int ANIMATION_FPS = GetPowerState ( ) . ACLineStatus == Online ? 20 : 60 ;
130
157
if ( parentDictionary == null )
131
158
parentDictionary = Application . Current . Resources ;
132
159
0 commit comments