UNPKG

@dderevjanik/termux-api

Version:

This library allows you to interact with your Android device from Node.js using termux-api

31 lines (28 loc) 803 B
import { exec } from "child_process"; export interface BrightnessOptions { /** * Set the screen brightness between 0 and 255 or auto * @default 240 */ value: number | "auto"; } /** * Set the screen brightness */ export async function brightness(options: BrightnessOptions): Promise<void> { if (options.value !== "auto" && (options.value < 0 || options.value > 255)) { throw new Error("Brightness value should be between 0 and 255"); } return new Promise<void>((resolve, reject) => { const command = `termux-brightness ${options.value}`; exec(command, (error, stdout, stderr) => { if (error) { return reject(`Error: ${error.message}`); } if (stderr) { return reject(`Error: ${stderr}`); } return resolve(); }); }); }