├── .gitignore ├── LICENSE ├── package.json ├── readme.md ├── src ├── index.ts ├── lib │ ├── ApiCommand.ts │ ├── ApiCommandFactory.ts │ ├── ApiResult.ts │ ├── ApiRunner.ts │ ├── TermuxApi.ts │ └── builders │ │ ├── BaseCommandBuilder.ts │ │ ├── BatteryStatusBuilder.ts │ │ ├── CameraInfoBuilder.ts │ │ ├── CameraPhotoBuilder.ts │ │ ├── ClipboardGetBuilder.ts │ │ ├── ClipboardSetBuilder.ts │ │ ├── ContactListBuilder.ts │ │ ├── DialogBuilder.ts │ │ ├── DownloadBuilder.ts │ │ ├── LocationBuilder.ts │ │ ├── NotificationBuilder.ts │ │ ├── SmsInboxBuilder.ts │ │ ├── SmsSendBuilder.ts │ │ ├── TTSEnginesBuilder.ts │ │ ├── TTSSpeakBuilder.ts │ │ ├── TelephonyCellInfoBuilder.ts │ │ ├── TelephonyDeviceInfoBuilder.ts │ │ ├── ToastBuilder.ts │ │ └── VibrateBuilder.ts └── samples │ ├── sample-battery-status.ts │ ├── sample-camera-info.ts │ ├── sample-camera-photo.ts │ ├── sample-clipboard-get.ts │ ├── sample-contact-list.ts │ ├── sample-dialog.ts │ ├── sample-download.ts │ ├── sample-location.ts │ ├── sample-notification.ts │ ├── sample-sms-inbox.ts │ ├── sample-sms-send.ts │ ├── sample-telephony-cellinfo.ts │ ├── sample-telephony-deviceinfo.ts │ ├── sample-toast.ts │ ├── sample-tts-engines.ts │ ├── sample-tts-speak.ts │ └── sample-vibrate.ts └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | .vscode 39 | dist 40 | typings 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Eduardo Pereira de Sousa 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "termux-api", 3 | "version": "0.0.1", 4 | "description": "A wrapper module for Termux-API", 5 | "main": "dist/index.js", 6 | "typings": "dist/index.d.ts", 7 | "files": [ 8 | "dist/index.*", 9 | "dist/lib" 10 | ], 11 | "scripts": { 12 | "test": "echo \"Error: no test specified\" && exit 1" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git+https://github.com/edupsousa/node-termux-api.git" 17 | }, 18 | "keywords": [ 19 | "android", 20 | "termux", 21 | "api" 22 | ], 23 | "author": "Eduardo P de Sousa ", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/edupsousa/node-termux-api/issues" 27 | }, 28 | "homepage": "https://github.com/edupsousa/node-termux-api#readme", 29 | "devDependencies": { 30 | "typescript": "^1.8.10", 31 | "@types/node": "^6.0.53" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Termux-API Wrapper for Node.JS 2 | 3 | ## This Repository is Unmaintained and Archived (Read-Only) 4 | 5 | Unfortunately, due to my work, i could not maintain this repository updated at this moment. 6 | 7 | This project aims to create a simple interface to invoke Termux-API commands 8 | directly from Node.JS applications. To use it you need to have Termux and Termux-API 9 | installed on your Android, and Node.JS installed on the Termux environment. 10 | 11 | ## What is Termux? 12 | 13 | From [Termux Website](https://termux.com/): "Termux is a terminal emulator and Linux environment bringing powerful terminal access to Android." 14 | 15 | With Termux you can run a small linux environment on your Android device, that means that you 16 | can run a small command-line utilities or a full-featured webserver directly from 17 | your Android phone. 18 | 19 | Install [Termux from Google Play](https://play.google.com/store/apps/details?id=com.termux) 20 | 21 | ## Termux-API 22 | 23 | Termux-API is a companion app to Termux, it creates an interface from Termux to your device 24 | features, with Termux-API you can take photos from your phone camera, get location 25 | from GPS, read or send SMS, and a lot of other features. Everything directly from the emulated 26 | Linux terminal. 27 | 28 | Install [Termux-API from Google Play](https://play.google.com/store/apps/details?id=com.termux.api) 29 | 30 | ## Node.JS on Termux 31 | 32 | Termux brings the possibily of running Node.JS on your Android device by simply installing it 33 | with APT (without rooting): 34 | 35 | ``` 36 | apt update 37 | apt install nodejs 38 | ```` 39 | 40 | # Usage 41 | 42 | Install the package on yout NPM project by: 43 | 44 | ``` 45 | npm install --save termux-api 46 | ``` 47 | 48 | Import the default object on JavaScript: 49 | 50 | ```javascript 51 | var api = require('termux-api').default; 52 | ``` 53 | 54 | Or with TypeScript: 55 | ```typescript 56 | import default as api from 'termux-api'; 57 | ``` 58 | 59 | Now you have a instance of the class TermuxApi as the api variable. To invoke API commands 60 | you must build it using the method createCommand(). 61 | 62 | The method createCommand() returns an instance of the ApiCommandFactory where you find 63 | one method for each API command you could invoke on Termux-API app. For example, to show 64 | a small popup, or [toast](https://developer.android.com/guide/topics/ui/notifiers/toasts.html) 65 | for those familiarized with Android UI you can use: 66 | 67 | 68 | ```javascript 69 | api.createCommand() 70 | .toast() 71 | .setText('Can you see me?') 72 | .shortDuration() 73 | .build() 74 | .run(); 75 | ``` 76 | 77 | * line 1: api.createCommand() returns an instance of [ApiCommandFactory](https://github.com/edupsousa/node-termux-api/blob/master/src/lib/ApiCommandFactory.ts) class. 78 | * line 2: ApiCommandFactory.toast() returns an instance of [ToastBuilder](https://github.com/edupsousa/node-termux-api/blob/master/src/lib/builders/ToastBuilder.ts) class. 79 | * line 3: ToastBuilder.setText() sets the text to be displayed and returns the ToastBuilder himself. 80 | * line 4: ToastBuilder.shortDuration() configures the toast to be displayed for a short while and returns himself (ToastBuilder). 81 | * line 5: ToastBuilder.build() builds and return a [ApiCommand](https://github.com/edupsousa/node-termux-api/blob/master/src/lib/ApiCommand.ts) instance. 82 | * line 6: The command is run. 83 | 84 | The process for calling other commands are very similar, you only need to change the 85 | command (line 2) and the options (lines 3 and 4). For example, to vibrate the 86 | phone for 1 second (1000 ms): 87 | 88 | ```javascript 89 | api.createCommand() 90 | .vibrate() 91 | .setDuration(1000) 92 | .build() 93 | .run(); 94 | ``` 95 | 96 | You can see all commands available on [ApiCommandFactory](https://github.com/edupsousa/node-termux-api/blob/master/src/lib/ApiCommandFactory.ts) 97 | source-code. And options for each command are availabe on the correspondent class in the 98 | [builders](https://github.com/edupsousa/node-termux-api/tree/master/src/lib/builders) folder. 99 | 100 | ### Returning data from the API 101 | 102 | Some API commands return data as String or JSON. To gather that data 103 | you could use the instance of [ApiResult](https://github.com/edupsousa/node-termux-api/blob/master/src/lib/ApiResult.ts) 104 | class returned by the method run() by invoking the methods getOutputObject() or getOutputString(). 105 | 106 | Notice that those 2 methods executes asynchronously returning ES6 107 | [Promises](https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/Promise) 108 | that resolves to an Object ou a String, respectively. 109 | 110 | For example to get a location update from GPS and show the returned object on console: 111 | 112 | ```javascript 113 | let result = api.createCommand() 114 | .location() 115 | .fromGPSProvider() 116 | .requestOnce() 117 | .build() 118 | .run(); 119 | 120 | result.getOutputObject() 121 | .then(function(location) { 122 | console.log('Last known location: ', location); 123 | }); 124 | 125 | ``` 126 | 127 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { TermuxApi } from './lib/TermuxApi'; 2 | let api = TermuxApi.getInstance(); 3 | export { TermuxApi } 4 | export default api; -------------------------------------------------------------------------------- /src/lib/ApiCommand.ts: -------------------------------------------------------------------------------- 1 | import { TermuxApi } from './TermuxApi'; 2 | import { ApiResult } from './ApiResult'; 3 | 4 | export class ApiCommand { 5 | private eParams: Map = new Map(); 6 | private esParams: Map = new Map(); 7 | private ezParams: Map = new Map(); 8 | private eiParams: Map = new Map(); 9 | private efParams: Map = new Map(); 10 | private esaParams: Map = new Map(); 11 | private lastArg: string = null; 12 | private input: string = null; 13 | constructor(public commandName: string) { 14 | 15 | } 16 | public run(): ApiResult { 17 | return TermuxApi.getInstance().runApi(this); 18 | } 19 | public setEParam(key: string, param: string): void { 20 | this.eParams.set(key, param); 21 | } 22 | public setESParam(key: string, param: string): void { 23 | this.esParams.set(key, param); 24 | } 25 | public setEZParam(key: string, param: boolean): void { 26 | let strParam: string = (param ? 'true' : 'false'); 27 | this.ezParams.set(key, strParam); 28 | } 29 | public setEIParam(key: string, param: number): void { 30 | let strParam: string = param.toString(); 31 | this.eiParams.set(key, strParam); 32 | } 33 | public setEFParam(key: string, param: number): void { 34 | let strParam: string = param.toString(); 35 | this.efParams.set(key, strParam); 36 | } 37 | public addESA(key: string, param: Array): void { 38 | let strParam: string = param.join(','); 39 | this.esaParams.set(key, strParam); 40 | } 41 | public setLastArg(arg: string): void { 42 | this.lastArg = arg; 43 | } 44 | public setStdinInput(input: string): void { 45 | if (input.substr(-1) !== '\n') { 46 | input += '\n'; 47 | } 48 | this.input = input; 49 | } 50 | public getInput(): string { 51 | return this.input; 52 | } 53 | public getArgs(): Array { 54 | let args: Array = []; 55 | 56 | args.concat(this.getArgsForParamType('e', this.eParams)); 57 | args.concat(this.getArgsForParamType('es', this.esParams)); 58 | args.concat(this.getArgsForParamType('ez', this.ezParams)); 59 | args.concat(this.getArgsForParamType('ei', this.eiParams)); 60 | args.concat(this.getArgsForParamType('ef', this.efParams)); 61 | args.concat(this.getArgsForParamType('esa', this.esaParams)); 62 | 63 | if (this.lastArg !== null) { 64 | args.push(this.lastArg); 65 | } 66 | return args; 67 | } 68 | private getArgsForParamType(paramType: string, parameters: Map): Array { 69 | let args = new Array(); 70 | for (let [key, value] of parameters.entries()) { 71 | args.push(`--${paramType}`); 72 | args.push(key); 73 | args.push(value); 74 | } 75 | return args; 76 | } 77 | } -------------------------------------------------------------------------------- /src/lib/ApiCommandFactory.ts: -------------------------------------------------------------------------------- 1 | import { BatteryStatusBuilder } from './builders/BatteryStatusBuilder'; 2 | import { CameraInfoBuilder } from './builders/CameraInfoBuilder'; 3 | import { CameraPhotoBuilder } from './builders/CameraPhotoBuilder'; 4 | import { ClipboardGetBuilder } from './builders/ClipboardGetBuilder'; 5 | import { ClipboardSetBuilder } from './builders/ClipboardSetBuilder'; 6 | import { ContactListBuilder } from './builders/ContactListBuilder'; 7 | import { DialogBuilder } from './builders/DialogBuilder'; 8 | import { DownloadBuilder } from './builders/DownloadBuilder'; 9 | import { LocationBuilder } from './builders/LocationBuilder'; 10 | import { NotificationBuilder } from './builders/NotificationBuilder'; 11 | import { SmsInboxBuilder } from './builders/SmsInboxBuilder'; 12 | import { SmsSendBuilder } from './builders/SmsSendBuilder'; 13 | import { TelephonyCellInfoBuilder } from './builders/TelephonyCellInfoBuilder'; 14 | import { TelephonyDeviceInfoBuilder } from './builders/TelephonyDeviceInfoBuilder'; 15 | import { ToastBuilder } from './builders/ToastBuilder'; 16 | import { VibrateBuilder } from './builders/VibrateBuilder'; 17 | import { TTSEnginesBuilder } from './builders/TTSEnginesBuilder'; 18 | import { TTSSpeakBuilder } from './builders/TTSSpeakBuilder'; 19 | 20 | export class ApiCommandFactory { 21 | public batteryStatus(): BatteryStatusBuilder { 22 | return new BatteryStatusBuilder(); 23 | } 24 | public cameraInfo(): CameraInfoBuilder { 25 | return new CameraInfoBuilder(); 26 | } 27 | public cameraPhoto(): CameraPhotoBuilder { 28 | return new CameraPhotoBuilder(); 29 | } 30 | public clipboardGet(): ClipboardGetBuilder { 31 | return new ClipboardGetBuilder(); 32 | } 33 | public clipboardSet(): ClipboardSetBuilder { 34 | return new ClipboardSetBuilder(); 35 | } 36 | public contactList(): ContactListBuilder { 37 | return new ContactListBuilder(); 38 | } 39 | public dialog(): DialogBuilder { 40 | return new DialogBuilder(); 41 | } 42 | public download(url: string): DownloadBuilder { 43 | return new DownloadBuilder().setUrl(url); 44 | } 45 | public location(): LocationBuilder { 46 | return new LocationBuilder(); 47 | } 48 | public notification(): NotificationBuilder { 49 | return new NotificationBuilder(); 50 | } 51 | public smsInbox(): SmsInboxBuilder { 52 | return new SmsInboxBuilder(); 53 | } 54 | public smsSend(): SmsSendBuilder { 55 | return new SmsSendBuilder(); 56 | } 57 | public telephonyCellInfo(): TelephonyCellInfoBuilder { 58 | return new TelephonyCellInfoBuilder(); 59 | } 60 | public telephonyDeviceInfo(): TelephonyDeviceInfoBuilder { 61 | return new TelephonyDeviceInfoBuilder(); 62 | } 63 | public toast(): ToastBuilder { 64 | return new ToastBuilder(); 65 | } 66 | public vibrate(): VibrateBuilder { 67 | return new VibrateBuilder(); 68 | } 69 | public ttsEngines(): TTSEnginesBuilder { 70 | return new TTSEnginesBuilder(); 71 | } 72 | public ttsSpeak(): TTSSpeakBuilder { 73 | return new TTSSpeakBuilder(); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/lib/ApiResult.ts: -------------------------------------------------------------------------------- 1 | import { ChildProcess } from 'child_process'; 2 | import { Readable } from 'stream'; 3 | 4 | export class ApiResult { 5 | private apiProcess: ChildProcess; 6 | private output: Promise; 7 | private statusCode: Promise; 8 | private apiRunning: boolean; 9 | constructor(apiProcess: ChildProcess) { 10 | this.apiRunning = true; 11 | this.apiProcess = apiProcess; 12 | this.output = this.readStream(this.apiProcess.stdout); 13 | this.statusCode = this.readStatusCode(); 14 | } 15 | public async getStatusCode(): Promise { 16 | return await this.statusCode; 17 | } 18 | public isRunning(): boolean { 19 | return this.apiRunning; 20 | } 21 | public async getOutputObject(): Promise { 22 | let output = await this.output; 23 | try { 24 | return JSON.parse(output); 25 | } catch (e) { 26 | console.error(e); 27 | throw e; 28 | } 29 | } 30 | public async getOutputString(): Promise { 31 | return await this.output; 32 | } 33 | public killApi(): void { 34 | this.apiProcess.kill('SIGHUP'); 35 | } 36 | private async readStatusCode(): Promise { 37 | return new Promise(resolve => { 38 | this.apiProcess.on('close', code => { 39 | this.apiRunning = false; 40 | resolve(code); 41 | }); 42 | }); 43 | } 44 | private async readStream(stream: Readable): Promise { 45 | return new Promise((resolve, reject) => { 46 | let data = []; 47 | stream.on('data', (chunk) => { 48 | data.push(chunk); 49 | }); 50 | stream.on('end', () => { 51 | resolve(Buffer.concat(data).toString()); 52 | }); 53 | stream.on('error', (error) => { 54 | reject(error); 55 | }); 56 | }); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/lib/ApiRunner.ts: -------------------------------------------------------------------------------- 1 | import { ApiCommand } from './ApiCommand'; 2 | import { ApiResult } from './ApiResult'; 3 | import { spawn } from 'child_process'; 4 | 5 | export class ApiRunner { 6 | constructor(public apiPath: string) { 7 | 8 | } 9 | public runCommand(command: ApiCommand): ApiResult { 10 | let args = [command.commandName].concat(command.getArgs()); 11 | let api = spawn(this.apiPath, args); 12 | let childInput = command.getInput(); 13 | if (childInput !== null) { 14 | api.stdin.end(childInput); 15 | } 16 | return new ApiResult(api); 17 | } 18 | } -------------------------------------------------------------------------------- /src/lib/TermuxApi.ts: -------------------------------------------------------------------------------- 1 | import { ApiCommand } from './ApiCommand'; 2 | import { ApiCommandFactory } from './ApiCommandFactory'; 3 | import { ApiRunner } from './ApiRunner'; 4 | import { ApiResult } from './ApiResult'; 5 | import { access, constants } from 'fs'; 6 | 7 | const DEFAULT_API_PATH = '/data/data/com.termux/files/usr/libexec/termux-api'; 8 | 9 | export class TermuxApi { 10 | private static _instance: TermuxApi = new TermuxApi(); 11 | protected commandFactory: ApiCommandFactory; 12 | protected apiRunner: ApiRunner; 13 | 14 | constructor(apiPath: string = DEFAULT_API_PATH) { 15 | if (TermuxApi._instance) { 16 | throw new Error('Use TermuxApi.getInstance() instead!'); 17 | } 18 | TermuxApi._instance = this; 19 | this.apiRunner = new ApiRunner(apiPath); 20 | this.commandFactory = new ApiCommandFactory(); 21 | } 22 | public static getInstance(): TermuxApi { 23 | return TermuxApi._instance; 24 | } 25 | public async apiExists(): Promise { 26 | return new Promise(resolve => { 27 | access(this.apiRunner.apiPath, constants.X_OK, err => { 28 | if (err) 29 | resolve(false); 30 | resolve(true); 31 | }); 32 | }); 33 | } 34 | public runApi(moduleConfig: ApiCommand): ApiResult { 35 | return this.apiRunner.runCommand(moduleConfig); 36 | } 37 | public createCommand(): ApiCommandFactory { 38 | return this.commandFactory; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/lib/builders/BaseCommandBuilder.ts: -------------------------------------------------------------------------------- 1 | import { ApiCommand } from '../ApiCommand'; 2 | import { ApiResult } from '../ApiResult'; 3 | import { TermuxApi } from '../TermuxApi'; 4 | 5 | export class BaseCommandBuilder { 6 | protected command: ApiCommand; 7 | constructor(apiCommand: string) { 8 | this.command = new ApiCommand(apiCommand); 9 | } 10 | public build(): ApiCommand { 11 | return this.command; 12 | } 13 | } -------------------------------------------------------------------------------- /src/lib/builders/BatteryStatusBuilder.ts: -------------------------------------------------------------------------------- 1 | import { BaseCommandBuilder } from './BaseCommandBuilder'; 2 | 3 | export class BatteryStatusBuilder extends BaseCommandBuilder { 4 | constructor() { 5 | super('BatteryStatus'); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/lib/builders/CameraInfoBuilder.ts: -------------------------------------------------------------------------------- 1 | import { BaseCommandBuilder } from './BaseCommandBuilder'; 2 | 3 | export class CameraInfoBuilder extends BaseCommandBuilder { 4 | constructor() { 5 | super('CameraInfo'); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/lib/builders/CameraPhotoBuilder.ts: -------------------------------------------------------------------------------- 1 | import { BaseCommandBuilder } from './BaseCommandBuilder'; 2 | 3 | export class CameraPhotoBuilder extends BaseCommandBuilder { 4 | constructor() { 5 | super('CameraPhoto'); 6 | } 7 | public setOutputFile(path: string): CameraPhotoBuilder { 8 | this.command.setESParam('file', path); 9 | return this; 10 | } 11 | public setCamera(id: Number): CameraPhotoBuilder { 12 | this.command.setESParam('camera', id.toString()); 13 | return this; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/lib/builders/ClipboardGetBuilder.ts: -------------------------------------------------------------------------------- 1 | 2 | import { BaseCommandBuilder } from './BaseCommandBuilder'; 3 | 4 | export class ClipboardGetBuilder extends BaseCommandBuilder { 5 | constructor() { 6 | super('Clipboard'); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/lib/builders/ClipboardSetBuilder.ts: -------------------------------------------------------------------------------- 1 | 2 | import { BaseCommandBuilder } from './BaseCommandBuilder'; 3 | 4 | export class ClipboardSetBuilder extends BaseCommandBuilder { 5 | constructor() { 6 | super('Clipboard'); 7 | this.command.setEParam('api_version', '2'); 8 | this.command.setEZParam('set', true); 9 | } 10 | setContents(text: string): ClipboardSetBuilder { 11 | this.command.setStdinInput(text); 12 | return this; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/lib/builders/ContactListBuilder.ts: -------------------------------------------------------------------------------- 1 | import { BaseCommandBuilder } from './BaseCommandBuilder'; 2 | 3 | export class ContactListBuilder extends BaseCommandBuilder { 4 | constructor() { 5 | super('ContactList'); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/lib/builders/DialogBuilder.ts: -------------------------------------------------------------------------------- 1 | import { BaseCommandBuilder } from './BaseCommandBuilder'; 2 | 3 | export class DialogBuilder extends BaseCommandBuilder { 4 | constructor() { 5 | super('Dialog'); 6 | } 7 | public setTypePassword(): DialogBuilder { 8 | this.command.setESParam('input_type', 'password'); 9 | return this; 10 | } 11 | public setTitle(title: string): DialogBuilder { 12 | this.command.setESParam('input_title', title); 13 | return this; 14 | } 15 | public setHint(title: string): DialogBuilder { 16 | this.command.setESParam('input_hint', title); 17 | return this; 18 | } 19 | public setMultiline(): DialogBuilder { 20 | this.command.setEZParam('multiple_lines', true); 21 | return this; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/lib/builders/DownloadBuilder.ts: -------------------------------------------------------------------------------- 1 | import { BaseCommandBuilder } from './BaseCommandBuilder'; 2 | 3 | export class DownloadBuilder extends BaseCommandBuilder { 4 | constructor() { 5 | super('Download'); 6 | } 7 | public setUrl(url: string): DownloadBuilder { 8 | this.command.setLastArg(url); 9 | return this; 10 | } 11 | public setDescription(description: string): DownloadBuilder { 12 | this.command.setESParam('description', description); 13 | return this; 14 | } 15 | public setTitle(title: string): DownloadBuilder { 16 | this.command.setESParam('title', title); 17 | return this; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/lib/builders/LocationBuilder.ts: -------------------------------------------------------------------------------- 1 | import { BaseCommandBuilder } from './BaseCommandBuilder'; 2 | 3 | export class LocationBuilder extends BaseCommandBuilder { 4 | constructor() { 5 | super('Location'); 6 | } 7 | public fromGPSProvider(): LocationBuilder { 8 | this.command.setESParam('provider', 'gps'); 9 | return this; 10 | } 11 | public fromNetworkProvider(): LocationBuilder { 12 | this.command.setESParam('provider', 'network'); 13 | return this; 14 | } 15 | public fromPassiveProvider(): LocationBuilder { 16 | this.command.setESParam('provider', 'passive'); 17 | return this; 18 | } 19 | public requestLast(): LocationBuilder { 20 | this.command.setESParam('request', 'last'); 21 | return this; 22 | } 23 | public requestOnce(): LocationBuilder { 24 | this.command.setESParam('request', 'once'); 25 | return this; 26 | } 27 | public requestUpdates(): LocationBuilder { 28 | this.command.setESParam('request', 'updates'); 29 | return this; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/lib/builders/NotificationBuilder.ts: -------------------------------------------------------------------------------- 1 | import { BaseCommandBuilder } from './BaseCommandBuilder'; 2 | 3 | export class NotificationBuilder extends BaseCommandBuilder { 4 | constructor() { 5 | super('Notification'); 6 | } 7 | public setContent(content: string): NotificationBuilder { 8 | this.command.setESParam('content', content); 9 | return this; 10 | } 11 | public setId(id: string): NotificationBuilder { 12 | this.command.setESParam('id', id); 13 | return this; 14 | } 15 | public setTitle(title: string): NotificationBuilder { 16 | this.command.setESParam('title', title); 17 | return this; 18 | } 19 | public setUrl(url: string): NotificationBuilder { 20 | this.command.setESParam('url', url); 21 | return this; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/lib/builders/SmsInboxBuilder.ts: -------------------------------------------------------------------------------- 1 | import { BaseCommandBuilder } from './BaseCommandBuilder'; 2 | 3 | export class SmsInboxBuilder extends BaseCommandBuilder { 4 | constructor() { 5 | super('SmsInbox'); 6 | } 7 | public showPhoneNumbers(): SmsInboxBuilder { 8 | this.command.setEZParam('show-phone-numbers', true); 9 | return this; 10 | } 11 | public showDates(): SmsInboxBuilder { 12 | this.command.setEZParam('show-dates', true); 13 | return this; 14 | } 15 | public offset(offset: number): SmsInboxBuilder { 16 | this.command.setEIParam('offset', offset); 17 | return this; 18 | } 19 | public limit(limit: number): SmsInboxBuilder { 20 | this.command.setEIParam('limit', limit); 21 | return this; 22 | } 23 | } -------------------------------------------------------------------------------- /src/lib/builders/SmsSendBuilder.ts: -------------------------------------------------------------------------------- 1 | import { BaseCommandBuilder } from './BaseCommandBuilder'; 2 | 3 | export class SmsSendBuilder extends BaseCommandBuilder { 4 | constructor() { 5 | super('SmsSend'); 6 | } 7 | public setRecipients(recipients: Array): SmsSendBuilder { 8 | this.command.addESA('recipients', recipients); 9 | return this; 10 | } 11 | public setRecipient(recipient: string): SmsSendBuilder { 12 | this.setRecipients([recipient]); 13 | return this; 14 | } 15 | public setMessage(message: string): SmsSendBuilder { 16 | this.command.setLastArg(message); 17 | return this; 18 | } 19 | } -------------------------------------------------------------------------------- /src/lib/builders/TTSEnginesBuilder.ts: -------------------------------------------------------------------------------- 1 | import { BaseCommandBuilder } from './BaseCommandBuilder'; 2 | 3 | export class TTSEnginesBuilder extends BaseCommandBuilder { 4 | constructor() { 5 | super('TextToSpeech'); 6 | this.command.setESParam('engine', 'LIST_AVAILABLE'); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/lib/builders/TTSSpeakBuilder.ts: -------------------------------------------------------------------------------- 1 | import { BaseCommandBuilder } from './BaseCommandBuilder'; 2 | 3 | export class TTSSpeakBuilder extends BaseCommandBuilder { 4 | constructor() { 5 | super('TextToSpeech'); 6 | this.command.setESParam('engine', 'LIST_AVAILABLE'); 7 | } 8 | setEngine(engine: string): TTSSpeakBuilder { 9 | this.command.setESParam('engine', engine); 10 | return this; 11 | } 12 | setLanguage(language: string): TTSSpeakBuilder { 13 | this.command.setESParam('language', language); 14 | return this; 15 | } 16 | setPitch(pitch: number): TTSSpeakBuilder { 17 | this.command.setEFParam('pitch', pitch); 18 | return this; 19 | } 20 | setRate(rate: number): TTSSpeakBuilder { 21 | this.command.setEFParam('rate', rate); 22 | return this; 23 | } 24 | setTextToSpeak(textToSpeak: string): TTSSpeakBuilder { 25 | this.command.setStdinInput(textToSpeak); 26 | return this; 27 | } 28 | streamAsAlarm(): TTSSpeakBuilder { 29 | this.command.setESParam('stream', 'ALARM'); 30 | return this; 31 | } 32 | streamAsMusic(): TTSSpeakBuilder { 33 | this.command.setESParam('stream', 'MUSIC'); 34 | return this; 35 | } 36 | streamAsNotification(): TTSSpeakBuilder { 37 | this.command.setESParam('stream', 'NOTIFICATION'); 38 | return this; 39 | } 40 | streamAsRing(): TTSSpeakBuilder { 41 | this.command.setESParam('stream', 'RING'); 42 | return this; 43 | } 44 | streamAsSystem(): TTSSpeakBuilder { 45 | this.command.setESParam('stream', 'SYSTEM'); 46 | return this; 47 | } 48 | streamAsVoiceCall(): TTSSpeakBuilder { 49 | this.command.setESParam('stream', 'VOICE_CALL'); 50 | return this; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/lib/builders/TelephonyCellInfoBuilder.ts: -------------------------------------------------------------------------------- 1 | import { BaseCommandBuilder } from './BaseCommandBuilder'; 2 | 3 | export class TelephonyCellInfoBuilder extends BaseCommandBuilder { 4 | constructor() { 5 | super('TelephonyCellInfo'); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/lib/builders/TelephonyDeviceInfoBuilder.ts: -------------------------------------------------------------------------------- 1 | import { BaseCommandBuilder } from './BaseCommandBuilder'; 2 | 3 | export class TelephonyDeviceInfoBuilder extends BaseCommandBuilder { 4 | constructor() { 5 | super('TelephonyDeviceInfo'); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/lib/builders/ToastBuilder.ts: -------------------------------------------------------------------------------- 1 | import { BaseCommandBuilder } from './BaseCommandBuilder'; 2 | 3 | export class ToastBuilder extends BaseCommandBuilder { 4 | constructor() { 5 | super('Toast'); 6 | } 7 | setText(text: string): ToastBuilder { 8 | this.command.setStdinInput(text); 9 | return this; 10 | } 11 | shortDuration(): ToastBuilder { 12 | this.command.setEZParam('short', true); 13 | return this; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/lib/builders/VibrateBuilder.ts: -------------------------------------------------------------------------------- 1 | import { BaseCommandBuilder } from './BaseCommandBuilder'; 2 | 3 | export class VibrateBuilder extends BaseCommandBuilder { 4 | constructor() { 5 | super('Vibrate'); 6 | } 7 | setDuration(duration: number): VibrateBuilder { 8 | this.command.setEIParam('duration_ms', duration); 9 | return this; 10 | } 11 | force(): VibrateBuilder { 12 | this.command.setEZParam('force', true); 13 | return this; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/samples/sample-battery-status.ts: -------------------------------------------------------------------------------- 1 | import { TermuxApi } from '../lib/TermuxApi'; 2 | 3 | async function main() { 4 | let api = TermuxApi.getInstance(); 5 | let exists = await api.apiExists(); 6 | 7 | if (exists) { 8 | let result = api.createCommand() 9 | .batteryStatus() 10 | .build() 11 | .run(); 12 | let code = await result.getStatusCode(); 13 | if (code !== 0) { 14 | console.log('Error executing API'); 15 | } else { 16 | console.log('API successfully executed.'); 17 | console.log(await result.getOutputObject()); 18 | } 19 | } else { 20 | console.log('Error: Termux-API not found. Please install Termux-Api from Google Play.'); 21 | } 22 | } 23 | 24 | try { 25 | main(); 26 | } catch (e) { 27 | console.error(e); 28 | } -------------------------------------------------------------------------------- /src/samples/sample-camera-info.ts: -------------------------------------------------------------------------------- 1 | import { TermuxApi } from '../lib/TermuxApi'; 2 | 3 | async function main() { 4 | let api = TermuxApi.getInstance(); 5 | let exists = await api.apiExists(); 6 | 7 | if (exists) { 8 | let result = api.createCommand() 9 | .cameraInfo() 10 | .build() 11 | .run(); 12 | 13 | let code = await result.getStatusCode(); 14 | if (code !== 0) { 15 | console.log('Error executing API'); 16 | } else { 17 | console.log('API successfully executed.'); 18 | console.log(await result.getOutputObject()); 19 | } 20 | } else { 21 | console.log('Error: Termux-API not found. Please install Termux-Api from Google Play.'); 22 | } 23 | } 24 | 25 | try { 26 | main(); 27 | } catch (e) { 28 | console.error(e); 29 | } -------------------------------------------------------------------------------- /src/samples/sample-camera-photo.ts: -------------------------------------------------------------------------------- 1 | import { TermuxApi } from '../lib/TermuxApi'; 2 | 3 | async function main() { 4 | let api = TermuxApi.getInstance(); 5 | let exists = await api.apiExists(); 6 | 7 | if (exists) { 8 | let result = api.createCommand() 9 | .cameraPhoto() 10 | .setOutputFile('/data/data/com.termux/files/home/photo.jpg') 11 | .setCamera(0) 12 | .build() 13 | .run(); 14 | 15 | let code = await result.getStatusCode(); 16 | if (code !== 0) { 17 | console.log('Error executing API'); 18 | } else { 19 | console.log('API successfully executed.'); 20 | } 21 | } else { 22 | console.log('Error: Termux-API not found. Please install Termux-Api from Google Play.'); 23 | } 24 | } 25 | 26 | try { 27 | main(); 28 | } catch (e) { 29 | console.error(e); 30 | } -------------------------------------------------------------------------------- /src/samples/sample-clipboard-get.ts: -------------------------------------------------------------------------------- 1 | import { TermuxApi } from '../lib/TermuxApi'; 2 | 3 | async function main() { 4 | let api = TermuxApi.getInstance(); 5 | let exists = await api.apiExists(); 6 | 7 | if (exists) { 8 | let result = api.createCommand() 9 | .clipboardGet() 10 | .build() 11 | .run(); 12 | 13 | let code = await result.getStatusCode(); 14 | if (code !== 0) { 15 | console.log('Error executing API'); 16 | } else { 17 | console.log('API successfully executed.'); 18 | console.log(await result.getOutputString()); 19 | } 20 | } else { 21 | console.log('Error: Termux-API not found. Please install Termux-Api from Google Play.'); 22 | } 23 | } 24 | 25 | try { 26 | main(); 27 | } catch (e) { 28 | console.error(e); 29 | } -------------------------------------------------------------------------------- /src/samples/sample-contact-list.ts: -------------------------------------------------------------------------------- 1 | import { TermuxApi } from '../lib/TermuxApi'; 2 | 3 | async function main() { 4 | let api = TermuxApi.getInstance(); 5 | let exists = await api.apiExists(); 6 | 7 | if (exists) { 8 | let result = api.createCommand() 9 | .contactList() 10 | .build() 11 | .run(); 12 | 13 | let code = await result.getStatusCode(); 14 | if (code !== 0) { 15 | console.log('Error executing API'); 16 | } else { 17 | console.log('API successfully executed.'); 18 | console.log(await result.getOutputObject()); 19 | } 20 | } else { 21 | console.log('Error: Termux-API not found. Please install Termux-Api from Google Play.'); 22 | } 23 | } 24 | 25 | try { 26 | main(); 27 | } catch (e) { 28 | console.error(e); 29 | } -------------------------------------------------------------------------------- /src/samples/sample-dialog.ts: -------------------------------------------------------------------------------- 1 | import { TermuxApi } from '../lib/TermuxApi'; 2 | 3 | async function main() { 4 | let api = TermuxApi.getInstance(); 5 | let exists = await api.apiExists(); 6 | 7 | if (exists) { 8 | let result = api.createCommand() 9 | .dialog() 10 | .setTitle('Password Dialog') 11 | //.setTypePassword() 12 | //.setMultiline() 13 | .setHint('Hint for the input.') 14 | .build() 15 | .run(); 16 | 17 | let code = await result.getStatusCode(); 18 | if (code !== 0) { 19 | console.log('Error executing API'); 20 | } else { 21 | console.log('API successfully executed.'); 22 | console.log(await result.getOutputString()); 23 | } 24 | } else { 25 | console.log('Error: Termux-API not found. Please install Termux-Api from Google Play.'); 26 | } 27 | } 28 | 29 | try { 30 | main(); 31 | } catch (e) { 32 | console.error(e); 33 | } -------------------------------------------------------------------------------- /src/samples/sample-download.ts: -------------------------------------------------------------------------------- 1 | import { TermuxApi } from '../lib/TermuxApi'; 2 | 3 | async function main() { 4 | let api = TermuxApi.getInstance(); 5 | let exists = await api.apiExists(); 6 | 7 | if (exists) { 8 | let result = api.createCommand() 9 | .download('http://speedtest.ftp.otenet.gr/files/test100k.db') 10 | .setTitle('Download Title') 11 | .setDescription('Download Description') 12 | .build() 13 | .run(); 14 | 15 | let code = await result.getStatusCode(); 16 | if (code !== 0) { 17 | console.log('Error executing API'); 18 | } else { 19 | console.log('API successfully executed.'); 20 | } 21 | } else { 22 | console.log('Error: Termux-API not found. Please install Termux-Api from Google Play.'); 23 | } 24 | } 25 | 26 | try { 27 | main(); 28 | } catch (e) { 29 | console.error(e); 30 | } -------------------------------------------------------------------------------- /src/samples/sample-location.ts: -------------------------------------------------------------------------------- 1 | import { TermuxApi } from '../lib/TermuxApi'; 2 | 3 | async function main() { 4 | let api = TermuxApi.getInstance(); 5 | let exists = await api.apiExists(); 6 | 7 | if (exists) { 8 | let result = api.createCommand() 9 | .location() 10 | .fromGPSProvider() 11 | .requestOnce() 12 | .build() 13 | .run(); 14 | 15 | let code = await result.getStatusCode(); 16 | if (code !== 0) { 17 | console.log('Error executing API'); 18 | } else { 19 | console.log('API successfully executed.'); 20 | console.log(await result.getOutputObject()); 21 | } 22 | } else { 23 | console.log('Error: Termux-API not found. Please install Termux-Api from Google Play.'); 24 | } 25 | } 26 | 27 | try { 28 | main(); 29 | } catch (e) { 30 | console.error(e); 31 | } -------------------------------------------------------------------------------- /src/samples/sample-notification.ts: -------------------------------------------------------------------------------- 1 | import { TermuxApi } from '../lib/TermuxApi'; 2 | 3 | async function main() { 4 | let api = TermuxApi.getInstance(); 5 | let exists = await api.apiExists(); 6 | 7 | if (exists) { 8 | let result = api.createCommand() 9 | .notification() 10 | .setId("sample") 11 | .setTitle("Sample") 12 | .setContent("This is a sample notification from node-termux-api.") 13 | .setUrl("https://github.com/edupsousa/node-termux-api") 14 | .build() 15 | .run(); 16 | 17 | let code = await result.getStatusCode(); 18 | if (code !== 0) { 19 | console.log('Error executing API'); 20 | } else { 21 | console.log('API successfully executed.'); 22 | } 23 | } else { 24 | console.log('Error: Termux-API not found. Please install Termux-Api from Google Play.'); 25 | } 26 | } 27 | 28 | try { 29 | main(); 30 | } catch (e) { 31 | console.error(e); 32 | } -------------------------------------------------------------------------------- /src/samples/sample-sms-inbox.ts: -------------------------------------------------------------------------------- 1 | import { TermuxApi } from '../lib/TermuxApi'; 2 | 3 | async function main() { 4 | let api = TermuxApi.getInstance(); 5 | let exists = await api.apiExists(); 6 | 7 | if (exists) { 8 | let result = api.createCommand() 9 | .smsInbox() 10 | .showDates() 11 | .showPhoneNumbers() 12 | .limit(10) 13 | .offset(0) 14 | .build() 15 | .run(); 16 | 17 | let code = await result.getStatusCode(); 18 | if (code !== 0) { 19 | console.log('Error executing API'); 20 | } else { 21 | console.log('API successfully executed.'); 22 | console.log(await result.getOutputObject()); 23 | } 24 | } else { 25 | console.log('Error: Termux-API not found. Please install Termux-Api from Google Play.'); 26 | } 27 | } 28 | 29 | try { 30 | main(); 31 | } catch (e) { 32 | console.error(e); 33 | } -------------------------------------------------------------------------------- /src/samples/sample-sms-send.ts: -------------------------------------------------------------------------------- 1 | import { TermuxApi } from '../lib/TermuxApi'; 2 | 3 | async function main() { 4 | let api = TermuxApi.getInstance(); 5 | let exists = await api.apiExists(); 6 | 7 | if (exists) { 8 | let result = api.createCommand() 9 | .smsSend() 10 | .setRecipient('123') 11 | .setMessage('Hello World') 12 | .build() 13 | .run(); 14 | 15 | let code = await result.getStatusCode(); 16 | if (code !== 0) { 17 | console.log('Error executing API'); 18 | } else { 19 | console.log('API successfully executed.'); 20 | console.log(await result.getOutputObject()); 21 | } 22 | } else { 23 | console.log('Error: Termux-API not found. Please install Termux-Api from Google Play.'); 24 | } 25 | } 26 | 27 | try { 28 | main(); 29 | } catch (e) { 30 | console.error(e); 31 | } -------------------------------------------------------------------------------- /src/samples/sample-telephony-cellinfo.ts: -------------------------------------------------------------------------------- 1 | import { TermuxApi } from '../lib/TermuxApi'; 2 | 3 | async function main() { 4 | let api = TermuxApi.getInstance(); 5 | let exists = await api.apiExists(); 6 | 7 | if (exists) { 8 | let result = api.createCommand() 9 | .telephonyCellInfo() 10 | .build() 11 | .run(); 12 | 13 | let code = await result.getStatusCode(); 14 | if (code !== 0) { 15 | console.log('Error executing API'); 16 | } else { 17 | console.log('API successfully executed.'); 18 | console.log(await result.getOutputObject()); 19 | } 20 | } else { 21 | console.log('Error: Termux-API not found. Please install Termux-Api from Google Play.'); 22 | } 23 | } 24 | 25 | try { 26 | main(); 27 | } catch (e) { 28 | console.error(e); 29 | } -------------------------------------------------------------------------------- /src/samples/sample-telephony-deviceinfo.ts: -------------------------------------------------------------------------------- 1 | import { TermuxApi } from '../lib/TermuxApi'; 2 | 3 | async function main() { 4 | let api = TermuxApi.getInstance(); 5 | let exists = await api.apiExists(); 6 | 7 | if (exists) { 8 | let result = api.createCommand() 9 | .telephonyDeviceInfo() 10 | .build() 11 | .run(); 12 | 13 | let code = await result.getStatusCode(); 14 | if (code !== 0) { 15 | console.log('Error executing API'); 16 | } else { 17 | console.log('API successfully executed.'); 18 | console.log(await result.getOutputObject()); 19 | } 20 | } else { 21 | console.log('Error: Termux-API not found. Please install Termux-Api from Google Play.'); 22 | } 23 | } 24 | 25 | try { 26 | main(); 27 | } catch (e) { 28 | console.error(e); 29 | } -------------------------------------------------------------------------------- /src/samples/sample-toast.ts: -------------------------------------------------------------------------------- 1 | import { TermuxApi } from '../lib/TermuxApi'; 2 | 3 | async function main() { 4 | let api = TermuxApi.getInstance(); 5 | let exists = await api.apiExists(); 6 | 7 | if (exists) { 8 | let result = api.createCommand() 9 | .toast() 10 | .setText('It`s a little toast showing for a short while.') 11 | .shortDuration() 12 | .build() 13 | .run(); 14 | 15 | let code = await result.getStatusCode(); 16 | if (code !== 0) { 17 | console.log('Error executing API'); 18 | } else { 19 | console.log('API successfully executed.'); 20 | } 21 | } else { 22 | console.log('Error: Termux-API not found. Please install Termux-Api from Google Play.'); 23 | } 24 | } 25 | 26 | try { 27 | main(); 28 | } catch (e) { 29 | console.error(e); 30 | } -------------------------------------------------------------------------------- /src/samples/sample-tts-engines.ts: -------------------------------------------------------------------------------- 1 | import { TermuxApi } from '../lib/TermuxApi'; 2 | 3 | async function main() { 4 | let api = TermuxApi.getInstance(); 5 | let exists = await api.apiExists(); 6 | 7 | if (exists) { 8 | let result = api.createCommand() 9 | .ttsEngines() 10 | .build() 11 | .run(); 12 | 13 | let code = await result.getStatusCode(); 14 | if (code !== 0) { 15 | console.log('Error executing API'); 16 | } else { 17 | console.log('API successfully executed.'); 18 | console.log(await result.getOutputObject()); 19 | } 20 | } else { 21 | console.log('Error: Termux-API not found. Please install Termux-Api from Google Play.'); 22 | } 23 | } 24 | 25 | try { 26 | main(); 27 | } catch (e) { 28 | console.error(e); 29 | } -------------------------------------------------------------------------------- /src/samples/sample-tts-speak.ts: -------------------------------------------------------------------------------- 1 | import { TermuxApi } from '../lib/TermuxApi'; 2 | 3 | async function main() { 4 | let api = TermuxApi.getInstance(); 5 | let exists = await api.apiExists(); 6 | 7 | if (exists) { 8 | let result = api.createCommand() 9 | .ttsSpeak() 10 | .setTextToSpeak("Thank you for using this library.") 11 | .build() 12 | .run(); 13 | 14 | let code = await result.getStatusCode(); 15 | if (code !== 0) { 16 | console.log('Error executing API'); 17 | } else { 18 | console.log('API successfully executed.'); 19 | } 20 | } else { 21 | console.log('Error: Termux-API not found. Please install Termux-Api from Google Play.'); 22 | } 23 | } 24 | 25 | try { 26 | main(); 27 | } catch (e) { 28 | console.error(e); 29 | } -------------------------------------------------------------------------------- /src/samples/sample-vibrate.ts: -------------------------------------------------------------------------------- 1 | import { TermuxApi } from '../lib/TermuxApi'; 2 | 3 | async function main() { 4 | let api = TermuxApi.getInstance(); 5 | let exists = await api.apiExists(); 6 | 7 | if (exists) { 8 | let result = api.createCommand() 9 | .vibrate() 10 | .setDuration(500) 11 | .build() 12 | .run(); 13 | 14 | let code = await result.getStatusCode(); 15 | if (code !== 0) { 16 | console.log('Error executing API'); 17 | } else { 18 | console.log('API successfully executed.'); 19 | } 20 | } else { 21 | console.log('Error: Termux-API not found. Please install Termux-Api from Google Play.'); 22 | } 23 | } 24 | 25 | try { 26 | main(); 27 | } catch (e) { 28 | console.error(e); 29 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "commonjs", 5 | "outDir": "dist", 6 | "declaration": true 7 | } 8 | } --------------------------------------------------------------------------------