using System; using System.Runtime.Versioning; // ReSharper disable InconsistentNaming namespace ElectronNET.API { /// /// Monitor power state changes.. /// public sealed class PowerMonitor : ApiBase { protected override SocketTaskEventNameTypes SocketTaskEventNameType => SocketTaskEventNameTypes.DashesLowerFirst; protected override SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.DashedLower; /// /// Emitted when the system is about to lock the screen. /// [SupportedOSPlatform("macOS")] [SupportedOSPlatform("Windows")] public event Action OnLockScreen { add => AddEvent(value); remove => RemoveEvent(value); } /// /// Emitted when the system is about to unlock the screen. /// [SupportedOSPlatform("macOS")] [SupportedOSPlatform("Windows")] public event Action OnUnLockScreen { add => AddEvent(value); remove => RemoveEvent(value); } /// /// Emitted when the system is suspending. /// public event Action OnSuspend { add => AddEvent(value); remove => RemoveEvent(value); } /// /// Emitted when system is resuming. /// public event Action OnResume { add => AddEvent(value); remove => RemoveEvent(value); } /// /// Emitted when the system changes to AC power. /// [SupportedOSPlatform("macOS")] [SupportedOSPlatform("Windows")] public event Action OnAC { add => AddEvent(value); remove => RemoveEvent(value); } /// /// Emitted when system changes to battery power. /// [SupportedOSPlatform("macOS")] [SupportedOSPlatform("Windows")] public event Action OnBattery { add => AddEvent(value); remove => RemoveEvent(value); } /// /// 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()`. /// [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; } } } }