Factor out realDevice [7/n]
Summary: `device.realDevice` was the escape hatch used in Sandy plugins to give access to device specific features like taking screenshots, clearing logs or accessing `adb`. Since in decapitated Flipper that won't be possible anymore (since plugins run in the client but device implementations on the server), all escape hatches have been bridged in this stack, and we can get of the `realDevice` interaction, by explicitly exposing those cases, which makes it type safe as well. Reviewed By: passy Differential Revision: D31079509 fbshipit-source-id: c9ec2e044d0dec0ccb1de287cf424907b198f818
This commit is contained in:
committed by
Facebook GitHub Bot
parent
11a27f9e1a
commit
3882357579
@@ -59,7 +59,7 @@ export function startAndroidCrashWatcher(
|
||||
let androidLog: string = '';
|
||||
let androidLogUnderProcess = false;
|
||||
let timer: null | NodeJS.Timeout = null;
|
||||
client.device.onLogEntry((entry: DeviceLogEntry) => {
|
||||
client.onDeviceLogEntry((entry: DeviceLogEntry) => {
|
||||
if (shouldParseAndroidLog(entry, referenceDate)) {
|
||||
if (androidLogUnderProcess) {
|
||||
androidLog += '\n' + entry.message;
|
||||
|
||||
@@ -156,7 +156,7 @@ export function devicePlugin(client: DevicePluginClient) {
|
||||
if (isPaused.get() && client.device.isConnected) {
|
||||
// start listening to the logs
|
||||
isPaused.set(false);
|
||||
logDisposer = client.device.onLogEntry((entry: DeviceLogEntry) => {
|
||||
logDisposer = client.onDeviceLogEntry((entry: DeviceLogEntry) => {
|
||||
const lastIndex = rows.size - 1;
|
||||
const previousRow = rows.get(lastIndex);
|
||||
if (
|
||||
@@ -182,9 +182,8 @@ export function devicePlugin(client: DevicePluginClient) {
|
||||
}
|
||||
}
|
||||
|
||||
function clearLogs() {
|
||||
// Non public Android specific api
|
||||
(client.device.realDevice as any)?.clearLogs?.();
|
||||
async function clearLogs() {
|
||||
await client.device.clearLogs();
|
||||
rows.clear();
|
||||
tableManagerRef.current?.clearSelection();
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ export function plugin(client: PluginClient<Events, Methods>) {
|
||||
draft.unshift(navigationEvent);
|
||||
});
|
||||
|
||||
const screenshot: Buffer = await client.device.realDevice.screenshot();
|
||||
const screenshot: Buffer = await client.device.screenshot();
|
||||
const blobURL = URL.createObjectURL(bufferToBlob(screenshot));
|
||||
// this process is async, make sure we update the correct one..
|
||||
const navigationEventIndex = navigationEvents
|
||||
@@ -86,7 +86,7 @@ export function plugin(client: PluginClient<Events, Methods>) {
|
||||
}
|
||||
});
|
||||
|
||||
getAppMatchPatterns(client.appId, client.device.realDevice)
|
||||
getAppMatchPatterns(client.appId, client.device)
|
||||
.then((patterns) => {
|
||||
appMatchPatterns.set(patterns);
|
||||
})
|
||||
@@ -111,7 +111,7 @@ export function plugin(client: PluginClient<Events, Methods>) {
|
||||
url: filterOptionalParameters(filteredQuery),
|
||||
});
|
||||
} else {
|
||||
client.device.realDevice.navigateToLocation(
|
||||
client.device.navigateToLocation(
|
||||
filterOptionalParameters(filteredQuery),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import {BaseDevice, getAppPath} from 'flipper';
|
||||
import {getAppPath} from 'flipper';
|
||||
import {AppMatchPattern} from '../types';
|
||||
import {Device} from 'flipper-plugin';
|
||||
|
||||
let patternsPath: string | undefined;
|
||||
|
||||
@@ -28,7 +29,7 @@ const extractAppNameFromSelectedApp = (selectedApp: string | null) => {
|
||||
|
||||
export const getAppMatchPatterns = (
|
||||
selectedApp: string | null,
|
||||
device: BaseDevice,
|
||||
device: Device,
|
||||
) => {
|
||||
return new Promise<Array<AppMatchPattern>>((resolve, reject) => {
|
||||
const appName = extractAppNameFromSelectedApp(selectedApp);
|
||||
|
||||
@@ -29,10 +29,6 @@ const DEV_TOOLS_NODE_ID = 'reactdevtools-out-of-react-node';
|
||||
const CONNECTED = 'DevTools connected';
|
||||
const DEV_TOOLS_PORT = 8097; // hardcoded in RN
|
||||
|
||||
interface MetroDevice {
|
||||
sendMetroCommand(command: string, params?: any): void;
|
||||
}
|
||||
|
||||
function findGlobalDevTools(): Promise<string | undefined> {
|
||||
return new Promise((resolve) => {
|
||||
child_process.exec('npm root -g', (error, basePath) => {
|
||||
@@ -64,10 +60,7 @@ enum ConnectionStatus {
|
||||
}
|
||||
|
||||
export function devicePlugin(client: DevicePluginClient) {
|
||||
const metroDevice: MetroDevice = client.device.realDevice;
|
||||
if (!metroDevice.sendMetroCommand) {
|
||||
throw new Error('Invalid metroDevice');
|
||||
}
|
||||
const metroDevice = client.device;
|
||||
|
||||
const statusMessage = createState('initializing');
|
||||
const connectionStatus = createState<ConnectionStatus>(
|
||||
|
||||
Reference in New Issue
Block a user