Select new client after connecting, if possible

Summary:
Small UX improvement, try to select a newly arriving client if possible, this is nice as it means that disconnecting and connecting will typically end you up in the same app.

Changelog: If a new client connects, Flipper will try to focus on it

Reviewed By: nikoant

Differential Revision: D26250896

fbshipit-source-id: 83d9777a8608cd887d663a6bbe1444d2aa614e95
This commit is contained in:
Michel Weststrate
2021-02-09 04:12:09 -08:00
committed by Facebook GitHub Bot
parent ff7997b3fa
commit 2df117923c

View File

@@ -15,6 +15,7 @@ import Client from '../Client';
import {UninitializedClient} from '../UninitializedClient';
import {addErrorNotification} from '../reducers/notifications';
import {CertificateExchangeMedium} from '../utils/CertificateProvider';
import {selectClient, selectDevice} from '../reducers/connections';
export default (store: Store, logger: Logger) => {
const server = new Server(logger, store);
@@ -96,9 +97,8 @@ export default (store: Store, logger: Logger) => {
};
export function registerNewClient(store: Store, client: Client) {
const existingClient = store
.getState()
.connections.clients.find((c) => c.id === client.id);
const {connections} = store.getState();
const existingClient = connections.clients.find((c) => c.id === client.id);
if (existingClient) {
existingClient.destroy();
@@ -119,4 +119,21 @@ export function registerNewClient(store: Store, client: Client) {
type: 'NEW_CLIENT',
payload: client,
});
const device = client.deviceSync;
if (device) {
const selectedDevice = connections.selectedDevice;
const selectedClient = connections.clients.find(
(c) => c.id === connections.selectedApp,
);
if (
// If this condition meets, it means that the previous app wasn't selected explicitly by the user
connections.selectedApp !== connections.userPreferredApp ||
!selectedClient ||
!selectedDevice
) {
store.dispatch(selectDevice(device));
store.dispatch(selectClient(client.id));
}
}
}