Reputation: 63
I want to use Node module to get idle time on my electron app, for example use this module : node-system-idle-time how can integrate this model with main.js electron file to read an idle time from the main window? Please help me.
Upvotes: 2
Views: 1050
Reputation: 131
This is how I figured it out from Electron Power monitor API's
const {powerMonitor} = require('electron');
const idle = powerMonitor.getSystemIdleTime() // it returns in seconds when I am writing this
console.log('Current System Idle Time - ', idle);
Upvotes: 2
Reputation: 46
If you want to use Node System Idle Time with your electron app , do the following steps:
Install node with this command:
npm install --save @paulcbetts/system-idle-time
Or if you are using yarn, then run:
yarn add @paulcbetts/system-idle-time
Usage, In your Node JS application import it as:
var systemIdleTime = require('@paulcbetts/system-idle-time');
Then you can use it calling: systemIdleTime.getIdleTime();
The method getIdleTime
will return the system idle time in milliseconds.
Usage in Electron , If you are building an Electron application you need to re-build the addon using Electron's version of Node.js. you can use electron-builder to build your app.
npm install --save-dev electron-rebuild
And then re-build the addon with:
./node_modules/.bin/electron-rebuild
Upvotes: 3