npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@paymoapp/real-idle

v1.1.1

Published

Detect if the system is really idle or the user is just watching a video

Downloads

24

Readme

@paymoapp/real-idle

NPM Typescript N-API License

NodeJS library using native modules to detect the real idle state of the system.

Table of Contents

What this library does

Sometimes it's not enough to know how long ago the last input event from the user was, to determine the idle state of the system.

This library can detect on mac and linux if there's a background activity running (for example: watching a video or participating in a Zoom meeting) in which case the user shouldn't be treated as idle.

This is done by requesting the IOPM Assertions (on Mac) and using the IsInhibited DBUS function (on Linux).

Getting started

Installation

npm install --save @paymoapp/real-idle

Native addon

This project uses NodeJS Native Addons to function, so you can use this library in any NodeJS or Electron project. There won't be any problem with bundling and code signing.

The project uses prebuild to supply prebuilt libraries.

The project uses Node-API version 6. You can check this table to see which node versions are supported.

If there's a compliant prebuilt binary, it will be downloaded during installation, or it will be built. You can also rebuild it anytime by running npm run build:gyp.

The library has native addons for Windows, MacOS and Linux.

Example

You can run a demo application by calling npm run demo and you can tweak the parameters in the demo/electron.js file. For the demo, it is required to start an electron application since on MacOS a GUI session is required to access some functions (although you might get it working in a console application as well).

import RealIdle from '@paymoapp/real-idle';

setTimeout(() => {
	console.log('System idle state:', RealIdle.getIdleState(300));
	console.log('  - Idle seconds:', RealIdle.getIdleSeconds());
	console.log('  - Is screen locked:', RealIdle.getLocked());
	console.log('  - Is idle prevented:', RealIdle.getIdlePrevented());
}, 5000);

API

Functions

𝑓    getLocked
type getLocked = () => boolean

Returns true if the screen is locked and false if the screen is unlocked or if the function is not available on the current operating system.

Supported on: MacOS

𝑓    getIdleSeconds
type getIdleSeconds = () => number

Returns the system idle time in seconds, or -1 if the library couldn't fetch this value.

Supported on: Windows, MacOS, Linux (X11)

𝑓    getIdlePrevented
type getIdlePrevented = () => boolean

Returns true if the system idle is prevented (the screen would not automatically dim/lock). This is mostly the cause of having a video playing back in the front, attending a meeting, etc. The function returns false if no assertion or inhibitor is set or if the function is not available on the current operating system.

Supported on: MacOS, Linux (X11 and Gnome, but some other desktop environments should work too)

𝑓    getIdleState
type getIdleState = (idleThreshold: number): IdleState

Returns the idle state of the system based on the idle threshold (in seconds). It's supported on all operating systems, but see the Platform support section for the possible return values.

Supported on: Windows, MacOS, Linux (X11 and Gnome, but some other desktop environments should work too)

Enums

📋    IdleState
enum IdleState {
	active = 'active',
	idlePrevented = 'idle-prevented',
	idle = 'idle',
	locked = 'locked',
	unknown = 'unknown'
}

Meaning:

  • active: The user is actively using the system.
  • idlePrevented: Something (video playback, meeting, etc) is preventing the system from dimming the screen and locking it. The user may not input events into the system, but he/she is probably using it.
  • idle: The user is idle.
  • locked: The system is locked.
  • unknown: We failed to fetch some parameter or the library is not available for the current operating system.

Platform support

Supported functions

| Function / Platform | Windows | MacOS | Linux | |----------------------|---------|-------|-------| | getLocked() | NO | YES | NO | | getIdleSeconds() | YES | YES | YES | | getIdlePrevented() | NO | YES | YES | | getIdleState() | YES* | YES | YES* |

* See supported idle states below

Supported idle states

| State / Platform | Windows | MacOS | Linux | |------------------|---------|-------|-------| | active | YES | YES | YES | | idlePrevented | NO | YES | YES | | idle | YES | YES | YES | | locked | NO | YES | NO | | unknown | YES | YES | YES |

Default values

Even if a function/idle state is unsupported on a specific platform, you can safely call them. They will just return the default value for that function.

| Function | Default value | |----------------------|---------------| | getLocked() | false | | getIdleSeconds() | -1 | | getIdlePrevented() | false | | getIdleState() | 'unknown' |