Capture screenshot during export

Summary:
^

context: https://fb.workplace.com/groups/flippersupport/permalink/804152663398727/

Reviewed By: passy

Differential Revision: D19747718

fbshipit-source-id: 30a06446ba3d7d103332580ab5baad59bbc2481c
This commit is contained in:
John Knox
2020-02-10 06:03:08 -08:00
committed by Facebook Github Bot
parent 912bfed0f8
commit 6712182fd1

View File

@@ -44,6 +44,8 @@ import {performance} from 'perf_hooks';
import {processMessageQueue} from './messageQueue'; import {processMessageQueue} from './messageQueue';
import {getPluginTitle} from './pluginUtils'; import {getPluginTitle} from './pluginUtils';
import {logPlatformSuccessRate} from './metrics'; import {logPlatformSuccessRate} from './metrics';
import {capture} from './screenshot';
import {uploadFlipperMedia} from '../fb-stubs/user';
export const IMPORT_FLIPPER_TRACE_EVENT = 'import-flipper-trace'; export const IMPORT_FLIPPER_TRACE_EVENT = 'import-flipper-trace';
export const EXPORT_FLIPPER_TRACE_EVENT = 'export-flipper-trace'; export const EXPORT_FLIPPER_TRACE_EVENT = 'export-flipper-trace';
@@ -57,6 +59,7 @@ export type ExportType = {
flipperReleaseRevision: string | undefined; flipperReleaseRevision: string | undefined;
clients: Array<ClientExport>; clients: Array<ClientExport>;
device: DeviceExport | null; device: DeviceExport | null;
deviceScreenshot: string | null;
store: { store: {
pluginStates: PluginStatesExportState; pluginStates: PluginStatesExportState;
activeNotifications: Array<PluginNotification>; activeNotifications: Array<PluginNotification>;
@@ -96,6 +99,7 @@ type PluginsToProcess = {
type AddSaltToDeviceSerialOptions = { type AddSaltToDeviceSerialOptions = {
salt: string; salt: string;
device: BaseDevice; device: BaseDevice;
deviceScreenshot: string | null;
clients: Array<ClientExport>; clients: Array<ClientExport>;
pluginStates: PluginStatesExportState; pluginStates: PluginStatesExportState;
pluginNotification: Array<PluginNotification>; pluginNotification: Array<PluginNotification>;
@@ -255,6 +259,7 @@ const addSaltToDeviceSerial = async (
const { const {
salt, salt,
device, device,
deviceScreenshot,
clients, clients,
pluginStates, pluginStates,
pluginNotification, pluginNotification,
@@ -314,6 +319,7 @@ const addSaltToDeviceSerial = async (
flipperReleaseRevision: revision, flipperReleaseRevision: revision,
clients: updatedClients, clients: updatedClients,
device: newDevice.toJSON(), device: newDevice.toJSON(),
deviceScreenshot: deviceScreenshot,
store: { store: {
pluginStates: updatedPluginStates, pluginStates: updatedPluginStates,
activeNotifications: updatedPluginNotifications, activeNotifications: updatedPluginNotifications,
@@ -351,6 +357,11 @@ export const processStore = async (
if (device) { if (device) {
const {serial} = device; const {serial} = device;
statusUpdate && statusUpdate('Capturing screenshot');
const deviceScreenshot = await capture(device).catch(e => {
console.warn('Failed to capture device screenshot when exporting. ' + e);
return null;
});
const processedClients = processClients(clients, serial, statusUpdate); const processedClients = processClients(clients, serial, statusUpdate);
const processedPluginStates = processPluginStates({ const processedPluginStates = processPluginStates({
clients: processedClients, clients: processedClients,
@@ -375,10 +386,19 @@ export const processStore = async (
statusUpdate, statusUpdate,
idler, idler,
); );
statusUpdate && statusUpdate('Uploading screenshot');
const deviceScreenshotLink =
deviceScreenshot &&
(await uploadFlipperMedia(deviceScreenshot, 'Image').catch(e => {
console.warn('Failed to upload device screenshot when exporting. ' + e);
return null;
}));
// Adding salt to the device id, so that the device_id in the device list is unique. // Adding salt to the device id, so that the device_id in the device list is unique.
const exportFlipperData = await addSaltToDeviceSerial({ const exportFlipperData = await addSaltToDeviceSerial({
salt, salt,
device, device,
deviceScreenshot: deviceScreenshotLink,
clients: processedClients, clients: processedClients,
pluginStates: exportPluginState, pluginStates: exportPluginState,
pluginNotification: processedActiveNotifications, pluginNotification: processedActiveNotifications,