change device plugin support check
Summary: Invert the way device plugin <-> device support works with the long term goal of supporting user defined device plugins Reviewed By: danielbuechele Differential Revision: D10240765 fbshipit-source-id: 9e886518a2fbfd263c79daa4b805c088ab38ab87
This commit is contained in:
committed by
Facebook Github Bot
parent
069f2be335
commit
7527636a38
@@ -182,16 +182,6 @@ class MainSidebar extends Component<MainSidebarProps> {
|
||||
} = this.props;
|
||||
let {clients} = this.props;
|
||||
|
||||
let enabledPlugins = [];
|
||||
for (const devicePlugin of devicePlugins) {
|
||||
if (selectedDevice && selectedDevice.supportsPlugin(devicePlugin)) {
|
||||
enabledPlugins.push(devicePlugin);
|
||||
}
|
||||
}
|
||||
enabledPlugins = enabledPlugins.sort((a, b) => {
|
||||
return (a.title || '').localeCompare(b.title);
|
||||
});
|
||||
|
||||
clients = clients
|
||||
.filter(
|
||||
(client: Client) =>
|
||||
@@ -237,7 +227,7 @@ class MainSidebar extends Component<MainSidebarProps> {
|
||||
)}
|
||||
{selectedDevice &&
|
||||
devicePlugins
|
||||
.filter(selectedDevice.supportsPlugin)
|
||||
.filter(plugin => plugin.supportsDevice(selectedDevice))
|
||||
.map((plugin: Class<FlipperDevicePlugin<>>) => (
|
||||
<PluginSidebarListItem
|
||||
key={plugin.id}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {FlipperDevicePlugin} from 'flipper';
|
||||
import {FlipperDevicePlugin, Device} from 'flipper';
|
||||
var adb = require('adbkit-fb');
|
||||
|
||||
import {
|
||||
@@ -113,6 +113,10 @@ export default class CPUFrequencyTable extends FlipperDevicePlugin<CPUState> {
|
||||
hardwareInfo: '',
|
||||
};
|
||||
|
||||
static supportsDevice(device: Device) {
|
||||
return device.os === 'Android' && device.deviceType === 'physical';
|
||||
}
|
||||
|
||||
init() {
|
||||
let device = ((this.device: any): AndroidDevice);
|
||||
this.adbClient = device.adb;
|
||||
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
FlipperDevicePlugin,
|
||||
SearchableTable,
|
||||
styled,
|
||||
Device,
|
||||
} from 'flipper';
|
||||
import textContent from '../../utils/textContent.js';
|
||||
import createPaste from '../../utils/createPaste.js';
|
||||
@@ -256,6 +257,10 @@ export default class LogTable extends FlipperDevicePlugin<
|
||||
initTimer: ?TimeoutID;
|
||||
batchTimer: ?TimeoutID;
|
||||
|
||||
static supportsDevice(device: Device) {
|
||||
return device.os === 'iOS' || device.os === 'Android';
|
||||
}
|
||||
|
||||
onKeyboardAction = (action: string) => {
|
||||
if (action === 'clear') {
|
||||
this.clearLogs();
|
||||
|
||||
@@ -23,9 +23,6 @@ export default class AndroidDevice extends BaseDevice {
|
||||
) {
|
||||
super(serial, deviceType, title);
|
||||
this.adb = adb;
|
||||
if (deviceType == 'physical') {
|
||||
this.supportedPlugins.push('DeviceCPU');
|
||||
}
|
||||
|
||||
this.adb.openLogcat(this.serial).then(reader => {
|
||||
reader.on('entry', entry => {
|
||||
@@ -63,12 +60,6 @@ export default class AndroidDevice extends BaseDevice {
|
||||
});
|
||||
}
|
||||
|
||||
supportedPlugins = [
|
||||
'DeviceLogs',
|
||||
'DeviceShell',
|
||||
'DeviceFiles',
|
||||
'DeviceScreen',
|
||||
];
|
||||
icon = 'icons/android.svg';
|
||||
os = 'Android';
|
||||
adb: ADBClient;
|
||||
|
||||
@@ -56,9 +56,6 @@ export default class BaseDevice {
|
||||
// serial number for this device
|
||||
serial: string;
|
||||
|
||||
// supported device plugins for this platform
|
||||
supportedPlugins: Array<string> = [];
|
||||
|
||||
// possible src of icon to display next to the device title
|
||||
icon: ?string;
|
||||
|
||||
@@ -69,10 +66,6 @@ export default class BaseDevice {
|
||||
return os.toLowerCase() === this.os.toLowerCase();
|
||||
}
|
||||
|
||||
supportsPlugin = (DevicePlugin: Class<FlipperDevicePlugin<>>): boolean => {
|
||||
return this.supportedPlugins.includes(DevicePlugin.id);
|
||||
};
|
||||
|
||||
toJSON() {
|
||||
return `<${this.constructor.name}#${this.title}>`;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ type RawLogEntry = {|
|
||||
|};
|
||||
|
||||
export default class IOSDevice extends BaseDevice {
|
||||
supportedPlugins = ['DeviceLogs'];
|
||||
icon = 'icons/ios.svg';
|
||||
os = 'iOS';
|
||||
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
import BaseDevice from './BaseDevice.js';
|
||||
|
||||
export default class WindowsDevice extends BaseDevice {
|
||||
supportedPlugins = [];
|
||||
os = 'windows';
|
||||
os = 'Windows';
|
||||
|
||||
constructor() {
|
||||
super('', 'physical', 'desktop');
|
||||
|
||||
@@ -100,6 +100,12 @@ export class FlipperDevicePlugin<S = *, A = *, P = *> extends FlipperBasePlugin<
|
||||
_init() {
|
||||
this.init();
|
||||
}
|
||||
|
||||
static supportsDevice(device: BaseDevice) {
|
||||
throw new Error(
|
||||
'supportsDevice is unimplemented in FlipperDevicePlugin class',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class FlipperPlugin<S = *, A = *, P = *> extends FlipperBasePlugin<
|
||||
|
||||
Reference in New Issue
Block a user