ioHook on electron consumes too much CPU. Is there anyway around? Or alternative to ioHook

Viewed 945

I am tracking users' mouse movement and upon receiving mouse movement emitter, I dispatch an event that does it work.

ioHook.on('mousemove', event => {
    dispatch(storeLatestWorkTimeStamp())
});

Sometimes the electron app consumes too much CPU more than skype and slack.

I tried setting the max listeners though

ioHook.setMaxListeners(10);

But it's not helping in the consumption of the CPU.

Below is the screenshot of the output of the htop htop output

The usage varies from 60 to 90. Is there any way to control the CPU usage of ioHook.

Is there any other npm packages that serve the purpose as ioHook.

1 Answers

Sorry that I am posting an answer to my own question. After R & D'ing with my colleague, I found out that this can be handled using a functionality called Power Monitor provided by the Electron.

Especially powerMonitor.getSystemIdleTime() comes in handy and it consumes way less RAM compared to ioHook.

For more information, you can refer to https://www.electronjs.org/docs/api/power-monitor. Hope this was helpful.

Related