Preserve Navigation plugin as background plugin eevn when disabled

Summary:
This diff fixes an issue where we don't want to have the Navigation plugin be disabled as background plugins like all other plugins, so that the breadcrumb navigation keeps working.

Yet another hack concerning the super useful Navigation plugin. On a positive note, since connection management for background is not entirely managed by the Desktop and not the native said, these kind of exceptions are fairly easy to make :)

Reviewed By: passy

Differential Revision: D21089537

fbshipit-source-id: 209954ff35c95e066fe688a60ad46ccfc3835c44
This commit is contained in:
Michel Weststrate
2020-04-27 09:43:43 -07:00
committed by Facebook GitHub Bot
parent b9c3d99f44
commit dba480ce74
4 changed files with 34 additions and 16 deletions

View File

@@ -24,7 +24,10 @@ import createTableNativePlugin from './plugins/TableNativePlugin';
import {EventEmitter} from 'events';
import invariant from 'invariant';
import {flipperRecorderAddEvent} from './utils/pluginStateRecorder';
import {getPluginKey} from './utils/pluginUtils';
import {
getPluginKey,
defaultEnabledBackgroundPlugins,
} from './utils/pluginUtils';
import {processMessageLater} from './utils/messageQueue';
import {sideEffect} from './utils/sideEffect';
import {emitBytesReceived} from './dispatcher/tracking';
@@ -241,16 +244,21 @@ export default class Client extends EventEmitter {
return this.backgroundPlugins.includes(pluginId);
}
shouldConnectAsBackgroundPlugin(pluginId: string) {
return (
defaultEnabledBackgroundPlugins.includes(pluginId) ||
this.store
.getState()
.connections.userStarredPlugins[this.query.app]?.includes(pluginId)
);
}
async init() {
this.setMatchingDevice();
await this.loadPlugins();
this.backgroundPlugins = await this.getBackgroundPlugins();
this.backgroundPlugins.forEach((plugin) => {
if (
this.store
.getState()
.connections.userStarredPlugins[this.query.app]?.includes(plugin)
) {
if (this.shouldConnectAsBackgroundPlugin(plugin)) {
this.initPlugin(plugin);
}
});
@@ -312,9 +320,7 @@ export default class Client extends EventEmitter {
newBackgroundPlugins.forEach((plugin) => {
if (
!oldBackgroundPlugins.includes(plugin) &&
this.store
.getState()
.connections.userStarredPlugins[this.query.app]?.includes(plugin)
this.shouldConnectAsBackgroundPlugin(plugin)
) {
this.initPlugin(plugin);
}