It's quite easy to get the system idle time in Electron with powerMonitor.getSystemIdleTime()
However, I wonder if there is any easy way to reset this? I tried both the powerSaveBlocker.start('prevent-app-suspension')
and the powerSaveBlocker.start('prevent-display-sleep')
but they don't really reset the idle time.
When I use the Caffeine on the Mac OSX I noticed it works perfectly. It keeps reseting the system idle time.
Checked into the Caffeine source code. It's written in C#, not sure how can we make it in Node.js/Electron.
internal static class NativeMethods {
[DllImport("kernel32.dll")]
public static extern uint SetThreadExecutionState(uint esFlags);
public const uint ES_CONTINUOUS = 0x80000000;
public const uint ES_SYSTEM_REQUIRED = 0x00000001;
public const uint ES_DISPLAY_REQUIRED = 0x00000002;
}
Any good ideas?
User contributions licensed under CC BY-SA 3.0