-
-
Notifications
You must be signed in to change notification settings - Fork 267
/
PowerManager.cs
48 lines (45 loc) · 1.39 KB
/
PowerManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Runtime.InteropServices;
using LibVLCSharp.Forms.Platforms.WPF;
using LibVLCSharp.Forms.Shared;
using Xamarin.Forms;
[assembly: Dependency(typeof(PowerManager))]
namespace LibVLCSharp.Forms.Platforms.WPF
{
/// <summary>
/// Power manager.
/// </summary>
public class PowerManager : IPowerManager
{
[DllImport("kernel32.dll")]
private static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
[Flags]
private enum EXECUTION_STATE : uint
{
ES_AWAYMODE_REQUIRED = 0x00000040,
ES_CONTINUOUS = 0x80000000,
ES_DISPLAY_REQUIRED = 0x00000002,
ES_SYSTEM_REQUIRED = 0x00000001
}
private bool _keepScreenOn;
/// <summary>
/// Gets or sets a value indicating whether the screen should be kept on.
/// </summary>
public bool KeepScreenOn
{
get => _keepScreenOn;
set
{
if (value)
{
SetThreadExecutionState(EXECUTION_STATE.ES_DISPLAY_REQUIRED | EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_CONTINUOUS);
}
else
{
SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);
}
_keepScreenOn = value;
}
}
}
}