From 1e5a070dbda2d6677c7a80c8621c75ff4da37c56 Mon Sep 17 00:00:00 2001 From: Lawrence Lomax Date: Fri, 28 Jan 2022 00:34:05 -0800 Subject: [PATCH] Move idb iOSBridge free-functions into class Summary: This isn't that important right now, but will help as the `IOSBridge` is expanded in the future. There's also an argument for logical ordering of functions within a container (a class!), but that's not the real motivation here. The existence of `bind` shows that this free function is effectively closing over this argument anyway. Reviewed By: passy, lblasa Differential Revision: D33818267 fbshipit-source-id: e7b83f013121cedbd31cb28746b69c1fa76a0803 --- .../src/devices/ios/IOSBridge.tsx | 77 ++++++++----------- 1 file changed, 34 insertions(+), 43 deletions(-) diff --git a/desktop/flipper-server-core/src/devices/ios/IOSBridge.tsx b/desktop/flipper-server-core/src/devices/ios/IOSBridge.tsx index 0bed6fa20..6c65b43a2 100644 --- a/desktop/flipper-server-core/src/devices/ios/IOSBridge.tsx +++ b/desktop/flipper-server-core/src/devices/ios/IOSBridge.tsx @@ -34,6 +34,39 @@ export interface IOSBridge { ) => child_process.ChildProcess; } +class IDBBridge implements IOSBridge { + constructor(private idbPath: string) {} + async navigate(serial: string, location: string): Promise { + exec(`idb open --udid ${serial} "${location}"`); + } + + recordVideo(serial: string, outputFile: string): child_process.ChildProcess { + console.log(`Starting screen record via idb to ${outputFile}.`); + return exec(`idb record-video --udid ${serial} ${outputFile}`); + } + + async screenshot(serial: string): Promise { + const imagePath = makeTempScreenshotFilePath(); + const command = `idb screenshot --udid ${serial} ${imagePath}`; + return runScreenshotCommand(command, imagePath); + } + + startLogListener( + udid: string, + deviceType: DeviceType, + ): child_process.ChildProcessWithoutNullStreams { + return child_process.spawn( + this.idbPath, + ['log', '--udid', udid, '--', ...getLogExtraArgs(deviceType)], + { + env: { + PYTHONUNBUFFERED: '1', + }, + }, + ); + } +} + async function isAvailable(idbPath: string): Promise { if (!idbPath) { return false; @@ -62,22 +95,6 @@ function getLogExtraArgs(deviceType: DeviceType) { } } -export function idbStartLogListener( - idbPath: string, - udid: string, - deviceType: DeviceType, -): child_process.ChildProcessWithoutNullStreams { - return child_process.spawn( - idbPath, - ['log', '--udid', udid, '--', ...getLogExtraArgs(deviceType)], - { - env: { - PYTHONUNBUFFERED: '1', - }, - }, - ); -} - export function xcrunStartLogListener(udid: string, deviceType: DeviceType) { if (deviceType === 'physical') { throw new Error(ERR_PHYSICAL_DEVICE_LOGS_WITHOUT_IDB); @@ -121,12 +138,6 @@ export async function xcrunScreenshot(serial: string): Promise { return runScreenshotCommand(command, imagePath); } -export async function idbScreenshot(serial: string): Promise { - const imagePath = makeTempScreenshotFilePath(); - const command = `idb screenshot --udid ${serial} ${imagePath}`; - return runScreenshotCommand(command, imagePath); -} - export async function xcrunNavigate( serial: string, location: string, @@ -134,13 +145,6 @@ export async function xcrunNavigate( exec(`xcrun simctl io ${serial} launch url "${location}"`); } -export async function idbNavigate( - serial: string, - location: string, -): Promise { - exec(`idb open --udid ${serial} "${location}"`); -} - export function xcrunRecordVideo( serial: string, outputFile: string, @@ -151,14 +155,6 @@ export function xcrunRecordVideo( ); } -export function idbRecordVideo( - serial: string, - outputFile: string, -): child_process.ChildProcess { - console.log(`Starting screen record via idb to ${outputFile}.`); - return exec(`idb record-video --udid ${serial} ${outputFile}`); -} - export async function makeIOSBridge( idbPath: string, isXcodeDetected: boolean, @@ -166,12 +162,7 @@ export async function makeIOSBridge( ): Promise { // prefer idb if (await isAvailableFn(idbPath)) { - return { - startLogListener: idbStartLogListener.bind(null, idbPath), - screenshot: idbScreenshot, - navigate: idbNavigate, - recordVideo: idbRecordVideo, - }; + return new IDBBridge(idbPath); } // no idb, if it's a simulator and xcode is available, we can use xcrun