Record success rate of screenshot capture

Summary: Android and iOS each have a separate metric

Reviewed By: passy

Differential Revision: D13763758

fbshipit-source-id: f679360ec0ee008b434bfe12107ac6548d882a1f
This commit is contained in:
John Knox
2019-01-22 10:48:01 -08:00
committed by Facebook Github Bot
parent 18d9244b7e
commit eeb40b5944

View File

@@ -15,6 +15,7 @@ import adb from 'adbkit-fb';
import {exec, spawn} from 'child_process';
import {remote} from 'electron';
import path from 'path';
import {recordSuccessMetric} from '../utils/metrics';
let CAPTURE_LOCATION = remote.app.getPath('desktop');
try {
@@ -125,26 +126,31 @@ class ScreenCaptureButtons extends Component<Props, State> {
const {selectedDevice} = this.props;
if (selectedDevice instanceof AndroidDevice) {
return selectedDevice.adb
.screencap(selectedDevice.serial)
.then(writePngStreamToFile)
.then(openFile)
.catch(console.error);
return recordSuccessMetric(
selectedDevice.adb
.screencap(selectedDevice.serial)
.then(writePngStreamToFile)
.then(openFile),
'captureScreenshotAndroid',
).catch(console.error);
} else if (selectedDevice instanceof IOSDevice) {
const screenshotPath = path.join(CAPTURE_LOCATION, getFileName('png'));
return new Promise((resolve, reject) => {
exec(
`xcrun simctl io booted screenshot "${screenshotPath}"`,
async (err, data) => {
if (err) {
reject(err);
} else {
openFile(screenshotPath);
resolve();
}
},
);
});
return recordSuccessMetric(
new Promise((resolve, reject) => {
exec(
`xcrun simctl io booted screenshot "${screenshotPath}"`,
async (err, data) => {
if (err) {
reject(err);
} else {
openFile(screenshotPath);
resolve();
}
},
);
}),
'captureScreenshotIos',
);
}
};