New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

simple-keep-pc-awake

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-keep-pc-awake - npm Package Compare versions

Comparing version 1.0.4 to 1.1.0

105

index.js
#!/usr/bin/env node
//@ts-check
// Import nut-js which handles the mouse-moving functionalities
/** Import nut-js which handles the mouse-moving functionalities */
const { mouse, Point } = require("@nut-tree/nut-js");
const desktopIdle = require("desktop-idle");
// Read the command line arguments
/** Read the command line arguments */
const args = process.argv.slice(2);

@@ -12,6 +13,5 @@

OFFSET_PX: 1,
INTERVAL_SEC: 30,
MAX_IDLE_SEC: 120,
};
//#region time-helpers
/**

@@ -41,7 +41,15 @@ * Representing the digits in a double digit format (0 to 00, 8 to 08, 12 to 12, etc.);

};
//#endregion
//#region args-parser-helpers
/**
* Searches the args for --quiet param and if found should return true to surpass console.logs
*/
const isQuietMode = args.some((arg) => arg === "--quiet");
/**
* console.logs the message if quiet mode is off
* @param {string} message
*/
const log = (message) => (!isQuietMode ? console.log(message) : null);
/**
* Extracts argument from the process args with the key provided

@@ -53,20 +61,19 @@ * @param {string} param Key of the extracted value

const getArgParam = (param, defaultValue) => {
// Find the arg index which corresponds to the param provided
/** Find the arg index which corresponds to the param provided */
const paramTagIndex = args.findIndex((arg) => arg === param);
if (paramTagIndex < 0) return defaultValue;
// Get the next element in the array, so we know the value of the param
/** Get the next element in the array, so we know the value of the param */
const paramValueIndex = paramTagIndex + 1;
// If there is such value after param tag
/** If there is such value after param tag */
if (args[paramValueIndex]) {
// Try to parse it to float
/** Try to parse it to float */
const paramValueAsFloat = parseFloat(args[paramValueIndex]);
// If it is not a valid number, return the default value
/** If it is not a valid number, return the default value */
if (isNaN(paramValueAsFloat)) {
return defaultValue;
}
// Else return the user-configured value
else {
} else {
/** Else return the user-configured value */
return paramValueAsFloat;

@@ -76,3 +83,3 @@ }

// Default return, if no arg after --offset is provided
/** Default return, if no arg after --offset is provided */
return defaultValue;

@@ -90,45 +97,53 @@ };

