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;
|
} = this.props;
|
||||||
let {clients} = 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
|
clients = clients
|
||||||
.filter(
|
.filter(
|
||||||
(client: Client) =>
|
(client: Client) =>
|
||||||
@@ -237,7 +227,7 @@ class MainSidebar extends Component<MainSidebarProps> {
|
|||||||
)}
|
)}
|
||||||
{selectedDevice &&
|
{selectedDevice &&
|
||||||
devicePlugins
|
devicePlugins
|
||||||
.filter(selectedDevice.supportsPlugin)
|
.filter(plugin => plugin.supportsDevice(selectedDevice))
|
||||||
.map((plugin: Class<FlipperDevicePlugin<>>) => (
|
.map((plugin: Class<FlipperDevicePlugin<>>) => (
|
||||||
<PluginSidebarListItem
|
<PluginSidebarListItem
|
||||||
key={plugin.id}
|
key={plugin.id}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {FlipperDevicePlugin} from 'flipper';
|
import {FlipperDevicePlugin, Device} from 'flipper';
|
||||||
var adb = require('adbkit-fb');
|
var adb = require('adbkit-fb');
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -113,6 +113,10 @@ export default class CPUFrequencyTable extends FlipperDevicePlugin<CPUState> {
|
|||||||
hardwareInfo: '',
|
hardwareInfo: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static supportsDevice(device: Device) {
|
||||||
|
return device.os === 'Android' && device.deviceType === 'physical';
|
||||||
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
let device = ((this.device: any): AndroidDevice);
|
let device = ((this.device: any): AndroidDevice);
|
||||||
this.adbClient = device.adb;
|
this.adbClient = device.adb;
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import {
|
|||||||
FlipperDevicePlugin,
|
FlipperDevicePlugin,
|
||||||
SearchableTable,
|
SearchableTable,
|
||||||
styled,
|
styled,
|
||||||
|
Device,
|
||||||
} from 'flipper';
|
} from 'flipper';
|
||||||
import textContent from '../../utils/textContent.js';
|
import textContent from '../../utils/textContent.js';
|
||||||
import createPaste from '../../utils/createPaste.js';
|
import createPaste from '../../utils/createPaste.js';
|
||||||
@@ -256,6 +257,10 @@ export default class LogTable extends FlipperDevicePlugin<
|
|||||||
initTimer: ?TimeoutID;
|
initTimer: ?TimeoutID;
|
||||||
batchTimer: ?TimeoutID;
|
batchTimer: ?TimeoutID;
|
||||||
|
|
||||||
|
static supportsDevice(device: Device) {
|
||||||
|
return device.os === 'iOS' || device.os === 'Android';
|
||||||
|
}
|
||||||
|
|
||||||
onKeyboardAction = (action: string) => {
|
onKeyboardAction = (action: string) => {
|
||||||
if (action === 'clear') {
|
if (action === 'clear') {
|
||||||
this.clearLogs();
|
this.clearLogs();
|
||||||
|
|||||||
@@ -23,9 +23,6 @@ export default class AndroidDevice extends BaseDevice {
|
|||||||
) {
|
) {
|
||||||
super(serial, deviceType, title);
|
super(serial, deviceType, title);
|
||||||
this.adb = adb;
|
this.adb = adb;
|
||||||
if (deviceType == 'physical') {
|
|
||||||
this.supportedPlugins.push('DeviceCPU');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.adb.openLogcat(this.serial).then(reader => {
|
this.adb.openLogcat(this.serial).then(reader => {
|
||||||
reader.on('entry', entry => {
|
reader.on('entry', entry => {
|
||||||
@@ -63,12 +60,6 @@ export default class AndroidDevice extends BaseDevice {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
supportedPlugins = [
|
|
||||||
'DeviceLogs',
|
|
||||||
'DeviceShell',
|
|
||||||
'DeviceFiles',
|
|
||||||
'DeviceScreen',
|
|
||||||
];
|
|
||||||
icon = 'icons/android.svg';
|
icon = 'icons/android.svg';
|
||||||
os = 'Android';
|
os = 'Android';
|
||||||
adb: ADBClient;
|
adb: ADBClient;
|
||||||
|
|||||||
@@ -56,9 +56,6 @@ export default class BaseDevice {
|
|||||||
// serial number for this device
|
// serial number for this device
|
||||||
serial: string;
|
serial: string;
|
||||||
|
|
||||||
// supported device plugins for this platform
|
|
||||||
supportedPlugins: Array<string> = [];
|
|
||||||
|
|
||||||
// possible src of icon to display next to the device title
|
// possible src of icon to display next to the device title
|
||||||
icon: ?string;
|
icon: ?string;
|
||||||
|
|
||||||
@@ -69,10 +66,6 @@ export default class BaseDevice {
|
|||||||
return os.toLowerCase() === this.os.toLowerCase();
|
return os.toLowerCase() === this.os.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
supportsPlugin = (DevicePlugin: Class<FlipperDevicePlugin<>>): boolean => {
|
|
||||||
return this.supportedPlugins.includes(DevicePlugin.id);
|
|
||||||
};
|
|
||||||
|
|
||||||
toJSON() {
|
toJSON() {
|
||||||
return `<${this.constructor.name}#${this.title}>`;
|
return `<${this.constructor.name}#${this.title}>`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ type RawLogEntry = {|
|
|||||||
|};
|
|};
|
||||||
|
|
||||||
export default class IOSDevice extends BaseDevice {
|
export default class IOSDevice extends BaseDevice {
|
||||||
supportedPlugins = ['DeviceLogs'];
|
|
||||||
icon = 'icons/ios.svg';
|
icon = 'icons/ios.svg';
|
||||||
os = 'iOS';
|
os = 'iOS';
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,7 @@
|
|||||||
import BaseDevice from './BaseDevice.js';
|
import BaseDevice from './BaseDevice.js';
|
||||||
|
|
||||||
export default class WindowsDevice extends BaseDevice {
|
export default class WindowsDevice extends BaseDevice {
|
||||||
supportedPlugins = [];
|
os = 'Windows';
|
||||||
os = 'windows';
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super('', 'physical', 'desktop');
|
super('', 'physical', 'desktop');
|
||||||
|
|||||||
@@ -100,6 +100,12 @@ export class FlipperDevicePlugin<S = *, A = *, P = *> extends FlipperBasePlugin<
|
|||||||
_init() {
|
_init() {
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static supportsDevice(device: BaseDevice) {
|
||||||
|
throw new Error(
|
||||||
|
'supportsDevice is unimplemented in FlipperDevicePlugin class',
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FlipperPlugin<S = *, A = *, P = *> extends FlipperBasePlugin<
|
export class FlipperPlugin<S = *, A = *, P = *> extends FlipperBasePlugin<
|
||||||
|
|||||||
Reference in New Issue
Block a user