From 1a0ee24b1a8bf95e425fc1d594909461fa4d9f75 Mon Sep 17 00:00:00 2001 From: Benjamin Elo Date: Fri, 28 Jun 2019 03:43:39 -0700 Subject: [PATCH] Mac devices excluded from default devices Summary: Bug Summary: When running Flipper on Mac, the Mac device is always first to register with Flipper and thus is always selected as the default connected device when first launching. This blocks the beautiful tutorial screen from appearing for new users. Fix: When registering new devices in the redux store, a new check has been added that maintains a blacklist of devices that cannot be selected as default. I have added Mac to start. At the same time, this fix preserves userPreferredDevices so that if the user has selected Mac as a device in the past, then next time Flipper is opened, even blacklisted devices will be displayed. Making this fix uncovered a race condition, between the redux state being rehydrated and the devices being registered. I have potentially fixed this via a callback function in persistStore. Reviewed By: passy Differential Revision: D16048371 fbshipit-source-id: 79580b30e8a3b077dac1ac15131266e59646253f --- src/init.js | 11 +++++++---- src/reducers/connections.js | 8 +++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/init.js b/src/init.js index 6dd0c3c8b..a104d0dce 100644 --- a/src/init.js +++ b/src/init.js @@ -27,11 +27,10 @@ const store = createStore( reducers, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(), ); -persistStore(store); const logger = initLogger(store); const bugReporter = new BugReporter(logger, store); -dispatcher(store, logger); + GK.init(); const AppFrame = () => ( @@ -69,5 +68,9 @@ function init() { initCrashReporter(sessionId || ''); } -// make init function callable from outside -window.Flipper.init = init; +// rehydrate app state before exposing init +persistStore(store, null, () => { + dispatcher(store, logger); + // make init function callable from outside + window.Flipper.init = init; +}); diff --git a/src/reducers/connections.js b/src/reducers/connections.js index d035b09be..fba9ca801 100644 --- a/src/reducers/connections.js +++ b/src/reducers/connections.js @@ -6,6 +6,7 @@ */ import type BaseDevice from '../devices/BaseDevice'; +import MacDevice from '../devices/MacDevice'; import type Client from '../Client'; import type {UninitializedClient} from '../UninitializedClient'; import {isEqual} from 'lodash'; @@ -95,6 +96,7 @@ export type Action = }; const DEFAULT_PLUGIN = 'DeviceLogs'; +const DEFAULT_DEVICE_BLACKLIST = [MacDevice]; const INITAL_STATE: State = { devices: [], @@ -141,7 +143,11 @@ const reducer = (state: State = INITAL_STATE, action: Action): State => { selectedPlugin: DEFAULT_PLUGIN, }; - if (!selectedDevice) { + let canBeDefaultDevice = !DEFAULT_DEVICE_BLACKLIST.some( + blacklistedDevice => payload instanceof blacklistedDevice, + ); + + if (!selectedDevice && canBeDefaultDevice) { selectedDevice = payload; if (selectedPlugin) { // We already had a plugin selected, but no device. This is happening