diff --git a/src/App.js b/src/App.js index 4c77e5e92..dba3d8999 100644 --- a/src/App.js +++ b/src/App.js @@ -19,6 +19,7 @@ import PluginManager from './chrome/PluginManager.js'; import type Logger from './fb-stubs/Logger.js'; import type BugReporter from './fb-stubs/BugReporter.js'; +import type BaseDevice from './devices/BaseDevice.js'; type Props = { logger: Logger, @@ -26,7 +27,7 @@ type Props = { leftSidebarVisible: boolean, bugDialogVisible: boolean, pluginManagerVisible: boolean, - selectedDeviceIndex: number, + selectedDevice: ?BaseDevice, error: ?string, toggleBugDialogVisible: (visible?: boolean) => void, }; @@ -51,7 +52,7 @@ export class App extends React.Component { close={() => this.props.toggleBugDialogVisible(false)} /> )} - {this.props.selectedDeviceIndex > -1 ? ( + {this.props.selectedDevice ? ( {this.props.leftSidebarVisible && } @@ -70,13 +71,13 @@ export class App extends React.Component { export default connect( ({ application: {pluginManagerVisible, bugDialogVisible, leftSidebarVisible}, - connections: {selectedDeviceIndex}, + connections: {selectedDevice}, server: {error}, }) => ({ pluginManagerVisible, bugDialogVisible, leftSidebarVisible, - selectedDeviceIndex, + selectedDevice, error, }), {toggleBugDialogVisible}, diff --git a/src/PluginContainer.js b/src/PluginContainer.js index 7858eca78..fed6d7cc3 100644 --- a/src/PluginContainer.js +++ b/src/PluginContainer.js @@ -34,12 +34,11 @@ const SidebarContainer = FlexRow.extends({ type Props = { logger: LogManager, - selectedDeviceIndex: number, + selectedDevice: BaseDevice, selectedPlugin: ?string, selectedApp: ?string, pluginStates: Object, clients: Array, - devices: Array, setPluginState: (payload: { pluginKey: string, state: Object, @@ -96,11 +95,10 @@ class PluginContainer extends Component { let activePlugin = devicePlugins.find( (p: Class>) => p.id === props.selectedPlugin, ); - const device: BaseDevice = props.devices[props.selectedDeviceIndex]; - let target = device; + let target = props.selectedDevice; let pluginKey = 'unknown'; if (activePlugin) { - pluginKey = `${device.serial}#${activePlugin.id}`; + pluginKey = `${props.selectedDevice.serial}#${activePlugin.id}`; } else { target = props.clients.find( (client: Client) => client.id === props.selectedApp, @@ -164,13 +162,12 @@ class PluginContainer extends Component { export default connect( ({ application: {rightSidebarVisible, rightSidebarAvailable}, - connections: {selectedPlugin, devices, selectedDeviceIndex, selectedApp}, + connections: {selectedPlugin, selectedDevice, selectedApp}, pluginStates, server: {clients}, }) => ({ selectedPlugin, - devices, - selectedDeviceIndex, + selectedDevice, pluginStates, selectedApp, clients, diff --git a/src/chrome/DevicesButton.js b/src/chrome/DevicesButton.js index 2985a1cb3..d341bd27e 100644 --- a/src/chrome/DevicesButton.js +++ b/src/chrome/DevicesButton.js @@ -12,10 +12,10 @@ import {selectDevice} from '../reducers/connections.js'; import type BaseDevice from '../devices/BaseDevice.js'; type Props = { - selectedDeviceIndex: number, + selectedDevice: ?BaseDevice, androidEmulators: Array, devices: Array, - selectDevice: (i: number) => void, + selectDevice: (device: BaseDevice) => void, }; class DevicesButton extends Component { @@ -31,14 +31,14 @@ class DevicesButton extends Component { const { devices, androidEmulators, - selectedDeviceIndex, + selectedDevice, selectDevice, } = this.props; let text = 'No device selected'; let icon = 'minus-circle'; - if (selectedDeviceIndex > -1) { - text = devices[selectedDeviceIndex].title; + if (selectedDevice) { + text = selectedDevice.title; icon = 'mobile'; } @@ -50,9 +50,9 @@ class DevicesButton extends Component { label: 'Running devices', enabled: false, }, - ...devices.map((device: BaseDevice, i: number) => ({ - click: () => selectDevice(i), - checked: i === selectedDeviceIndex, + ...devices.map((device: BaseDevice) => ({ + click: () => selectDevice(device), + checked: device === selectedDevice, label: `${device.deviceType === 'physical' ? '📱 ' : ''}${ device.title }`, @@ -91,10 +91,10 @@ class DevicesButton extends Component { } } export default connect( - ({connections: {devices, androidEmulators, selectedDeviceIndex}}) => ({ + ({connections: {devices, androidEmulators, selectedDevice}}) => ({ devices, androidEmulators, - selectedDeviceIndex, + selectedDevice, }), {selectDevice}, )(DevicesButton); diff --git a/src/chrome/MainSidebar.js b/src/chrome/MainSidebar.js index 33dac7b5a..b86bfad7f 100644 --- a/src/chrome/MainSidebar.js +++ b/src/chrome/MainSidebar.js @@ -134,30 +134,27 @@ class PluginSidebarListItem extends Component<{ type MainSidebarProps = {| selectedPlugin: ?string, selectedApp: ?string, - selectedDeviceIndex: number, + selectedDevice: BaseDevice, selectPlugin: (payload: { selectedPlugin: ?string, selectedApp: ?string, }) => void, - devices: Array, clients: Array, |}; class MainSidebar extends Component { render() { const { - devices, - selectedDeviceIndex, + selectedDevice, selectedPlugin, selectedApp, selectPlugin, } = this.props; let {clients} = this.props; - const device: BaseDevice = devices[selectedDeviceIndex]; let enabledPlugins = []; for (const devicePlugin of devicePlugins) { - if (device.supportsPlugin(devicePlugin)) { + if (selectedDevice.supportsPlugin(devicePlugin)) { enabledPlugins.push(devicePlugin); } } @@ -168,9 +165,9 @@ class MainSidebar extends Component { clients = clients .filter((client: Client) => { if ( - (device instanceof AndroidDevice && + (selectedDevice instanceof AndroidDevice && client.query.os.toLowerCase() !== 'android') || - (device instanceof IOSDevice && + (selectedDevice instanceof IOSDevice && client.query.os.toLowerCase() !== 'ios') ) { return false; @@ -183,7 +180,7 @@ class MainSidebar extends Component { return ( {devicePlugins - .filter(device.supportsPlugin) + .filter(selectedDevice.supportsPlugin) .map((plugin: Class>) => ( { export default connect( ({ - connections: {devices, selectedDeviceIndex, selectedPlugin, selectedApp}, + connections: {selectedDevice, selectedPlugin, selectedApp}, server: {clients}, }) => ({ - devices, - selectedDeviceIndex, + selectedDevice, selectedPlugin, selectedApp, clients, diff --git a/src/chrome/ScreenCaptureButtons.js b/src/chrome/ScreenCaptureButtons.js index 683ddc365..4f23f60c1 100644 --- a/src/chrome/ScreenCaptureButtons.js +++ b/src/chrome/ScreenCaptureButtons.js @@ -29,8 +29,7 @@ import type BaseDevice from '../devices/BaseDevice'; type PullTransfer = any; type Props = {| - devices: Array, - selectedDeviceIndex: number, + selectedDevice: ?BaseDevice, |}; type State = {| @@ -93,12 +92,11 @@ class ScreenCaptureButtons extends Component { } checkIfRecordingIsAvailable = (props: Props = this.props): void => { - const {devices, selectedDeviceIndex} = props; - const device: BaseDevice = devices[selectedDeviceIndex]; + const {selectedDevice} = props; - if (device instanceof AndroidDevice) { + if (selectedDevice instanceof AndroidDevice) { this.executeShell( - device, + selectedDevice, `[ ! -f /system/bin/screenrecord ] && echo "File does not exist"`, ).then(output => this.setState({ @@ -106,8 +104,8 @@ class ScreenCaptureButtons extends Component { }), ); } else if ( - device instanceof IOSDevice && - device.deviceType === 'emulator' + selectedDevice instanceof IOSDevice && + selectedDevice.deviceType === 'emulator' ) { this.setState({ recordingEnabled: true, @@ -120,16 +118,15 @@ class ScreenCaptureButtons extends Component { }; captureScreenshot = () => { - const {devices, selectedDeviceIndex} = this.props; - const device: BaseDevice = devices[selectedDeviceIndex]; + const {selectedDevice} = this.props; - if (device instanceof AndroidDevice) { - return device.adb - .screencap(device.serial) + if (selectedDevice instanceof AndroidDevice) { + return selectedDevice.adb + .screencap(selectedDevice.serial) .then(writePngStreamToFile) .then(openFile) .catch(console.error); - } else if (device instanceof IOSDevice) { + } else if (selectedDevice instanceof IOSDevice) { exec( `xcrun simctl io booted screenshot ${SCREENSHOT_PATH}`, (err, data) => { @@ -144,15 +141,14 @@ class ScreenCaptureButtons extends Component { }; startRecording = () => { - const {devices, selectedDeviceIndex} = this.props; - const device: BaseDevice = devices[selectedDeviceIndex]; + const {selectedDevice} = this.props; - if (device instanceof AndroidDevice) { + if (selectedDevice instanceof AndroidDevice) { this.setState({ recording: true, }); this.executeShell( - device, + selectedDevice, `screenrecord --bugreport /sdcard/${VIDEO_FILE_NAME}`, ) .then(output => { @@ -169,7 +165,7 @@ class ScreenCaptureButtons extends Component { .then( (): Promise => { return this.pullFromDevice( - device, + selectedDevice, `/sdcard/${VIDEO_FILE_NAME}`, VIDEO_PATH, ); @@ -177,7 +173,7 @@ class ScreenCaptureButtons extends Component { ) .then(openFile) .then(() => { - this.executeShell(device, `rm /sdcard/${VIDEO_FILE_NAME}`); + this.executeShell(selectedDevice, `rm /sdcard/${VIDEO_FILE_NAME}`); }) .then(() => { this.setState({ @@ -191,7 +187,7 @@ class ScreenCaptureButtons extends Component { pullingData: false, }); }); - } else if (device instanceof IOSDevice) { + } else if (selectedDevice instanceof IOSDevice) { this.setState({ recording: true, }); @@ -218,10 +214,10 @@ class ScreenCaptureButtons extends Component { }; stopRecording = () => { - const {devices, selectedDeviceIndex} = this.props; - const device: BaseDevice = devices[selectedDeviceIndex]; - if (device instanceof AndroidDevice) { - this.executeShell(device, `pgrep 'screenrecord' -L 2`); + const {selectedDevice} = this.props; + + if (selectedDevice instanceof AndroidDevice) { + this.executeShell(selectedDevice, `pgrep 'screenrecord' -L 2`); } else if (this.iOSRecorder) { this.iOSRecorder.kill(); this.setState({ @@ -248,9 +244,7 @@ class ScreenCaptureButtons extends Component { render() { const {recordingEnabled} = this.state; - const {devices, selectedDeviceIndex} = this.props; - const device: ?BaseDevice = - selectedDeviceIndex > -1 ? devices[selectedDeviceIndex] : null; + const {selectedDevice} = this.props; return ( @@ -259,7 +253,7 @@ class ScreenCaptureButtons extends Component { onClick={this.captureScreenshot} icon="camera" title="Take Screenshot" - disabled={!device} + disabled={!selectedDevice} />