From 3dcfe9f3aef2b02ec8f520c0d331a962c1a1e197 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Tue, 11 Feb 2020 07:27:00 -0800 Subject: [PATCH] Move Metro control buttons to titlebar Summary: The Metro control buttons are now in the titlebar. This has a few benefits: - the buttons are accessible if you are inspecting other metro plugins - the buttons are even usuable if you selected an app on the actual device. This should help with reducing the cognitive dissonance of having apps both as 'android' app and metro device - killed the Metro plugin again :) Reviewed By: nikoant Differential Revision: D19789455 fbshipit-source-id: 476fd0af1d3fc7b51a33f1af6d3fc3578aeeefae --- .../index.tsx => chrome/MetroButton.tsx} | 105 ++++++++---------- src/chrome/TitleBar.tsx | 14 ++- src/plugins/metro/package.json | 18 --- static/icons.json | 8 +- 4 files changed, 65 insertions(+), 80 deletions(-) rename src/{plugins/metro/index.tsx => chrome/MetroButton.tsx} (63%) delete mode 100644 src/plugins/metro/package.json diff --git a/src/plugins/metro/index.tsx b/src/chrome/MetroButton.tsx similarity index 63% rename from src/plugins/metro/index.tsx rename to src/chrome/MetroButton.tsx index 47e79f9dc..482ca18a3 100644 --- a/src/plugins/metro/index.tsx +++ b/src/chrome/MetroButton.tsx @@ -7,16 +7,9 @@ * @format */ -import React from 'react'; -import { - FlipperDevicePlugin, - Device, - View, - Button, - Toolbar, - ButtonGroup, - MetroDevice, -} from 'flipper'; +import React, {useCallback} from 'react'; +import {Button, ButtonGroup, MetroDevice, connect} from 'flipper'; +import {State} from '../reducers'; type LogEntry = {}; @@ -24,8 +17,6 @@ export type PersistedState = { logs: LogEntry[]; }; -type State = {}; - /* Flow types for events @@ -120,52 +111,50 @@ export type ReportableEvent = }; */ -export default class MetroPlugin extends FlipperDevicePlugin< - State, - any, - PersistedState -> { - static supportsDevice(device: Device) { - return device.os === 'Metro'; - } +type Props = { + device: MetroDevice; +}; - get ws(): WebSocket { - return (this.device as MetroDevice).ws; - } +function MetroButton({device}: Props) { + const sendCommand = useCallback( + (command: string) => { + if (device.ws) { + device.ws.send( + JSON.stringify({ + version: 2, + type: 'command', + command, + }), + ); + } + }, + [device], + ); - sendCommand(command: string) { - if (this.ws) { - this.ws.send( - JSON.stringify({ - version: 2, - type: 'command', - command, - }), - ); - } - } - - render() { - return ( - - - - Work-in-progress - - - - - - ); - } + return ( + +