Migrate androidDevice dispatcher from js to tsx
Summary: As per the title Reviewed By: jknoxville Differential Revision: D16689714 fbshipit-source-id: 1ff415a89b4ac91ffd4a23e8b50ec9fedfeea40e
This commit is contained in:
committed by
Facebook Github Bot
parent
0c0d595cbb
commit
03b5b133b8
@@ -5,21 +5,21 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import AndroidDevice from '../devices/AndroidDevice.tsx';
|
import AndroidDevice from '../devices/AndroidDevice';
|
||||||
import child_process from 'child_process';
|
import child_process from 'child_process';
|
||||||
import type {Store} from '../reducers/index.tsx';
|
import {Store} from '../reducers/index';
|
||||||
import type BaseDevice from '../devices/BaseDevice.tsx';
|
import BaseDevice from '../devices/BaseDevice';
|
||||||
import type {Logger} from '../fb-interfaces/Logger.js';
|
import {Logger} from '../fb-interfaces/Logger.js';
|
||||||
import {registerDeviceCallbackOnPlugins} from '../utils/onRegisterDevice.js';
|
import {registerDeviceCallbackOnPlugins} from '../utils/onRegisterDevice.js';
|
||||||
import {getAdbClient} from '../utils/adbClient';
|
import {getAdbClient} from '../utils/adbClient';
|
||||||
import {default as which} from 'which';
|
import {default as which} from 'which';
|
||||||
import {promisify} from 'util';
|
import {promisify} from 'util';
|
||||||
import type {ServerPorts} from '../reducers/application.tsx';
|
import {ServerPorts} from '../reducers/application';
|
||||||
|
|
||||||
function createDevice(
|
function createDevice(
|
||||||
adbClient: any,
|
adbClient: any,
|
||||||
device: any,
|
device: any,
|
||||||
ports: ?ServerPorts,
|
ports?: ServerPorts,
|
||||||
): Promise<AndroidDevice> {
|
): Promise<AndroidDevice> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const type =
|
const type =
|
||||||
@@ -49,7 +49,9 @@ export async function getActiveAndroidDevices(): Promise<Array<BaseDevice>> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRunningEmulatorName(id: string): Promise<?string> {
|
function getRunningEmulatorName(
|
||||||
|
id: string,
|
||||||
|
): Promise<string | null | undefined> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const port = id.replace('emulator-', '');
|
const port = id.replace('emulator-', '');
|
||||||
// The GNU version of netcat doesn't terminate after 1s when
|
// The GNU version of netcat doesn't terminate after 1s when
|
||||||
@@ -59,7 +61,7 @@ function getRunningEmulatorName(id: string): Promise<?string> {
|
|||||||
child_process.exec(
|
child_process.exec(
|
||||||
`echo "avd name" | nc -w 1 localhost ${port}`,
|
`echo "avd name" | nc -w 1 localhost ${port}`,
|
||||||
{timeout: 1000, encoding: 'utf-8'},
|
{timeout: 1000, encoding: 'utf-8'},
|
||||||
(error: ?Error, data) => {
|
(error: Error | null | undefined, data) => {
|
||||||
if (data != null && typeof data === 'string') {
|
if (data != null && typeof data === 'string') {
|
||||||
const match = data.trim().match(/(.*)\r\nOK$/);
|
const match = data.trim().match(/(.*)\r\nOK$/);
|
||||||
resolve(match != null && match.length > 0 ? match[1] : null);
|
resolve(match != null && match.length > 0 ? match[1] : null);
|
||||||
@@ -79,7 +81,7 @@ export default (store: Store, logger: Logger) => {
|
|||||||
.then(emulatorPath => {
|
.then(emulatorPath => {
|
||||||
child_process.exec(
|
child_process.exec(
|
||||||
`${emulatorPath} -list-avds`,
|
`${emulatorPath} -list-avds`,
|
||||||
(error: ?Error, data: ?string) => {
|
(error: Error | null, data: string | null) => {
|
||||||
if (error != null || data == null) {
|
if (error != null || data == null) {
|
||||||
console.error(error || 'Failed to list AVDs');
|
console.error(error || 'Failed to list AVDs');
|
||||||
return;
|
return;
|
||||||
@@ -102,7 +104,9 @@ export default (store: Store, logger: Logger) => {
|
|||||||
if (err.message === 'Connection closed') {
|
if (err.message === 'Connection closed') {
|
||||||
// adb server has shutdown, remove all android devices
|
// adb server has shutdown, remove all android devices
|
||||||
const {connections} = store.getState();
|
const {connections} = store.getState();
|
||||||
const deviceIDsToRemove: Array<string> = connections.devices
|
const deviceIDsToRemove: Array<
|
||||||
|
string
|
||||||
|
> = connections.devices
|
||||||
.filter(
|
.filter(
|
||||||
(device: BaseDevice) => device instanceof AndroidDevice,
|
(device: BaseDevice) => device instanceof AndroidDevice,
|
||||||
)
|
)
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import androidDevice from './androidDevice';
|
import androidDevice from './androidDevice.tsx';
|
||||||
import iOSDevice from './iOSDevice';
|
import iOSDevice from './iOSDevice';
|
||||||
import desktopDevice from './desktopDevice';
|
import desktopDevice from './desktopDevice';
|
||||||
import application from './application';
|
import application from './application';
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
import {getActiveAndroidDevices} from '../dispatcher/androidDevice';
|
import {getActiveAndroidDevices} from '../dispatcher/androidDevice.tsx';
|
||||||
import {getActiveDevicesAndSimulators} from '../dispatcher/iOSDevice';
|
import {getActiveDevicesAndSimulators} from '../dispatcher/iOSDevice';
|
||||||
import type BaseDevice from '../devices/BaseDevice.tsx';
|
import type BaseDevice from '../devices/BaseDevice.tsx';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user