diff --git a/ElectronNET.API/PowerMonitor.cs b/ElectronNET.API/PowerMonitor.cs
index 8954904..2bed8e9 100644
--- a/ElectronNET.API/PowerMonitor.cs
+++ b/ElectronNET.API/PowerMonitor.cs
@@ -1,4 +1,5 @@
using System;
+using System.Threading.Tasks;
namespace ElectronNET.API
{
@@ -66,7 +67,7 @@ namespace ElectronNET.API
private event Action _unlockScreen;
///
- ///Emitted when the system is suspending.
+ /// Emitted when the system is suspending.
///
public event Action OnSuspend
{
@@ -95,7 +96,7 @@ namespace ElectronNET.API
private event Action _suspend;
///
- ///Emitted when system is resuming.
+ /// Emitted when system is resuming.
///
public event Action OnResume
{
@@ -124,7 +125,7 @@ namespace ElectronNET.API
private event Action _resume;
///
- ///Emitted when the system changes to AC power.
+ /// Emitted when the system changes to AC power.
///
public event Action OnAC
{
@@ -153,7 +154,7 @@ namespace ElectronNET.API
private event Action _onAC;
///
- ///Emitted when system changes to battery power.
+ /// Emitted when system changes to battery power.
///
public event Action OnBattery
{
@@ -183,10 +184,10 @@ namespace ElectronNET.API
///
- ///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()`.
+ /// 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()`.
///
public event Action OnShutdown
{
@@ -214,6 +215,47 @@ namespace ElectronNET.API
private event Action _shutdown;
+ ///
+ /// Idle time in seconds
+ /// Calculate system idle time in seconds.
+ ///
+ public Task GetSystemIdleTimeAsync()
+ {
+ var taskCompletionSource = new TaskCompletionSource();
+
+ BridgeConnector.Socket.On("pm-getSystemIdleTime-completed", (idleTime) =>
+ {
+ BridgeConnector.Socket.Off("pm-getSystemIdleTime-completed");
+ taskCompletionSource.SetResult((int)idleTime);
+ });
+
+ BridgeConnector.Socket.Emit("pm-getSystemIdleTime");
+
+ return taskCompletionSource.Task;
+ }
+
+ ///
+ /// The system's current state. Can be `active`, `idle`, `locked` or `unknown`.
+ ///
+ /// Calculate the system idle state. `idleThreshold` is the amount of time (in
+ /// seconds) before considered idle. `locked` is available on supported systems
+ /// only.
+ ///
+ public Task GetSystemIdleStateAsync(int IdleThreshold)
+ {
+ var taskCompletionSource = new TaskCompletionSource();
+
+ BridgeConnector.Socket.On("pm-getSystemIdleState-completed", (idleTime) =>
+ {
+ BridgeConnector.Socket.Off("pm-getSystemIdleState-completed");
+ taskCompletionSource.SetResult((string)idleTime);
+ });
+
+ BridgeConnector.Socket.Emit("pm-getSystemIdleState");
+
+ return taskCompletionSource.Task;
+ }
+
private static PowerMonitor _powerMonitor;
private static object _syncRoot = new object();
diff --git a/ElectronNET.Host/api/powerMonitor.js b/ElectronNET.Host/api/powerMonitor.js
index 0b4dd7a..a679565 100644
--- a/ElectronNET.Host/api/powerMonitor.js
+++ b/ElectronNET.Host/api/powerMonitor.js
@@ -38,5 +38,13 @@ module.exports = (socket) => {
electronSocket.emit('pm-shutdown');
});
});
+ socket.on('pm-getSystemIdleTime', () => {
+ var idleTime = electron_1.powerMonitor.getSystemIdleTime();
+ electronSocket.emit('pm-getSystemIdleTime-completed', idleTime);
+ });
+ socket.on('pm-getSystemIdleState', (idleThreshold) => {
+ var idleState = electron_1.powerMonitor.getSystemIdleState(idleThreshold);
+ electronSocket.emit('pm-getSystemIdleState-completed', idleState);
+ });
};
//# sourceMappingURL=powerMonitor.js.map
\ No newline at end of file
diff --git a/ElectronNET.Host/api/powerMonitor.js.map b/ElectronNET.Host/api/powerMonitor.js.map
index 51c5763..6e03906 100644
--- a/ElectronNET.Host/api/powerMonitor.js.map
+++ b/ElectronNET.Host/api/powerMonitor.js.map
@@ -1 +1 @@
-{"version":3,"file":"powerMonitor.js","sourceRoot":"","sources":["powerMonitor.ts"],"names":[],"mappings":";AA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ET.Host/api/powerMonitor.ts b/ElectronNET.Host/api/powerMonitor.ts
index 30b42df..e6aa070 100644
--- a/ElectronNET.Host/api/powerMonitor.ts
+++ b/ElectronNET.Host/api/powerMonitor.ts
@@ -38,4 +38,14 @@ export = (socket: SocketIO.Socket) => {
electronSocket.emit('pm-shutdown');
});
});
+ socket.on('pm-getSystemIdleTime', () => {
+ var idleTime = powerMonitor.getSystemIdleTime();
+
+ electronSocket.emit('pm-getSystemIdleTime-completed', idleTime);
+ });
+ socket.on('pm-getSystemIdleState', (idleThreshold ) => {
+ var idleState = powerMonitor.getSystemIdleState(idleThreshold );
+
+ electronSocket.emit('pm-getSystemIdleState-completed', idleState);
+ });
};
diff --git a/ElectronNET.WebApp/Controllers/HomeController.cs b/ElectronNET.WebApp/Controllers/HomeController.cs
index e944fcd..a375660 100644
--- a/ElectronNET.WebApp/Controllers/HomeController.cs
+++ b/ElectronNET.WebApp/Controllers/HomeController.cs
@@ -37,7 +37,7 @@ namespace ElectronNET.WebApp.Controllers
Electron.PowerMonitor.OnBattery += () =>
{
- Console.WriteLine("The system about to reboot or shut down.");
+ Console.WriteLine("The system about to changes to battery power");
};
}