UNPKG

@dderevjanik/termux-api

Version:

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

42 lines (41 loc) 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.callLog = callLog; const child_process_1 = require("child_process"); // TODO: Finish return data & type /** * List call log history * * **Requires permission:** `android.permission.READ_CALL_LOG` */ async function callLog(options = {}) { const opts = { limit: 10, offset: 0, ...options, }; return new Promise((resolve, reject) => { const command = `termux-call-log -l ${opts.limit} -o ${opts.offset}`; (0, child_process_1.exec)(command, (error, stdout, stderr) => { if (error) { return reject(`Error: ${error.message}`); } if (stderr) { return reject(`Error: ${stderr}`); } const output = stdout.trim(); if (output.length === 0) { // <https://github.com/termux/termux-api/issues/434> return reject(`Error: No call logs found`); } try { const callLogs = JSON.parse(output); resolve(callLogs); } catch (e) { reject(`Error: ${e.message}`); return; } }); }); }