UNPKG

3.23 kBTypeScriptView Raw
1import type { CommandBase, CommandLifeCycle } from "./command";
2import { type Vector2 } from "./types";
3export declare class DeviceEmitter<K extends string, T extends object = never> {
4 private emitter;
5 on(eventName: K, listener: (command: CommandBase) => void): void;
6 off(eventName: K, listener: (command: CommandBase) => void): void;
7 emit(eventName: K, arg?: T): void;
8}
9/**
10 * The Device instance is binding with specific serial number of adb device.
11 *
12 */
13export declare class Device {
14 /**
15 * The folder where adb.exe is located
16 */
17 private readonly adbPath;
18 /**
19 * Adb creates a string to uniquely identify the device by its port number. Here's an example serial number: emulator-5554
20 */
21 readonly serialNumber: string;
22 /**
23 * Check whether device is connected before issue a command
24 */
25 autoCheckConnected: boolean;
26 deviceResolution: Vector2;
27 commandResolution: Vector2;
28 private get resolutionRatio();
29 private _connected;
30 /**
31 * Determines whether the device is connected
32 */
33 get connected(): boolean;
34 private _running;
35 /**
36 * Determines whether the command is running
37 */
38 get running(): boolean;
39 private readonly _eventEmmiter;
40 constructor(adbPath: string, serialNumber: string, connectStatus: boolean);
41 checkConnected(retry?: number): Promise<boolean>;
42 /**
43 * Issue command by text
44 * @param commandText
45 */
46 issueShellCommandText(commandText: string): Promise<string>;
47 /**
48 * Issue specified command
49 * @param command
50 */
51 issueShellCommand(command: CommandBase): Promise<boolean>;
52 /**
53 * Issue specified commands
54 * @param commands
55 */
56 issueShellCommands(commands: CommandBase[]): Promise<boolean>;
57 /**
58 * Add listener to command life cycle event
59 * @param eventName
60 * @param listener
61 */
62 on(eventName: CommandLifeCycle, listener: (command: CommandBase) => void): void;
63 /**
64 * Remove Listener to command life cycle event
65 * @param eventName
66 * @param listener
67 */
68 off(eventName: CommandLifeCycle, listener: (command: CommandBase) => void): void;
69 /**
70 * Get resolution of this device
71 * @returns
72 */
73 getResolution(): Promise<Vector2>;
74 getAllPackages(): Promise<string[]>;
75 getSystemPackages(): Promise<string[]>;
76 getThirdPartyPackages(): Promise<string[]>;
77 private parsePackages;
78 existPackage(packageName: string): Promise<boolean>;
79 /**
80 * Check if activity is running top
81 * @param activityName
82 * @returns
83 */
84 isCurrentActivity(packageName: string, activityName?: string): Promise<boolean>;
85 /**
86 * Start an app if not at the current focus
87 * @param packageName
88 * @param activityName
89 */
90 startApp(packageName: string, activityName: string, timeout?: number): Promise<boolean>;
91 /**
92 * Close an app
93 * @param packageName
94 */
95 closeApp(packageName: string, timeout?: number): Promise<boolean>;
96 /**
97 * Take a screencap and pull it out
98 * @param options
99 */
100 getScreencap(options?: {
101 fileName?: string;
102 pullPath?: string;
103 }): Promise<void>;
104}