Better error handling (#1478)
Summary: Show a notification if device connect failed, or if USB debugging hasn't been authorized When trying to run Flipper on my linux device, it didn't connect to my phone ootb. `adb devices` showed the device, and the flipper console did show an error, which, correctly stated that the device isn't authorized, but I missed the popup on my phone. This hopefully removes one hindrance for others in the future when connecting Flipper to Android. ## Changelog Pull Request resolved: https://github.com/facebook/flipper/pull/1478 Test Plan: Before (no hint in Flipper UI):  After: Desktop notification + notification in notifications section   (sorry, had a movie, but can't access paste and GH doesn't allow them) Reviewed By: passy Differential Revision: D23220915 Pulled By: mweststrate fbshipit-source-id: 4f4bc8023612301191ece62b9bc2bd008f3bb3cb
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c38071e9ba
commit
f342561196
@@ -19,10 +19,12 @@ import which from 'which';
|
|||||||
import {promisify} from 'util';
|
import {promisify} from 'util';
|
||||||
import {ServerPorts} from '../reducers/application';
|
import {ServerPorts} from '../reducers/application';
|
||||||
import {Client as ADBClient} from 'adbkit';
|
import {Client as ADBClient} from 'adbkit';
|
||||||
|
import {addNotification} from '../reducers/notifications';
|
||||||
|
|
||||||
function createDevice(
|
function createDevice(
|
||||||
adbClient: ADBClient,
|
adbClient: ADBClient,
|
||||||
device: any,
|
device: any,
|
||||||
|
store: Store,
|
||||||
ports?: ServerPorts,
|
ports?: ServerPorts,
|
||||||
): Promise<AndroidDevice | undefined> {
|
): Promise<AndroidDevice | undefined> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -79,7 +81,26 @@ function createDevice(
|
|||||||
) {
|
) {
|
||||||
console.debug('Device still connecting: ' + device.id);
|
console.debug('Device still connecting: ' + device.id);
|
||||||
} else {
|
} else {
|
||||||
|
const isAuthorizationError = (e?.message as string)?.includes(
|
||||||
|
'device unauthorized',
|
||||||
|
);
|
||||||
console.error('Failed to initialize device: ' + device.id, e);
|
console.error('Failed to initialize device: ' + device.id, e);
|
||||||
|
store.dispatch(
|
||||||
|
addNotification({
|
||||||
|
client: null,
|
||||||
|
notification: {
|
||||||
|
id: 'androidDeviceConnectionError' + device.id,
|
||||||
|
title: 'Could not connect to ' + device.id,
|
||||||
|
severity: 'error',
|
||||||
|
message: `Failed to connect to '${device.id}': ${
|
||||||
|
isAuthorizationError
|
||||||
|
? 'make sure to authorize debugging on the phone'
|
||||||
|
: JSON.stringify(e, null, 2)
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
pluginId: 'androidDevice',
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
resolve(undefined); // not ready yet, we will find it in the next tick
|
resolve(undefined); // not ready yet, we will find it in the next tick
|
||||||
});
|
});
|
||||||
@@ -92,7 +113,7 @@ export async function getActiveAndroidDevices(
|
|||||||
const client = await getAdbClient(store);
|
const client = await getAdbClient(store);
|
||||||
const androidDevices = await client.listDevices();
|
const androidDevices = await client.listDevices();
|
||||||
const devices = await Promise.all(
|
const devices = await Promise.all(
|
||||||
androidDevices.map((device) => createDevice(client, device)),
|
androidDevices.map((device) => createDevice(client, device, store)),
|
||||||
);
|
);
|
||||||
return devices.filter(Boolean) as any;
|
return devices.filter(Boolean) as any;
|
||||||
}
|
}
|
||||||
@@ -201,6 +222,7 @@ export default (store: Store, logger: Logger) => {
|
|||||||
const androidDevice = await createDevice(
|
const androidDevice = await createDevice(
|
||||||
adbClient,
|
adbClient,
|
||||||
deviceData,
|
deviceData,
|
||||||
|
store,
|
||||||
store.getState().application.serverPorts,
|
store.getState().application.serverPorts,
|
||||||
);
|
);
|
||||||
if (!androidDevice) {
|
if (!androidDevice) {
|
||||||
|
|||||||
Reference in New Issue
Block a user