More granular logging

Summary: The `'PLUGIN_DEVICE_BAIL'` event encompasses too many individual steps. This is now broken down into the various parts like closing the emulator launch dialogue, selecting multiple apps/devices or quitting the wait period.

Differential Revision: D31861520

fbshipit-source-id: ff724b461f3af8021950f4aebe87eba0b20dea79
This commit is contained in:
Pascal Hartig
2021-10-25 03:17:06 -07:00
committed by Facebook GitHub Bot
parent 0b44931e2b
commit 695ba14289
2 changed files with 39 additions and 18 deletions

View File

@@ -16,16 +16,21 @@ export type OpenPluginParams = {
payload: string | undefined; payload: string | undefined;
}; };
export type DeeplinkInteractionState =
| 'INIT'
| 'ERROR'
| 'PLUGIN_LIGHTHOUSE_BAIL'
| 'PLUGIN_STATUS_BAIL'
| 'PLUGIN_DEVICE_BAIL'
| 'PLUGIN_CLIENT_BAIL'
| 'PLUGIN_DEVICE_SELECTION_BAIL'
| 'PLUGIN_CLIENT_SELECTION_BAIL'
| 'PLUGIN_DEVICE_UNSUPPORTED'
| 'PLUGIN_CLIENT_UNSUPPORTED'
| 'PLUGIN_OPEN_SUCCESS';
export type DeeplinkInteraction = { export type DeeplinkInteraction = {
state: state: DeeplinkInteractionState;
| 'INIT'
| 'ERROR'
| 'PLUGIN_LIGHTHOUSE_BAIL'
| 'PLUGIN_STATUS_BAIL'
| 'PLUGIN_DEVICE_BAIL'
| 'PLUGIN_DEVICE_UNSUPPORTED'
| 'PLUGIN_CLIENT_UNSUPPORTED'
| 'PLUGIN_OPEN_SUCCESS';
errorMessage?: string; errorMessage?: string;
plugin?: OpenPluginParams; plugin?: OpenPluginParams;
extra?: object; extra?: object;

View File

@@ -34,7 +34,11 @@ import {RocketOutlined} from '@ant-design/icons';
import {showEmulatorLauncher} from '../sandy-chrome/appinspect/LaunchEmulator'; import {showEmulatorLauncher} from '../sandy-chrome/appinspect/LaunchEmulator';
import {getAllClients} from '../reducers/connections'; import {getAllClients} from '../reducers/connections';
import {showLoginDialog} from '../chrome/fb-stubs/SignInSheet'; import {showLoginDialog} from '../chrome/fb-stubs/SignInSheet';
import {DeeplinkInteraction, OpenPluginParams} from '../deeplinkTracking'; import {
DeeplinkInteraction,
DeeplinkInteractionState,
OpenPluginParams,
} from '../deeplinkTracking';
export function parseOpenPluginParams(query: string): OpenPluginParams { export function parseOpenPluginParams(query: string): OpenPluginParams {
// 'flipper://open-plugin?plugin-id=graphql&client=facebook&devices=android,ios&chrome=1&payload=' // 'flipper://open-plugin?plugin-id=graphql&client=facebook&devices=android,ios&chrome=1&payload='
@@ -100,9 +104,9 @@ export async function handleOpenPluginDeeplink(
isDevicePlugin, isDevicePlugin,
); );
console.debug('[deeplink] Selected device and client:', deviceOrClient); console.debug('[deeplink] Selected device and client:', deviceOrClient);
if (deviceOrClient === false) { if ('errorState' in deviceOrClient) {
trackInteraction({ trackInteraction({
state: 'PLUGIN_DEVICE_BAIL', state: deviceOrClient.errorState,
plugin: params, plugin: params,
}); });
return; return;
@@ -444,12 +448,16 @@ async function installMarketPlacePlugin(
return true; return true;
} }
type DeeplinkError = {
errorState: DeeplinkInteractionState;
};
async function selectDevicesAndClient( async function selectDevicesAndClient(
store: Store, store: Store,
params: OpenPluginParams, params: OpenPluginParams,
title: string, title: string,
isDevicePlugin: boolean, isDevicePlugin: boolean,
): Promise<false | BaseDevice | Client> { ): Promise<DeeplinkError | BaseDevice | Client> {
function findValidDevices() { function findValidDevices() {
// find connected devices with the right OS. // find connected devices with the right OS.
return ( return (
@@ -468,7 +476,7 @@ async function selectDevicesAndClient(
// loop until we have devices (or abort) // loop until we have devices (or abort)
while (!findValidDevices().length) { while (!findValidDevices().length) {
if (!(await launchDeviceDialog(store, params, title))) { if (!(await launchDeviceDialog(store, params, title))) {
return false; return {errorState: 'PLUGIN_DEVICE_BAIL'};
} }
} }
@@ -483,12 +491,17 @@ async function selectDevicesAndClient(
if (availableDevices.length === 1) { if (availableDevices.length === 1) {
return availableDevices[0]; return availableDevices[0];
} }
return (await selectDeviceDialog(availableDevices, title)) ?? false; const selectedDevice = await selectDeviceDialog(availableDevices, title);
if (!selectedDevice) {
return {errorState: 'PLUGIN_DEVICE_SELECTION_BAIL'};
}
return selectedDevice;
} }
console.debug('[deeplink] Not a device plugin. Waiting for valid client.'); console.debug('[deeplink] Not a device plugin. Waiting for valid client.');
// wait for valid client // wait for valid client
while (true) { while (true) {
const origClients = store.getState().connections.clients;
const validClients = getAllClients(store.getState().connections) const validClients = getAllClients(store.getState().connections)
.filter( .filter(
// correct app name, or, if not set, an app that at least supports this plugin // correct app name, or, if not set, an app that at least supports this plugin
@@ -504,7 +517,11 @@ async function selectDevicesAndClient(
return validClients[0]; return validClients[0];
} }
if (validClients.length > 1) { if (validClients.length > 1) {
return (await selectClientDialog(validClients, title)) ?? false; const selectedClient = await selectClientDialog(validClients, title);
if (!selectedClient) {
return {errorState: 'PLUGIN_CLIENT_SELECTION_BAIL'};
}
return selectedClient;
} }
// no valid client yet // no valid client yet
@@ -520,7 +537,6 @@ async function selectDevicesAndClient(
// eslint-disable-next-line promise/catch-or-return // eslint-disable-next-line promise/catch-or-return
dialog.then(() => resolve(false)); dialog.then(() => resolve(false));
const origClients = store.getState().connections.clients;
// eslint-disable-next-line promise/catch-or-return // eslint-disable-next-line promise/catch-or-return
waitFor(store, (state) => state.connections.clients !== origClients).then( waitFor(store, (state) => state.connections.clients !== origClients).then(
() => { () => {
@@ -539,7 +555,7 @@ async function selectDevicesAndClient(
}); });
if (!result) { if (!result) {
return false; // User cancelled return {errorState: 'PLUGIN_CLIENT_BAIL'}; // User cancelled
} }
} }
} }