From e2abe1c89a5c68b7ef69ee4b6002e493a9d7d1e7 Mon Sep 17 00:00:00 2001 From: Lawrence Lomax Date: Fri, 28 Jan 2022 00:34:05 -0800 Subject: [PATCH] Separate concerns of reading screenshot into buffer & execing screenshot function Summary: This allows us to change the way that the command is itself exec'd (for instance to change the idb exec'ing in D33818298) Reviewed By: passy Differential Revision: D33818822 fbshipit-source-id: c90b7e58c7476f5db08da0e74e9791230ff97f6f --- .../src/devices/ios/IOSBridge.tsx | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/desktop/flipper-server-core/src/devices/ios/IOSBridge.tsx b/desktop/flipper-server-core/src/devices/ios/IOSBridge.tsx index 7545f4554..85d809636 100644 --- a/desktop/flipper-server-core/src/devices/ios/IOSBridge.tsx +++ b/desktop/flipper-server-core/src/devices/ios/IOSBridge.tsx @@ -47,8 +47,8 @@ class IDBBridge implements IOSBridge { async screenshot(serial: string): Promise { const imagePath = makeTempScreenshotFilePath(); - const command = `idb screenshot --udid ${serial} ${imagePath}`; - return runScreenshotCommand(command, imagePath); + await exec(`idb screenshot --udid ${serial} ${imagePath}`); + return readScreenshotIntoBuffer(imagePath); } startLogListener( @@ -95,8 +95,8 @@ class SimctlBridge implements IOSBridge { async screenshot(serial: string): Promise { const imagePath = makeTempScreenshotFilePath(); - const command = `xcrun simctl io ${serial} screenshot ${imagePath}`; - return runScreenshotCommand(command, imagePath); + await exec(`xcrun simctl io ${serial} screenshot ${imagePath}`); + return readScreenshotIntoBuffer(imagePath); } async navigate(serial: string, location: string): Promise { @@ -144,11 +144,7 @@ function makeTempScreenshotFilePath() { return path.join(getFlipperServerConfig().paths.tempPath, imageName); } -async function runScreenshotCommand( - command: string, - imagePath: string, -): Promise { - await exec(command); +async function readScreenshotIntoBuffer(imagePath: string): Promise { const buffer = await fs.readFile(imagePath); await fs.unlink(imagePath); return buffer;