-
-
Notifications
You must be signed in to change notification settings - Fork 745
Expand file tree
/
Copy pathPowerMonitor.cs
More file actions
118 lines (105 loc) · 3.41 KB
/
PowerMonitor.cs
File metadata and controls
118 lines (105 loc) · 3.41 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
using System.Runtime.Versioning;
// ReSharper disable InconsistentNaming
namespace ElectronNET.API
{
/// <summary>
/// Monitor power state changes..
/// </summary>
public sealed class PowerMonitor : ApiBase
{
protected override SocketTaskEventNameTypes SocketTaskEventNameType => SocketTaskEventNameTypes.DashesLowerFirst;
protected override SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.DashedLower;
/// <summary>
/// Emitted when the system is about to lock the screen.
/// </summary>
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
public event Action OnLockScreen
{
add => AddEvent(value);
remove => RemoveEvent(value);
}
/// <summary>
/// Emitted when the system is about to unlock the screen.
/// </summary>
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
public event Action OnUnLockScreen
{
add => AddEvent(value);
remove => RemoveEvent(value);
}
/// <summary>
/// Emitted when the system is suspending.
/// </summary>
public event Action OnSuspend
{
add => AddEvent(value);
remove => RemoveEvent(value);
}
/// <summary>
/// Emitted when system is resuming.
/// </summary>
public event Action OnResume
{
add => AddEvent(value);
remove => RemoveEvent(value);
}
/// <summary>
/// Emitted when the system changes to AC power.
/// </summary>
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
public event Action OnAC
{
add => AddEvent(value);
remove => RemoveEvent(value);
}
/// <summary>
/// Emitted when system changes to battery power.
/// </summary>
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
public event Action OnBattery
{
add => AddEvent(value);
remove => RemoveEvent(value);
}
/// <summary>
/// Emitted when the system is about to reboot or shut down. If the event handler
/// invokes `e.preventDefault()`, Electron will attempt to delay system shutdown in
/// order for the app to exit cleanly.If `e.preventDefault()` is called, the app
/// should exit as soon as possible by calling something like `app.quit()`.
/// </summary>
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("macOS")]
public event Action OnShutdown
{
add => AddEvent(value);
remove => RemoveEvent(value);
}
private static PowerMonitor _powerMonitor;
private static object _syncRoot = new object();
internal PowerMonitor()
{
}
internal static PowerMonitor Instance
{
get
{
if (_powerMonitor == null)
{
lock (_syncRoot)
{
if (_powerMonitor == null)
{
_powerMonitor = new PowerMonitor();
}
}
}
return _powerMonitor;
}
}
}
}