How to detect desktop idle time from an Electron app?

前端 未结 4 1030
情话喂你
情话喂你 2021-02-06 10:01

I need my Electron app to respond to the user becoming idle (no mouse or keyboard inputs to any program on the OS) for a certain amount of time.

How can I trigger a func

4条回答
  •  盖世英雄少女心
    2021-02-06 10:07

    Some people have written node libraries that hook into the native platform code for OSX, Windows, and Linux to accomplish this.

    I ended up using this library to accomplish the same thing in my electron app: https://github.com/paulcbetts/node-system-idle-time

    It's published on npm as @paulcbetts/system-idle-time

    I tested it on OSX and it seemed to work fine there.

    I did originally get a "module version mismatch expected 50 got 46" error, but running this command cleared it up:

    npm rebuild --runtime=electron --target=1.4.3 --disturl=https://atom.io/download/atom-shell --abi=49

    Replace target with whatever version of electron you're using.

提交回复
热议问题