UNPKG

@dderevjanik/termux-api

Version:

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

40 lines (37 loc) 837 B
import { exec } from "child_process"; export interface VibrateOptions { /** * The duration to vibrate in ms * @default 1000 */ duration?: number; /** * Force vibration even in silent mode * @default false */ force?: boolean; } /** * Vibrate the device */ export async function vibrate(options: VibrateOptions = {}): Promise<void> { const opts: VibrateOptions = { duration: 1_000, // number: "", ...options, }; return new Promise<void>((resolve, reject) => { const command = `termux-vibrate -d ${opts.duration} ${ opts.force ? "-f" : "" }`; exec(command, (error, stdout, stderr) => { if (error) { return reject(`Error: ${error.message}`); } if (stderr) { return reject(`Error: ${stderr}`); } return resolve(); }); }); }