|
| 1 | +import { Contract } from "../common/di/contract"; |
| 2 | +import type { IAppInstalledInfo } from "../common/declarations"; |
| 3 | + |
| 4 | +/** |
| 5 | + * The EventEmitter surface is merged in rather than redeclared as abstract |
| 6 | + * members: the contract must stay free of runtime imports, so it cannot extend |
| 7 | + * `EventEmitter`, and merging keeps the signatures (including the `this` |
| 8 | + * returns) tied to the ambient definition instead of a hand-copied snapshot. |
| 9 | + */ |
| 10 | +export interface DevicesService extends NodeJS.EventEmitter {} |
| 11 | + |
| 12 | +/** |
| 13 | + * Discovers connected devices and emulators and executes actions against them. |
| 14 | + */ |
| 15 | +@Contract({ name: "devicesService" }) |
| 16 | +export abstract class DevicesService { |
| 17 | + /** The platform the service has been initialized for. */ |
| 18 | + abstract platform: string; |
| 19 | + |
| 20 | + /** Whether any device matching the current initialization options is attached. */ |
| 21 | + abstract hasDevices: boolean; |
| 22 | + |
| 23 | + /** The number of devices matching the current initialization options. */ |
| 24 | + abstract deviceCount: number; |
| 25 | + |
| 26 | + abstract execute<T>( |
| 27 | + action: (device: Mobile.IDevice) => Promise<T>, |
| 28 | + canExecute?: (dev: Mobile.IDevice) => boolean, |
| 29 | + options?: { allowNoDevices?: boolean }, |
| 30 | + ): Promise<Mobile.IDeviceActionResult<T>[]>; |
| 31 | + |
| 32 | + /** |
| 33 | + * Initializes DevicesService, so after that device operations could be executed. |
| 34 | + * @param {IDevicesServicesInitializationOptions} data Defines the options which will be used for whole devicesService. |
| 35 | + * @return {Promise<void>} |
| 36 | + */ |
| 37 | + abstract initialize( |
| 38 | + data?: Mobile.IDevicesServicesInitializationOptions, |
| 39 | + ): Promise<void>; |
| 40 | + |
| 41 | + /** |
| 42 | + * Add an IDeviceDiscovery instance which will from now on report devices. The instance should implement IDeviceDiscovery and raise "deviceFound" and "deviceLost" events. |
| 43 | + * @param {IDeviceDiscovery} deviceDiscovery Instance, implementing IDeviceDiscovery and raising raise "deviceFound" and "deviceLost" events. |
| 44 | + * @return {void} |
| 45 | + */ |
| 46 | + abstract addDeviceDiscovery(deviceDiscovery: Mobile.IDeviceDiscovery): void; |
| 47 | + |
| 48 | + abstract getDevices(): Mobile.IDeviceInfo[]; |
| 49 | + |
| 50 | + /** |
| 51 | + * Gets device instance by specified identifier or number. |
| 52 | + * @param {string} deviceOption The specified device identifier or number. |
| 53 | + * @returns {Promise<Mobile.IDevice>} Instance of IDevice. |
| 54 | + */ |
| 55 | + abstract getDevice(deviceOption: string): Promise<Mobile.IDevice>; |
| 56 | + |
| 57 | + abstract getDevicesForPlatform(platform: string): Mobile.IDevice[]; |
| 58 | + |
| 59 | + abstract getDeviceInstances(): Mobile.IDevice[]; |
| 60 | + |
| 61 | + abstract getDeviceByDeviceOption(): Mobile.IDevice; |
| 62 | + |
| 63 | + abstract isAndroidDevice(device: Mobile.IDevice): boolean; |
| 64 | + |
| 65 | + abstract isiOSDevice(device: Mobile.IDevice): boolean; |
| 66 | + |
| 67 | + abstract isiOSSimulator(device: Mobile.IDevice): boolean; |
| 68 | + |
| 69 | + abstract isOnlyiOSSimultorRunning(): boolean; |
| 70 | + |
| 71 | + abstract isAppInstalledOnDevices( |
| 72 | + deviceIdentifiers: string[], |
| 73 | + appIdentifier: string, |
| 74 | + framework: string, |
| 75 | + projectDir: string, |
| 76 | + ): Promise<IAppInstalledInfo>[]; |
| 77 | + |
| 78 | + abstract setLogLevel(logLevel: string, deviceIdentifier?: string): void; |
| 79 | + |
| 80 | + abstract deployOnDevices( |
| 81 | + deviceIdentifiers: string[], |
| 82 | + packageFile: string, |
| 83 | + packageName: string, |
| 84 | + framework: string, |
| 85 | + projectDir: string, |
| 86 | + ): Promise<void>[]; |
| 87 | + |
| 88 | + abstract getDeviceByIdentifier(identifier: string): Mobile.IDevice; |
| 89 | + |
| 90 | + abstract mapAbstractToTcpPort( |
| 91 | + deviceIdentifier: string, |
| 92 | + appIdentifier: string, |
| 93 | + framework: string, |
| 94 | + ): Promise<string>; |
| 95 | + |
| 96 | + abstract getDebuggableApps( |
| 97 | + deviceIdentifiers: string[], |
| 98 | + ): Promise<Mobile.IDeviceApplicationInformation[]>[]; |
| 99 | + |
| 100 | + abstract getDebuggableViews( |
| 101 | + deviceIdentifier: string, |
| 102 | + appIdentifier: string, |
| 103 | + ): Promise<Mobile.IDebugWebViewInfo[]>; |
| 104 | + |
| 105 | + /** |
| 106 | + * Returns all applications installed on the specified device. |
| 107 | + * @param {string} deviceIdentifer The identifier of the device for which to get installed applications. |
| 108 | + * @returns {Promise<string[]>} Array of all application identifiers of the apps installed on device. |
| 109 | + */ |
| 110 | + abstract getInstalledApplications( |
| 111 | + deviceIdentifier: string, |
| 112 | + ): Promise<string[]>; |
| 113 | + |
| 114 | + /** |
| 115 | + * Returns all available iOS and/or Android emulators. |
| 116 | + * @param options The options that can be passed to filter the result. |
| 117 | + * @returns {Promise<Mobile.IListEmulatorsOutput>} Dictionary with the following format: { ios: { devices: Mobile.IDeviceInfo[], errors: string[] }, android: { devices: Mobile.IDeviceInfo[], errors: string[]}}. |
| 118 | + */ |
| 119 | + abstract getEmulatorImages( |
| 120 | + options?: Mobile.IListEmulatorsOptions, |
| 121 | + ): Promise<Mobile.IListEmulatorsOutput>; |
| 122 | + |
| 123 | + /** |
| 124 | + * Starts an emulator by provided options. |
| 125 | + * @param options |
| 126 | + * @returns {Promise<string[]>} - Returns array of errors. |
| 127 | + */ |
| 128 | + abstract startEmulator( |
| 129 | + options?: Mobile.IStartEmulatorOptions, |
| 130 | + ): Promise<string[]>; |
| 131 | + |
| 132 | + /** |
| 133 | + * Starts polling for attached devices, raising the deviceFound/deviceLost |
| 134 | + * events as the set of attached devices changes. Calling it while a poll |
| 135 | + * is already running is a no-op. |
| 136 | + * @param {Mobile.IDeviceLookingOptions} deviceInitOpts Options describing which devices to look for and how often to poll. |
| 137 | + * @returns {void} |
| 138 | + */ |
| 139 | + abstract startDeviceDetectionInterval( |
| 140 | + deviceInitOpts?: Mobile.IDeviceLookingOptions, |
| 141 | + ): void; |
| 142 | + |
| 143 | + /** |
| 144 | + * Stops the poll started by startDeviceDetectionInterval. |
| 145 | + * @returns {void} |
| 146 | + */ |
| 147 | + abstract stopDeviceDetectionInterval(): void; |
| 148 | + |
| 149 | + /** |
| 150 | + * Starts polling for available emulator images, raising the |
| 151 | + * emulatorImageFound/emulatorImageLost events as the set changes. |
| 152 | + * @param {Mobile.IHasDetectionInterval} opts Options describing how often to poll. |
| 153 | + * @returns {void} |
| 154 | + */ |
| 155 | + abstract startEmulatorDetectionInterval( |
| 156 | + opts?: Mobile.IHasDetectionInterval, |
| 157 | + ): void; |
| 158 | + |
| 159 | + /** |
| 160 | + * Stops the poll started by startEmulatorDetectionInterval. |
| 161 | + * @returns {void} |
| 162 | + */ |
| 163 | + abstract stopEmulatorDetectionInterval(): void; |
| 164 | + |
| 165 | + /** |
| 166 | + * Returns a single device based on the specified options. If more than one devices are matching, |
| 167 | + * prompts the user for a manual choice or returns the first one for non interactive terminals. |
| 168 | + */ |
| 169 | + abstract pickSingleDevice( |
| 170 | + options: Mobile.IPickSingleDeviceOptions, |
| 171 | + ): Promise<Mobile.IDevice>; |
| 172 | + |
| 173 | + abstract getPlatformsFromDeviceDescriptors( |
| 174 | + deviceDescriptors: ILiveSyncDeviceDescriptor[], |
| 175 | + ): string[]; |
| 176 | +} |
0 commit comments