Add custom timeout to Device.installApp

Reviewed By: lblasa

Differential Revision: D39728545

fbshipit-source-id: be77a2e7ddac4071c9cafc88e67b793ee8c7631c
This commit is contained in:
Andrey Goncharov
2022-09-23 10:20:53 -07:00
committed by Facebook GitHub Bot
parent dd7ba2d6fc
commit 228de6c542
5 changed files with 89 additions and 11 deletions

View File

@@ -11,6 +11,8 @@ import EventEmitter from 'eventemitter3';
import {
ExecWebSocketMessage,
FlipperServer,
FlipperServerCommands,
FlipperServerExecOptions,
ServerWebSocketMessage,
} from 'flipper-common';
import ReconnectingWebSocket from 'reconnecting-websocket';
@@ -127,10 +129,30 @@ export function createFlipperServerWithSocket(
}
});
const commandOrOptionsIsOptions = (
commandOrOptions: FlipperServerExecOptions | string,
): commandOrOptions is FlipperServerExecOptions =>
typeof commandOrOptions === 'object';
const flipperServer: FlipperServer = {
async connect() {},
close() {},
exec(command, ...args): any {
exec(commandOrOptions, ...argsAmbiguous): any {
let timeout: number;
let command: string;
let args: Parameters<
FlipperServerCommands[keyof FlipperServerCommands]
>;
if (commandOrOptionsIsOptions(commandOrOptions)) {
timeout = commandOrOptions.timeout;
command = argsAmbiguous[0] as string;
args = argsAmbiguous.slice(1) as typeof args;
} else {
timeout = EXEC_TIMEOUT;
command = commandOrOptions;
args = argsAmbiguous as typeof args;
}
if (connected) {
const id = ++requestId;
return new Promise<any>((resolve, reject) => {
@@ -144,7 +166,7 @@ export function createFlipperServerWithSocket(
reject(
new Error(`flipper-server: timeout for command '${command}'`),
);
}, EXEC_TIMEOUT),
}, timeout),
});
const execMessage = {

View File

@@ -239,12 +239,19 @@ export default class BaseDevice implements Device {
return this.flipperServer.exec('device-navigate', this.serial, location);
}
async installApp(appBundlePath: string): Promise<void> {
return this.flipperServer.exec(
'device-install-app',
this.serial,
appBundlePath,
);
async installApp(appBundlePath: string, timeout?: number): Promise<void> {
return timeout
? this.flipperServer.exec(
{timeout},
'device-install-app',
this.serial,
appBundlePath,
)
: this.flipperServer.exec(
'device-install-app',
this.serial,
appBundlePath,
);
}
async screenshot(): Promise<Uint8Array | undefined> {