diff --git a/README.md b/README.md index 6e2838a..f5fc92b 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ Check and run [test.js](./test.js) for complete examples * *timeout* - Request timeout in milliseconds, default: 1000 * *playbackDelayOff* - Playback delay before it considered there's no media playing, default: 10000 * *retryPowerOn* - How many retry before power on request considered failure, default: 10 + * *keycodePowerOn* - Keycode to power on device, default: 'KEYCODE_POWER' + * *keycodePowerOff* - Keycode to power on device, default: 'KEYCODE_POWER' ## Methods @@ -40,6 +42,7 @@ Check if Android device have `tail` command. Wrapper to run ADB command **parameters** +Available parameters: * **params**: string - the adb command, eg: `dumpsys` @@ -54,6 +57,7 @@ Wrapper to run ADB command Wrapper to run shell command **parameters** +Available parameters: * **params**: string - the shell command, eg: `dumpsys` * *id*: string - process id diff --git a/index.js b/index.js index f86391f..02b4268 100644 --- a/index.js +++ b/index.js @@ -52,6 +52,10 @@ class adb extends EventEmitter { const _playbackDelayOff = config.playbackDelayOff || 10000; const _retryPowerOn = config.retryPowerOn || 5; + // Keycode + const _keycodePowerOn = config.keycodePowerOn || 'KEYCODE_POWER'; + const _keycodePowerOff = config.keycodePowerOff || 'KEYCODE_POWER'; + // Device state let _connected = this.DISCONNECTED; let _currentAppID = false; @@ -212,7 +216,7 @@ class adb extends EventEmitter { do { await this.sendKeycode(keycode || `KEYCODE_POWER`); await _sleep(100); - await _state(); + await _state(true); _emitUpdate(`debugPower${isPowerOn ? `On` : `Off`}`, { awake: _isAwake }, retry); @@ -242,7 +246,7 @@ class adb extends EventEmitter { */ this.powerOn = async keycode => { if (_isAwake) return { result: true, message: `Device already awake` }; - return await _power(keycode || `KEYCODE_POWER`); + return await _power(keycode || _keycodePowerOn || `KEYCODE_POWER`); } /** * Turn off device @@ -250,7 +254,7 @@ class adb extends EventEmitter { */ this.powerOff = async keycode => { if (!_isAwake) return { result: true, message: `Device already sleep` }; - return await _power(keycode || `KEYCODE_POWER`, false); + return await _power(keycode || _keycodePowerOff || `KEYCODE_POWER`, false); } /** * Get power information diff --git a/package.json b/package.json index f77a7e0..2765c5b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nodejs-adb-wrapper", - "version": "1.3.4", + "version": "1.3.5", "description": "Node.js module to connect to Android device using ADB", "main": "index.js", "scripts": {