/**
* Extracts the interval value from the --interval argument
* @returns {number} Amount of MS to wait before moving the cursor again. User defined or default.
* @typedef {Object} IMaxIdleTime
* @property {number} seconds - The time which the computer can stay idle in seconds
* @property {number} milliseconds - The time which the computer can stay idle in milliseconds
*
* Extracts the interval value from the --max-idle argument
* @returns {IMaxIdleTime} Amount of MS to wait before moving the cursor after system is idle. User defined or default.
*/
const getMoveInterval = () => {
return getArgParam("--interval", DEFAULTS.INTERVAL_SEC) * 1_000;
const getMaxIdleTime = () => {
const maxIdleTime = getArgParam("--max-idle", DEFAULTS.MAX_IDLE_SEC);
return {
seconds: maxIdleTime,
milliseconds: maxIdleTime * 1_000,
};
};
/**
* Searches the args for --quiet param and if found should return true to surpass console.logs
*/
const isQuietMode = args.some((arg) => arg === "--quiet");
//#endregion
/**
* console.logs the message if quiet mode is off
* @param {string} message
*/
const log = (message) => (!isQuietMode ? console.log(message) : null);
/**
* Moves the mouse cursor by X amount of pixels
* @param {number} offset How many pixels should the mouse be moved by
* @param {number} interval How many milliseconds to wait before moving the mouse again
* @param {IMaxIdleTime} maxIdleTime How many milliseconds to wait before moving the mouse again
*/
const mouseMover = async (offset, interval) => {
log(`\x1b[33m${now()}\x1b[0m Moved mouse cursor by ${offset} pixels`);
const keepAwake = async (offset, maxIdleTime) => {
/** Check if the idle time of the machine is higher than the max idle time */
if (desktopIdle.getIdleTime() >= maxIdleTime.seconds) {
log(`💤\x1b[33m ${now()}\x1b[0m System idling... Moving mouse`);
const prevPosition = await mouse.getPosition();
const coordinates = new Point(prevPosition.x + offset, prevPosition.y + offset);
await mouse.setPosition(coordinates);
/** Get last position of the cursor and move it by the given offset */
const prevPosition = await mouse.getPosition();
const coordinates = new Point(prevPosition.x + offset, prevPosition.y + offset);
await mouse.setPosition(coordinates);
}
/** Call the function recursively again to check after the max idle time */
setTimeout(() => {
mouseMover(offset * -1, interval);
}, interval);
/** Multiply offset by -1 to switch between 2 positions of the cursor (move it one direction and then back the same direction) */
keepAwake(offset * -1, maxIdleTime);
}, maxIdleTime.milliseconds);
};
const moveOffset = getMoveOffset();
const moveInterval = getMoveInterval();
/** Executed on startup. Should start all needed utilities for the wake keeper. */
const start = () => {
const moveOffset = getMoveOffset();
const maxIdleTime = getMaxIdleTime();
log("\x1b[32m 🚀 Started simple-keep-pc-awake...\x1b[0m");
log(`\x1b[34m INFO \x1b[0m Moving mouse cursor by ${moveOffset} pixels`);
log(`\x1b[34m INFO \x1b[0m Moving mouse cursor every ${moveInterval / 1_000} seconds`);
log("🚀\x1b[32m success \x1b[0mStarted simple-keep-pc-awake");
log(`⚙ \x1b[34m info \x1b[0mMouse move offset: ${moveOffset} pixels`);
log(`⚙ \x1b[34m info \x1b[0mMax idle time: ${maxIdleTime.seconds} seconds`);
mouseMover(moveOffset, moveInterval);
keepAwake(moveOffset, maxIdleTime);
};
start();
{
"name": "simple-keep-pc-awake",
"version": "1.0.4",
"version": "1.1.0",
"description": "A simple way to keep your PC awake with no configuration and setup.",
"main": "index.js",
"homepage": "https://github.com/mutafow/simple-keep-pc-awake#readme",
"scripts": {
"start": "node index.js",
"publish": "npm publish --access public"
"publish-npm": "npm publish --access public",
"build": "pkg index.js --output build/simple-keep-pc-awake -t node16-macos,node16-linux,node16-win"
},

@@ -20,4 +22,9 @@ "bin": "index.js",

"license": "ISC",
"repository": {
"type": "git",
"url": "https://github.com/mutafow/simple-keep-pc-awake"
},
"dependencies": {
"@nut-tree/nut-js": "^2.0.1"
"@nut-tree/nut-js": "^2.0.1",
"desktop-idle": "^1.3.0"
},

@@ -24,0 +31,0 @@ "devDependencies": {

# Simple Keep PC Awake
A simple quick program that keeps your PC awake by moving your mouse by 1px diagonally every 30 seconds. It has no interface as is intended to be as simple as possible.
A simple quick program that keeps your PC awake by moving your mouse by some pixels every time whenever the system has been idling more than the configured time. Default is: moves the mouse 1px back and forth, when the system has been idle for 120 seconds.
It has no interface as is intended to be as simple as possible.

@@ -26,3 +27,3 @@ ## Run via npx

To run via built executables, go to [the releases tab in the repo](https://github.com/mutafow/simple-keep-pc-awake/releases) and download the latest version of the binaries for your machine. Then simply run it when you need to keep your PC awake and close it when you don't!
To run via built executables, go to [the releases tab in the repo](https://github.com/mutafow/simple-keep-pc-awake/releases) and download the latest version of the binaries for your machine. Then simply run it and it will detect when you are idling and react accordingly. The executable will always use the default settings.

@@ -40,3 +41,3 @@ ## Options

--offset by how many pixels should the mouse move (default: 1)
--interval how much time should pass before mouse is moved again, in seconds (default: 30s)
--max-idle how much time should pass after system is idling before the script moves the mouse, in seconds (default: 120s)

@@ -46,4 +47,4 @@ Examples:

npx simple-keep-pc-awake --quiet --offset 5 moves the cursor by 5px each 30 seconds, in quiet mode
npx simple-keep-pc-awake --offset 5 --interval 100 moves the cursor by 5px each 100 seconds
npx simple-keep-pc-awake default behavior, moves the cursor by 1px every 30 seconds
npx simple-keep-pc-awake --offset 5 --max-idle 300 moves the cursor by 5px each 300 seconds (5 minutes)
npx simple-keep-pc-awake default behavior, moves the cursor by 1px after 120 seconds of idling
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc