Files
Electron.NET/ElectronNET.API/PowerMonitor.cs

92 lines
2.4 KiB
C#
Raw Normal View History

using System;
2020-05-11 12:59:21 -05:00
namespace ElectronNET.API
{
/// <summary>
2020-05-12 10:50:08 -05:00
/// Monitor power state changes..
2020-05-11 12:59:21 -05:00
/// </summary>
public sealed class PowerMonitor
{
/// <summary>
2020-05-12 10:50:08 -05:00
/// Emitted when the system is about to lock the screen.
2020-05-11 12:59:21 -05:00
/// </summary>
public event Action OnLockScreen
{
add
{
if (_lockScreen == null)
{
BridgeConnector.Socket.On("pm-lock-screen" , () =>
{
_lockScreen();
});
BridgeConnector.Socket.Emit("register-pm-lock-screen");
}
_lockScreen += value;
}
remove
{
_lockScreen -= value;
if (_lockScreen == null)
BridgeConnector.Socket.Off("pm-lock-screen");
}
}
private event Action _lockScreen;
/// <summary>
2020-05-12 10:50:08 -05:00
/// Emitted when the system is about to unlock the screen.
2020-05-11 12:59:21 -05:00
/// </summary>
public event Action OnUnLockScreen
{
add
{
if (_unlockScreen == null)
{
BridgeConnector.Socket.On("pm-unlock-screen", () =>
{
_unlockScreen();
});
BridgeConnector.Socket.Emit("register-pm-unlock-screen");
}
_unlockScreen += value;
}
remove
{
_unlockScreen -= value;
if (_unlockScreen == null)
BridgeConnector.Socket.Off("pm-unlock-screen");
}
}
private event Action _unlockScreen;
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;
}
}
}
}