diff --git a/desktop/app/src/Client.tsx b/desktop/app/src/Client.tsx index dd07950e5..5c24f2954 100644 --- a/desktop/app/src/Client.tsx +++ b/desktop/app/src/Client.tsx @@ -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); } diff --git a/desktop/app/src/reducers/connections.tsx b/desktop/app/src/reducers/connections.tsx index 876339342..224601859 100644 --- a/desktop/app/src/reducers/connections.tsx +++ b/desktop/app/src/reducers/connections.tsx @@ -24,7 +24,10 @@ const WelcomeScreen = isHeadless() import NotificationScreen from '../chrome/NotificationScreen'; import SupportRequestFormV2 from '../fb-stubs/SupportRequestFormV2'; import SupportRequestDetails from '../fb-stubs/SupportRequestDetails'; -import {getPluginKey} from '../utils/pluginUtils'; +import { + getPluginKey, + defaultEnabledBackgroundPlugins, +} from '../utils/pluginUtils'; import {deconstructClientId} from '../utils/clientUtils'; import {FlipperDevicePlugin} from '../plugin'; import {RegisterPluginAction} from './plugins'; @@ -288,12 +291,18 @@ const reducer = (state: State = INITAL_STATE, action: Actions): State => { const idx = plugins.indexOf(selectedPlugin); if (idx === -1) { plugins.push(selectedPlugin); - if (client?.isBackgroundPlugin(selectedPlugin)) { + if ( + !defaultEnabledBackgroundPlugins.includes(selectedPlugin) && + client?.isBackgroundPlugin(selectedPlugin) + ) { client.initPlugin(selectedPlugin); } } else { plugins.splice(idx, 1); - if (client?.isBackgroundPlugin(selectedPlugin)) { + if ( + !defaultEnabledBackgroundPlugins.includes(selectedPlugin) && + client?.isBackgroundPlugin(selectedPlugin) + ) { client.deinitPlugin(selectedPlugin); } } diff --git a/desktop/app/src/utils/messageQueue.tsx b/desktop/app/src/utils/messageQueue.tsx index 1c7e4f3a1..7d0e5513f 100644 --- a/desktop/app/src/utils/messageQueue.tsx +++ b/desktop/app/src/utils/messageQueue.tsx @@ -20,6 +20,7 @@ import {Idler, BaseIdler} from './Idler'; import {pluginIsStarred, getSelectedPluginKey} from '../reducers/connections'; import {deconstructPluginKey} from './clientUtils'; import {onBytesReceived} from '../dispatcher/tracking'; +import {defaultEnabledBackgroundPlugins} from './pluginUtils'; const MAX_BACKGROUND_TASK_TIME = 25; @@ -223,9 +224,10 @@ export function processMessageLater( break; default: // In all other cases, messages will be dropped... - console.warn( - `Received message for disabled plugin ${plugin.id}: ${message.method}, dropping..`, - ); + if (!defaultEnabledBackgroundPlugins.includes(plugin.id)) + console.error( + `Received message for disabled plugin ${plugin.id}, dropping..`, + ); } } diff --git a/desktop/app/src/utils/pluginUtils.tsx b/desktop/app/src/utils/pluginUtils.tsx index 3704a913a..83a628ac4 100644 --- a/desktop/app/src/utils/pluginUtils.tsx +++ b/desktop/app/src/utils/pluginUtils.tsx @@ -8,7 +8,6 @@ */ import {FlipperDevicePlugin, FlipperPlugin, FlipperBasePlugin} from '../plugin'; -import BaseDevice from '../devices/BaseDevice'; import {State as PluginStatesState} from '../reducers/pluginStates'; import {State as PluginsState} from '../reducers/plugins'; import {State as PluginMessageQueueState} from '../reducers/pluginMessageQueue'; @@ -17,6 +16,8 @@ import {deconstructPluginKey, deconstructClientId} from './clientUtils'; type Client = import('../Client').default; +export const defaultEnabledBackgroundPlugins = ['Navigation']; // The navigation plugin is enabled always, to make sure the navigation features works + export function pluginsClassMap( plugins: PluginsState, ): Map {