Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
Select new client after connecting, if possible
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mweststrate authored and facebook-github-bot committed Feb 9, 2021
1 parent ff7997b commit 2df1179
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions desktop/app/src/dispatcher/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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));
}
}
}

0 comments on commit 2df1179

Please sign in to comment.