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
This commit is contained in:
Benjamin Elo
2019-06-28 03:43:39 -07:00
committed by Facebook Github Bot
parent 63ad32f66b
commit 1a0ee24b1a
2 changed files with 14 additions and 5 deletions

View File

@@ -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;
});

View File

@@ -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