Set device features on device initialization

Summary:
1. Identify if device supports screenshots/screen recording when it is created.
2. Disable screen recording/screenshot buttons when they are not supported

Reviewed By: passy

Differential Revision: D34611133

fbshipit-source-id: 82ad2d67e4af482d9becf7995187667b5d99bc36
This commit is contained in:
Andrey Goncharov
2022-03-04 02:00:23 -08:00
committed by Facebook GitHub Bot
parent 04e7c7282b
commit 6c74f2dd18
19 changed files with 81 additions and 75 deletions

View File

@@ -11,6 +11,7 @@ import BaseDevice from '../devices/BaseDevice';
import {reportPlatformFailures} from 'flipper-common';
import {getRenderHostInstance} from '../RenderHost';
import {getFlipperLib, path} from 'flipper-plugin';
import {assertNotNull} from './assertNotNull';
export function getCaptureLocation() {
return (
@@ -27,7 +28,7 @@ export function getFileName(extension: 'png' | 'mp4'): string {
export async function capture(device: BaseDevice): Promise<string> {
if (!device.connected.get()) {
console.log('Skipping screenshot for disconnected device');
console.info('Skipping screenshot for disconnected device');
return '';
}
const pngPath = path.join(getCaptureLocation(), getFileName('png'));
@@ -36,9 +37,16 @@ export async function capture(device: BaseDevice): Promise<string> {
// again to write in a file, probably easier to change screenshot api to `device.screenshot(): path`
device
.screenshot()
.then((buffer) =>
getFlipperLib().remoteServerContext.fs.writeFileBinary(pngPath, buffer),
)
.then((buffer) => {
assertNotNull(
buffer,
`Device ${device.description.deviceType}:${device.description.os} does not support taking screenshots`,
);
return getFlipperLib().remoteServerContext.fs.writeFileBinary(
pngPath,
buffer,
);
})
.then(() => pngPath),
'captureScreenshot',
);