Skip to content

Commit 9bc7e38

Browse files
committed
feat(preview-api): expose public api for getting device's warnings
1 parent 5ac9442 commit 9bc7e38

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

lib/definitions/preview-app-livesync.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ declare global {
1818
}
1919

2020
interface IPreviewAppPluginsService {
21+
getDeviceWarnings(device: Device): string[];
2122
comparePluginsOnDevice(data: IPreviewAppLiveSyncData, device: Device): Promise<void>;
2223
getExternalPlugins(device: Device): string[];
2324
}

lib/services/livesync/playground/devices/preview-devices-service.ts

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import { DeviceDiscoveryEventNames } from "../../../../common/constants";
55
export class PreviewDevicesService extends EventEmitter implements IPreviewDevicesService {
66
private connectedDevices: Device[] = [];
77

8+
constructor(private $previewAppPluginsService: IPreviewAppPluginsService) {
9+
super();
10+
}
11+
812
public getConnectedDevices(): Device[] {
913
return this.connectedDevices;
1014
}
@@ -27,6 +31,10 @@ export class PreviewDevicesService extends EventEmitter implements IPreviewDevic
2731
return _.filter(this.connectedDevices, { platform: platform.toLowerCase() });
2832
}
2933

34+
public getDeviceWarnings(device: Device): string[] {
35+
return this.$previewAppPluginsService.getDeviceWarnings(device);
36+
}
37+
3038
private raiseDeviceFound(device: Device) {
3139
this.emit(DeviceDiscoveryEventNames.DEVICE_FOUND, device);
3240
this.connectedDevices.push(device);

lib/services/livesync/playground/preview-app-plugins-service.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,23 @@ import { PLATFORMS_DIR_NAME, PACKAGE_JSON_FILE_NAME } from "../../../constants";
99
export class PreviewAppPluginsService implements IPreviewAppPluginsService {
1010
private previewAppVersionWarnings: IDictionary<string[]> = {};
1111

12-
constructor(private $fs: IFileSystem,
12+
constructor(private $errors: IErrors,
13+
private $fs: IFileSystem,
1314
private $logger: ILogger,
1415
private $pluginsService: IPluginsService) { }
1516

17+
public getDeviceWarnings(device: Device): string[] {
18+
if (!device) {
19+
this.$errors.failWithoutHelp("No device provided.");
20+
}
21+
22+
if (!device.previewAppVersion) {
23+
this.$errors.failWithoutHelp("No version of preview app provided.");
24+
}
25+
26+
return this.previewAppVersionWarnings[device.previewAppVersion];
27+
}
28+
1629
public async comparePluginsOnDevice(data: IPreviewAppLiveSyncData, device: Device): Promise<void> {
1730
if (!this.previewAppVersionWarnings[device.previewAppVersion]) {
1831
const devicePlugins = this.getDevicePlugins(device);

0 commit comments

Comments
 (0)