Files
flipper/desktop/types/adbkit.d.ts
Michel Weststrate 3882357579 Factor out realDevice [7/n]
Summary: `device.realDevice` was the escape hatch used in Sandy plugins to give access to device specific features like taking screenshots, clearing logs or accessing `adb`. Since in decapitated Flipper that won't be possible anymore (since plugins run in the client but device implementations on the server), all escape hatches have been bridged in this stack, and we can get of the `realDevice` interaction, by explicitly exposing those cases, which makes it type safe as well.

Reviewed By: passy

Differential Revision: D31079509

fbshipit-source-id: c9ec2e044d0dec0ccb1de287cf424907b198f818
2021-09-22 09:03:33 -07:00

80 lines
2.3 KiB
TypeScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
declare module 'adbkit' {
export interface Device {
id: string;
type: 'emulator' | 'device' | 'offline';
}
interface Util {
readAll: (stream: NodeJS.ReadStream) => Promise<Buffer>;
}
// https://github.com/openstf/adbkit#pulltransfer
export interface PullTransfer extends NodeJS.WriteStream {
cancel: () => this;
on(
event: 'progress',
listener: (stats: {bytesTransferred: number}) => void,
): this;
on(event: 'error', listener: (err: Error) => void): this;
on(event: 'end', listener: () => void): this;
on(event: 'resize', listener: () => void): this;
}
interface DeviceTracker extends NodeJS.EventEmitter {
on(event: 'add', listener: (device: Device) => void): this;
on(event: 'remove', listener: (device: Device) => void): this;
on(event: 'change', listener: (device: Device) => void): this;
on(
event: 'changeSet',
listener: (changes: {
added: Device[];
removed: Device[];
changed: Device[];
}) => void,
): this;
on(event: 'error', listener: (err: Error) => void): this;
on(event: 'end', listener: () => void): this;
}
const util: Util;
const adbkit: any;
export interface Client {
listDevices: () => Promise<Device[]>;
reverse: (
serial: string,
remote: string,
local: string,
) => Promise<boolean>;
shell: (
serial: string,
command: string | string[],
) => Promise<NodeJS.ReadStream>;
screencap: (serial: string) => Promise<NodeJS.WriteStream>;
pull: (serial: string, path: string) => Promise<PullTransfer>;
openLogcat: (
serial: string,
options?: {
clear?: boolean;
},
callback?: any,
) => Promise<import('adbkit-logcat').Reader>;
getProperties: (serial: string) => Promise<{[key: string]: string}>;
trackDevices: () => Promise<DeviceTracker>;
kill: () => Promise<boolean>;
forward: (
serial: string,
local: string,
remote: string,
) => Promise<boolean>; // TODO: verify correctness of signature
}
export function createClient(config: {port: number; host: string}): Client;
}