Rename star/unstar actions to enable/disable/switch

Summary:
Renamed actions "star" and "unstar" everywhere to "enable", "disable" and "switch". The logic behind original "star" action changed significantly, so this rename just makes everything much clearer.

Please note that as a part of rename persisted state fields "userStarredPlugins" and "userStarredDevicePlugins" were renamed. I've added a "redux-persist" migration for seamless transition.

Reviewed By: passy

Differential Revision: D26606459

fbshipit-source-id: 83ad475f9b0231194701c40a2cdbda36f02c3d10
This commit is contained in:
Anton Nikolaev
2021-02-24 05:28:25 -08:00
committed by Facebook GitHub Bot
parent e9bab76614
commit fa3ff83595
29 changed files with 230 additions and 201 deletions

View File

@@ -222,7 +222,7 @@ export default class Client extends EventEmitter {
isEnabledPlugin(pluginId: string) {
return this.store
.getState()
.connections.userStarredPlugins[this.query.app]?.includes(pluginId);
.connections.enabledPlugins[this.query.app]?.includes(pluginId);
}
shouldConnectAsBackgroundPlugin(pluginId: string) {
@@ -294,7 +294,7 @@ export default class Client extends EventEmitter {
plugin: PluginDefinition | undefined,
isEnabled = plugin ? this.isEnabledPlugin(plugin.id) : false,
) {
// start a plugin on start if it is a SandyPlugin, which is starred, and doesn't have persisted state yet
// start a plugin on start if it is a SandyPlugin, which is enabled, and doesn't have persisted state yet
if (
isSandyPlugin(plugin) &&
(isEnabled || defaultEnabledBackgroundPlugins.includes(plugin.id)) &&
@@ -375,7 +375,7 @@ export default class Client extends EventEmitter {
!newBackgroundPlugins.includes(plugin) &&
this.store
.getState()
.connections.userStarredPlugins[this.query.app]?.includes(plugin)
.connections.enabledPlugins[this.query.app]?.includes(plugin)
) {
this.deinitPlugin(plugin);
}

View File

@@ -32,9 +32,9 @@ import {
import {
StaticView,
setStaticView,
pluginIsStarred,
isPluginEnabled,
} from './reducers/connections';
import {starPlugin} from './reducers/pluginManager';
import {switchPlugin} from './reducers/pluginManager';
import React, {PureComponent} from 'react';
import {connect, ReactReduxContext} from 'react-redux';
import {setPluginState} from './reducers/pluginStates';
@@ -127,7 +127,7 @@ type DispatchFromProps = {
}) => any;
setPluginState: (payload: {pluginKey: string; state: any}) => void;
setStaticView: (payload: StaticView) => void;
starPlugin: typeof starPlugin;
enablePlugin: typeof switchPlugin;
loadPlugin: typeof loadPlugin;
};
@@ -315,7 +315,7 @@ class PluginContainer extends PureComponent<Props, State> {
<ToggleButton
toggled={false}
onClick={() => {
this.props.starPlugin({
this.props.enablePlugin({
plugin: activePlugin,
selectedApp: (this.props.target as Client)?.query?.app,
});
@@ -552,8 +552,8 @@ export default connect<StateFromProps, DispatchFromProps, OwnProps, Store>(
selectedApp,
clients,
deepLinkPayload,
userStarredPlugins,
userStarredDevicePlugins,
enabledPlugins,
enabledDevicePlugins,
},
pluginStates,
plugins: {devicePlugins, clientPlugins, installedPlugins},
@@ -580,9 +580,9 @@ export default connect<StateFromProps, DispatchFromProps, OwnProps, Store>(
}
pluginIsEnabled =
activePlugin !== undefined &&
pluginIsStarred(
userStarredPlugins,
userStarredDevicePlugins,
isPluginEnabled(
enabledPlugins,
enabledDevicePlugins,
selectedApp,
activePlugin.id,
);
@@ -619,7 +619,7 @@ export default connect<StateFromProps, DispatchFromProps, OwnProps, Store>(
setPluginState,
selectPlugin,
setStaticView,
starPlugin,
loadPlugin: loadPlugin,
enablePlugin: switchPlugin,
loadPlugin,
},
)(PluginContainer);

View File

@@ -23,7 +23,7 @@ import {
} from 'flipper-plugin';
import {selectPlugin} from '../reducers/connections';
import {updateSettings} from '../reducers/settings';
import {starPlugin} from '../reducers/pluginManager';
import {switchPlugin} from '../reducers/pluginManager';
interface PersistedState {
count: 1;
@@ -287,7 +287,7 @@ test('PluginContainer can render Sandy plugins', async () => {
// disable
act(() => {
store.dispatch(
starPlugin({
switchPlugin({
plugin: definition,
selectedApp: client.query.app,
}),
@@ -302,7 +302,7 @@ test('PluginContainer can render Sandy plugins', async () => {
// re-enable
act(() => {
store.dispatch(
starPlugin({
switchPlugin({
plugin: definition,
selectedApp: client.query.app,
}),
@@ -402,7 +402,7 @@ test('PluginContainer triggers correct lifecycles for background plugin', async
// disable
act(() => {
store.dispatch(
starPlugin({
switchPlugin({
plugin: definition,
selectedApp: client.query.app,
}),
@@ -427,7 +427,7 @@ test('PluginContainer triggers correct lifecycles for background plugin', async
// re-enable
act(() => {
store.dispatch(
starPlugin({
switchPlugin({
plugin: definition,
selectedApp: client.query.app,
}),
@@ -962,7 +962,7 @@ test('Sandy plugins support isPluginSupported + selectPlugin', async () => {
expect(linksSeen).toEqual([]);
// star and navigate to a device plugin
store.dispatch(starPlugin({plugin: definition3}));
store.dispatch(switchPlugin({plugin: definition3}));
pluginInstance.selectPlugin(definition3.id);
expect(pluginInstance.isPluginAvailable(definition3.id)).toBeTruthy();
expect(store.getState().connections.selectedPlugin).toBe(definition3.id);
@@ -984,13 +984,13 @@ test('Sandy plugins support isPluginSupported + selectPlugin', async () => {
`);
expect(linksSeen).toEqual(['data']);
// try to go to plugin 2, fails (not starred, so no-op)
// try to go to plugin 2, fails (not enabled, so no-op)
pluginInstance.selectPlugin(definition2.id);
expect(store.getState().connections.selectedPlugin).toBe(definition.id);
// star plugin 2 and navigate to plugin 2
store.dispatch(
starPlugin({
switchPlugin({
plugin: definition2,
selectedApp: client.query.app,
}),

View File

@@ -24,6 +24,18 @@ Object {
"title": "MockAndroidDevice",
},
],
"enabledDevicePlugins": Set {
"DeviceLogs",
"CrashReporter",
"MobileBuilds",
"Hermesdebuggerrn",
"React",
},
"enabledPlugins": Object {
"TestApp": Array [
"TestPlugin",
],
},
"selectedApp": "TestApp#Android#MockAndroidDevice#serial",
"selectedDevice": Object {
"deviceType": "physical",
@@ -37,18 +49,6 @@ Object {
"userPreferredApp": "TestApp#Android#MockAndroidDevice#serial",
"userPreferredDevice": "MockAndroidDevice",
"userPreferredPlugin": "TestPlugin",
"userStarredDevicePlugins": Set {
"DeviceLogs",
"CrashReporter",
"MobileBuilds",
"Hermesdebuggerrn",
"React",
},
"userStarredPlugins": Object {
"TestApp": Array [
"TestPlugin",
],
},
}
`;

View File

@@ -111,7 +111,7 @@ test('New device with same serial removes & cleans the old one', async () => {
});
device2.loadDevicePlugins(
store.getState().plugins.devicePlugins,
store.getState().connections.userStarredDevicePlugins,
store.getState().connections.enabledDevicePlugins,
);
expect(device.isArchived).toBe(false);

View File

@@ -11,7 +11,7 @@ jest.mock('../plugins');
jest.mock('../../utils/electronModuleCache');
import {
loadPlugin,
starPlugin,
switchPlugin,
uninstallPlugin,
} from '../../reducers/pluginManager';
import {requirePlugin} from '../plugins';
@@ -189,35 +189,35 @@ test('star plugin', async () => {
loadPlugin({plugin: pluginDetails1, enable: false, notifyIfFailed: false}),
);
mockFlipper.dispatch(
starPlugin({
switchPlugin({
plugin: pluginDefinition1,
selectedApp: mockClient.query.app,
}),
);
expect(
mockFlipper.getState().connections.userStarredPlugins[mockClient.query.app],
mockFlipper.getState().connections.enabledPlugins[mockClient.query.app],
).toContain('plugin1');
expect(mockClient.sandyPluginStates.has('plugin1')).toBeTruthy();
});
test('unstar plugin', async () => {
test('disable plugin', async () => {
mockFlipper.dispatch(
loadPlugin({plugin: pluginDetails1, enable: false, notifyIfFailed: false}),
);
mockFlipper.dispatch(
starPlugin({
switchPlugin({
plugin: pluginDefinition1,
selectedApp: mockClient.query.app,
}),
);
mockFlipper.dispatch(
starPlugin({
switchPlugin({
plugin: pluginDefinition1,
selectedApp: mockClient.query.app,
}),
);
expect(
mockFlipper.getState().connections.userStarredPlugins[mockClient.query.app],
mockFlipper.getState().connections.enabledPlugins[mockClient.query.app],
).not.toContain('plugin1');
expect(mockClient.sandyPluginStates.has('plugin1')).toBeFalsy();
});
@@ -231,17 +231,17 @@ test('star device plugin', async () => {
}),
);
mockFlipper.dispatch(
starPlugin({
switchPlugin({
plugin: devicePluginDefinition,
}),
);
expect(
mockFlipper.getState().connections.userStarredDevicePlugins.has('device'),
mockFlipper.getState().connections.enabledDevicePlugins.has('device'),
).toBeTruthy();
expect(mockDevice.sandyPluginStates.has('device')).toBeTruthy();
});
test('unstar device plugin', async () => {
test('disable device plugin', async () => {
mockFlipper.dispatch(
loadPlugin({
plugin: devicePluginDetails,
@@ -250,17 +250,17 @@ test('unstar device plugin', async () => {
}),
);
mockFlipper.dispatch(
starPlugin({
switchPlugin({
plugin: devicePluginDefinition,
}),
);
mockFlipper.dispatch(
starPlugin({
switchPlugin({
plugin: devicePluginDefinition,
}),
);
expect(
mockFlipper.getState().connections.userStarredDevicePlugins.has('device'),
mockFlipper.getState().connections.enabledDevicePlugins.has('device'),
).toBeFalsy();
expect(mockDevice.sandyPluginStates.has('device')).toBeFalsy();
});

View File

@@ -242,7 +242,7 @@ export default (store: Store, logger: Logger) => {
androidDevice.loadDevicePlugins(
store.getState().plugins.devicePlugins,
store.getState().connections.userStarredDevicePlugins,
store.getState().connections.enabledDevicePlugins,
);
store.dispatch({
type: 'REGISTER_DEVICE',

View File

@@ -24,7 +24,7 @@ export default (store: Store, _logger: Logger) => {
}
device.loadDevicePlugins(
store.getState().plugins.devicePlugins,
store.getState().connections.userStarredDevicePlugins,
store.getState().connections.enabledDevicePlugins,
);
store.dispatch({
type: 'REGISTER_DEVICE',

View File

@@ -136,7 +136,7 @@ function processDevices(
const iOSDevice = new IOSDevice(udid, type, name);
iOSDevice.loadDevicePlugins(
store.getState().plugins.devicePlugins,
store.getState().connections.userStarredDevicePlugins,
store.getState().connections.enabledDevicePlugins,
);
store.dispatch({
type: 'REGISTER_DEVICE',

View File

@@ -59,7 +59,7 @@ export async function registerMetroDevice(
metroDevice.loadDevicePlugins(
store.getState().plugins.devicePlugins,
store.getState().connections.userStarredDevicePlugins,
store.getState().connections.enabledDevicePlugins,
);
store.dispatch({
type: 'REGISTER_DEVICE',

View File

@@ -165,7 +165,7 @@ function pluginIsDisabledForAllConnectedClients(
return (
!state.plugins.clientPlugins.has(plugin.id) ||
!state.connections.clients.some((c) =>
state.connections.userStarredPlugins[c.query.app]?.includes(plugin.id),
state.connections.enabledPlugins[c.query.app]?.includes(plugin.id),
)
);
}

View File

@@ -15,7 +15,7 @@ import {
UninstallPluginActionPayload,
UpdatePluginActionPayload,
pluginCommandsProcessed,
StarPluginActionPayload,
SwitchPluginActionPayload,
PluginCommand,
} from '../reducers/pluginManager';
import {
@@ -42,10 +42,10 @@ import {
} from '../reducers/plugins';
import {_SandyPluginDefinition} from 'flipper-plugin';
import {
devicePluginStarred,
devicePluginUnstarred,
pluginStarred,
pluginUnstarred,
setDevicePluginEnabled,
setDevicePluginDisabled,
setPluginEnabled,
setPluginDisabled,
} from '../reducers/connections';
import {deconstructClientId} from '../utils/clientUtils';
import {clearMessageQueue} from '../reducers/pluginMessageQueue';
@@ -112,8 +112,8 @@ export function processPluginCommandsQueue(
case 'UPDATE_PLUGIN':
updatePlugin(store, command.payload);
break;
case 'STAR_PLUGIN':
starPlugin(store, command.payload);
case 'SWITCH_PLUGIN':
switchPlugin(store, command.payload);
break;
default:
console.error('Unexpected plugin command', command);
@@ -181,18 +181,18 @@ function getSelectedAppId(store: Store) {
return selectedApp;
}
function starPlugin(
function switchPlugin(
store: Store,
{plugin, selectedApp}: StarPluginActionPayload,
{plugin, selectedApp}: SwitchPluginActionPayload,
) {
if (isDevicePluginDefinition(plugin)) {
starDevicePlugin(store, plugin);
switchDevicePlugin(store, plugin);
} else {
starClientPlugin(store, plugin, selectedApp);
switchClientPlugin(store, plugin, selectedApp);
}
}
function starClientPlugin(
function switchClientPlugin(
store: Store,
plugin: ClientPluginDefinition,
selectedApp: string | undefined,
@@ -205,7 +205,7 @@ function starClientPlugin(
const clients = connections.clients.filter(
(client) => client.query.app === selectedApp,
);
if (connections.userStarredPlugins[selectedApp]?.includes(plugin.id)) {
if (connections.enabledPlugins[selectedApp]?.includes(plugin.id)) {
clients.forEach((client) => {
stopPlugin(client, plugin.id);
const pluginKey = getPluginKey(
@@ -215,30 +215,30 @@ function starClientPlugin(
);
store.dispatch(clearMessageQueue(pluginKey));
});
store.dispatch(pluginUnstarred(plugin.id, selectedApp));
store.dispatch(setPluginDisabled(plugin.id, selectedApp));
} else {
clients.forEach((client) => {
startPlugin(client, plugin);
});
store.dispatch(pluginStarred(plugin.id, selectedApp));
store.dispatch(setPluginEnabled(plugin.id, selectedApp));
}
}
function starDevicePlugin(store: Store, plugin: DevicePluginDefinition) {
function switchDevicePlugin(store: Store, plugin: DevicePluginDefinition) {
const {connections} = store.getState();
const devicesWithPlugin = connections.devices.filter((d) =>
d.supportsPlugin(plugin.details),
);
if (connections.userStarredDevicePlugins.has(plugin.id)) {
if (connections.enabledDevicePlugins.has(plugin.id)) {
devicesWithPlugin.forEach((d) => {
d.unloadDevicePlugin(plugin.id);
});
store.dispatch(devicePluginUnstarred(plugin.id));
store.dispatch(setDevicePluginDisabled(plugin.id));
} else {
devicesWithPlugin.forEach((d) => {
d.loadDevicePlugin(plugin);
});
store.dispatch(devicePluginStarred(plugin.id));
store.dispatch(setDevicePluginEnabled(plugin.id));
}
}
@@ -251,7 +251,7 @@ function updateClientPlugin(
if (enable) {
const selectedApp = getSelectedAppId(store);
if (selectedApp) {
store.dispatch(pluginStarred(plugin.id, selectedApp));
store.dispatch(setPluginEnabled(plugin.id, selectedApp));
}
}
const clientsWithEnabledPlugin = clients.filter((c) => {
@@ -259,7 +259,7 @@ function updateClientPlugin(
c.supportsPlugin(plugin.id) &&
store
.getState()
.connections.userStarredPlugins[c.query.app]?.includes(plugin.id)
.connections.enabledPlugins[c.query.app]?.includes(plugin.id)
);
});
const previousVersion = store.getState().plugins.clientPlugins.get(plugin.id);
@@ -283,7 +283,7 @@ function updateDevicePlugin(
enable: boolean,
) {
if (enable) {
store.dispatch(devicePluginStarred(plugin.id));
store.dispatch(setDevicePluginEnabled(plugin.id));
}
const connections = store.getState().connections;
const devicesWithEnabledPlugin = connections.devices.filter((d) =>

View File

@@ -145,12 +145,18 @@ export default (store: Store, logger: Logger) => {
logger.track('usage', TIME_SPENT_EVENT, usageSummary[key], key);
}
Object.entries(state.connections.userStarredPlugins).forEach(
([app, plugins]) =>
Object.entries(state.connections.enabledPlugins).forEach(
([app, plugins]) => {
// TODO: remove "starred-plugns" event in favor of "enabled-plugins" after some transition period
logger.track('usage', 'starred-plugins', {
app: app,
app,
starredPlugins: plugins,
}),
});
logger.track('usage', 'enabled-plugins', {
app,
enabledPugins: plugins,
});
},
);
const bgStats = getPluginBackgroundStats();

View File

@@ -17,7 +17,7 @@ import {
PluginClient,
TestUtils,
} from 'flipper-plugin';
import {starPlugin} from '../pluginManager';
import {switchPlugin} from '../pluginManager';
const pluginDetails = TestUtils.createMockPluginDetails();
@@ -59,7 +59,7 @@ type PluginApi = ReturnType<typeof plugin>;
function starTestPlugin(store: Store, client: Client) {
store.dispatch(
starPlugin({
switchPlugin({
plugin: TestPlugin,
selectedApp: client.query.app,
}),
@@ -110,7 +110,7 @@ test('it should cleanup a plugin if disabled', async () => {
client.initPlugin(TestPlugin.id);
expect(pluginInstance.connectStub).toHaveBeenCalledTimes(1);
// unstar
// disable
starTestPlugin(store, client);
expect(client.sandyPluginStates.has(TestPlugin.id)).toBeFalsy();
expect(pluginInstance.disconnectStub).toHaveBeenCalledTimes(1);
@@ -174,7 +174,7 @@ test('it should not initialize a sandy plugin if not enabled', async () => {
expect(Plugin2.asPluginModule().plugin).toBeCalledTimes(0);
store.dispatch(
starPlugin({
switchPlugin({
plugin: Plugin2,
selectedApp: client.query.app,
}),
@@ -193,7 +193,7 @@ test('it should not initialize a sandy plugin if not enabled', async () => {
// disable plugin again
store.dispatch(
starPlugin({
switchPlugin({
plugin: Plugin2,
selectedApp: client.query.app,
}),
@@ -278,7 +278,7 @@ test('it should initialize "Navigation" plugin if not enabled', async () => {
expect(Plugin2.asPluginModule().plugin).toBeCalledTimes(1);
store.dispatch(
starPlugin({
switchPlugin({
plugin: Plugin2,
selectedApp: client.query.app,
}),
@@ -292,7 +292,7 @@ test('it should initialize "Navigation" plugin if not enabled', async () => {
// disable plugin again
store.dispatch(
starPlugin({
switchPlugin({
plugin: Plugin2,
selectedApp: client.query.app,
}),

View File

@@ -31,7 +31,22 @@ export type StaticView =
| ComponentType<StaticViewProps>
| React.FunctionComponent<any>;
export type State = {
export type State = StateV1;
export const persistVersion = 1;
export const persistMigrations = {
1: (state: any) => {
const stateV0 = state as StateV0;
const stateV1 = {
...stateV0,
enabledPlugins: stateV0.userStarredPlugins,
enabledDevicePlugins: stateV0.userStarredDevicePlugins,
};
return stateV1 as any;
},
};
type StateV1 = {
devices: Array<BaseDevice>;
androidEmulators: Array<string>;
selectedDevice: null | BaseDevice;
@@ -40,8 +55,8 @@ export type State = {
userPreferredDevice: null | string;
userPreferredPlugin: null | string;
userPreferredApp: null | string;
userStarredPlugins: {[client: string]: string[]};
userStarredDevicePlugins: Set<string>;
enabledPlugins: {[client: string]: string[]};
enabledDevicePlugins: Set<string>;
clients: Array<Client>;
uninitializedClients: Array<{
client: UninitializedClient;
@@ -52,6 +67,11 @@ export type State = {
staticView: StaticView;
};
type StateV0 = Omit<StateV1, 'enabledPlugins' | 'enabledDevicePlugins'> & {
userStarredPlugins: {[client: string]: string[]};
userStarredDevicePlugins: Set<string>;
};
export type Action =
| {
type: 'UNREGISTER_DEVICES';
@@ -109,27 +129,27 @@ export type Action =
deepLinkPayload: unknown;
}
| {
type: 'PLUGIN_STARRED';
type: 'SET_PLUGIN_ENABLED';
payload: {
pluginId: string;
selectedApp: string;
};
}
| {
type: 'DEVICE_PLUGIN_STARRED';
type: 'SET_DEVICE_PLUGIN_ENABLED';
payload: {
pluginId: string;
};
}
| {
type: 'PLUGIN_UNSTARRED';
type: 'SET_PLUGIN_DISABLED';
payload: {
pluginId: string;
selectedApp: string;
};
}
| {
type: 'DEVICE_PLUGIN_UNSTARRED';
type: 'SET_DEVICE_PLUGIN_DISABLED';
payload: {
pluginId: string;
};
@@ -151,8 +171,8 @@ const INITAL_STATE: State = {
userPreferredDevice: null,
userPreferredPlugin: null,
userPreferredApp: null,
userStarredPlugins: {},
userStarredDevicePlugins: new Set([
enabledPlugins: {},
enabledDevicePlugins: new Set([
'DeviceLogs',
'CrashReporter',
'MobileBuilds',
@@ -384,42 +404,42 @@ export default (state: State = INITAL_STATE, action: Actions): State => {
});
return state;
}
case 'PLUGIN_STARRED': {
case 'SET_PLUGIN_ENABLED': {
const {pluginId, selectedApp} = action.payload;
return produce(state, (draft) => {
if (!draft.userStarredPlugins[selectedApp]) {
draft.userStarredPlugins[selectedApp] = [];
if (!draft.enabledPlugins[selectedApp]) {
draft.enabledPlugins[selectedApp] = [];
}
const plugins = draft.userStarredPlugins[selectedApp];
const plugins = draft.enabledPlugins[selectedApp];
const idx = plugins.indexOf(pluginId);
if (idx === -1) {
plugins.push(pluginId);
}
});
}
case 'DEVICE_PLUGIN_STARRED': {
case 'SET_DEVICE_PLUGIN_ENABLED': {
const {pluginId} = action.payload;
return produce(state, (draft) => {
draft.userStarredDevicePlugins.add(pluginId);
draft.enabledDevicePlugins.add(pluginId);
});
}
case 'PLUGIN_UNSTARRED': {
case 'SET_PLUGIN_DISABLED': {
const {pluginId, selectedApp} = action.payload;
return produce(state, (draft) => {
if (!draft.userStarredPlugins[selectedApp]) {
draft.userStarredPlugins[selectedApp] = [];
if (!draft.enabledPlugins[selectedApp]) {
draft.enabledPlugins[selectedApp] = [];
}
const plugins = draft.userStarredPlugins[selectedApp];
const plugins = draft.enabledPlugins[selectedApp];
const idx = plugins.indexOf(pluginId);
if (idx !== -1) {
plugins.splice(idx, 1);
}
});
}
case 'DEVICE_PLUGIN_UNSTARRED': {
case 'SET_DEVICE_PLUGIN_DISABLED': {
const {pluginId} = action.payload;
return produce(state, (draft) => {
draft.userStarredDevicePlugins.delete(pluginId);
draft.enabledDevicePlugins.delete(pluginId);
});
}
default:
@@ -467,30 +487,30 @@ export const selectClient = (clientId: string | null): Action => ({
payload: clientId,
});
export const pluginStarred = (pluginId: string, appId: string): Action => ({
type: 'PLUGIN_STARRED',
export const setPluginEnabled = (pluginId: string, appId: string): Action => ({
type: 'SET_PLUGIN_ENABLED',
payload: {
pluginId,
selectedApp: appId,
},
});
export const devicePluginStarred = (pluginId: string): Action => ({
type: 'DEVICE_PLUGIN_STARRED',
export const setDevicePluginEnabled = (pluginId: string): Action => ({
type: 'SET_DEVICE_PLUGIN_ENABLED',
payload: {
pluginId,
},
});
export const devicePluginUnstarred = (pluginId: string): Action => ({
type: 'DEVICE_PLUGIN_UNSTARRED',
export const setDevicePluginDisabled = (pluginId: string): Action => ({
type: 'SET_DEVICE_PLUGIN_DISABLED',
payload: {
pluginId,
},
});
export const pluginUnstarred = (pluginId: string, appId: string): Action => ({
type: 'PLUGIN_UNSTARRED',
export const setPluginDisabled = (pluginId: string, appId: string): Action => ({
type: 'SET_PLUGIN_DISABLED',
payload: {
pluginId,
selectedApp: appId,
@@ -618,19 +638,19 @@ export function getSelectedPluginKey(state: State): string | undefined {
: undefined;
}
export function pluginIsStarred(
userStarredPlugins: State['userStarredPlugins'],
userStarredDevicePlugins: State['userStarredDevicePlugins'],
export function isPluginEnabled(
enabledPlugins: State['enabledPlugins'],
enabledDevicePlugins: State['enabledDevicePlugins'],
app: string | null,
pluginId: string,
): boolean {
if (userStarredDevicePlugins.has(pluginId)) {
if (enabledDevicePlugins.has(pluginId)) {
return true;
}
if (!app) {
return false;
}
const appInfo = deconstructClientId(app);
const starred = userStarredPlugins[appInfo.app];
const starred = enabledPlugins[appInfo.app];
return starred && starred.indexOf(pluginId) > -1;
}

View File

@@ -15,6 +15,8 @@ import application, {
import connections, {
State as DevicesState,
Action as DevicesAction,
persistMigrations as devicesPersistMigrations,
persistVersion as devicesPersistVersion,
} from './connections';
import pluginStates, {
State as PluginStatesState,
@@ -67,7 +69,7 @@ import {launcherConfigDir} from '../utils/launcher';
import os from 'os';
import {resolve} from 'path';
import xdg from 'xdg-basedir';
import {createTransform, persistReducer} from 'redux-persist';
import {createMigrate, createTransform, persistReducer} from 'redux-persist';
import {PersistPartial} from 'redux-persist/es/persistReducer';
import {Store as ReduxStore, MiddlewareAPI as ReduxMiddlewareAPI} from 'redux';
@@ -140,10 +142,16 @@ export default combineReducers<State, Actions>({
'userPreferredDevice',
'userPreferredPlugin',
'userPreferredApp',
'userStarredPlugins',
'userStarredDevicePlugins',
'enabledPlugins',
'enabledDevicePlugins',
],
transforms: [setTransformer({whitelist: ['userStarredDevicePlugins']})],
transforms: [
setTransformer({
whitelist: ['enabledDevicePlugins', 'userStarredDevicePlugins'],
}),
],
version: devicesPersistVersion,
migrate: createMigrate(devicesPersistMigrations),
},
connections,
),

View File

@@ -20,7 +20,7 @@ export type PluginCommand =
| LoadPluginAction
| UninstallPluginAction
| UpdatePluginAction
| StarPluginAction;
| SwitchPluginAction;
export type LoadPluginActionPayload = {
plugin: ActivatablePluginDetails;
@@ -52,14 +52,14 @@ export type UpdatePluginAction = {
payload: UpdatePluginActionPayload;
};
export type StarPluginActionPayload = {
export type SwitchPluginActionPayload = {
plugin: PluginDefinition;
selectedApp?: string;
};
export type StarPluginAction = {
type: 'STAR_PLUGIN';
payload: StarPluginActionPayload;
export type SwitchPluginAction = {
type: 'SWITCH_PLUGIN';
payload: SwitchPluginActionPayload;
};
export type Action =
@@ -81,7 +81,7 @@ export default function reducer(
case 'LOAD_PLUGIN':
case 'UNINSTALL_PLUGIN':
case 'UPDATE_PLUGIN':
case 'STAR_PLUGIN':
case 'SWITCH_PLUGIN':
return produce(state, (draft) => {
draft.pluginCommandsQueue.push(action);
});
@@ -118,7 +118,7 @@ export const registerPluginUpdate = (
payload,
});
export const starPlugin = (payload: StarPluginActionPayload): Action => ({
type: 'STAR_PLUGIN',
export const switchPlugin = (payload: SwitchPluginActionPayload): Action => ({
type: 'SWITCH_PLUGIN',
payload,
});

View File

@@ -10,7 +10,7 @@
import {Actions, Store} from './';
import {setStaticView} from './connections';
import {deconstructClientId} from '../utils/clientUtils';
import {starPlugin as setStarPlugin} from './pluginManager';
import {switchPlugin} from './pluginManager';
import {showStatusUpdatesForDuration} from '../utils/promiseTimeout';
import {selectedPlugins as setSelectedPlugins} from './plugins';
import {addStatusMessage, removeStatusMessage} from './application';
@@ -125,7 +125,7 @@ export class Group {
if (selectedApp) {
const {app} = deconstructClientId(selectedApp);
const enabledPlugins: Array<string> | null = store.getState().connections
.userStarredPlugins[app];
.enabledPlugins[app];
const unsupportedPlugins = [];
for (const requiredPlugin of this.requiredPlugins) {
const requiredPluginEnabled =
@@ -139,7 +139,7 @@ export class Group {
store.getState().plugins.clientPlugins.get(requiredPlugin) ||
store.getState().plugins.devicePlugins.get(requiredPlugin)!;
store.dispatch(
setStarPlugin({
switchPlugin({
selectedApp: app,
plugin,
}),

View File

@@ -38,7 +38,7 @@ import {
} from '../../reducers/pluginDownloads';
import {
loadPlugin,
starPlugin,
switchPlugin,
uninstallPlugin,
} from '../../reducers/pluginManager';
import {BundledPluginDetails} from 'plugin-lib';
@@ -86,8 +86,8 @@ export const PluginList = memo(function PluginList({
metroDevice,
client,
plugins,
connections.userStarredPlugins,
connections.userStarredDevicePlugins,
connections.enabledPlugins,
connections.enabledDevicePlugins,
pluginsChanged,
]);
const isConnected = useValue(activeDevice?.connected, false);
@@ -142,12 +142,12 @@ export const PluginList = memo(function PluginList({
},
[dispatch, metroDevice, connections.selectedApp],
);
const handleStarPlugin = useCallback(
const handleEnablePlugin = useCallback(
(id: string) => {
const plugin = (plugins.clientPlugins.get(id) ??
plugins.devicePlugins.get(id))!;
dispatch(
starPlugin({
switchPlugin({
selectedApp: client?.query.app,
plugin,
}),
@@ -207,7 +207,7 @@ export const PluginList = memo(function PluginList({
isArchived ? null : (
<ActionButton
id={plugin.id}
onClick={handleStarPlugin}
onClick={handleEnablePlugin}
title="Disable plugin"
icon={
<MinusOutlined size={16} style={{marginRight: 0}} />
@@ -250,7 +250,7 @@ export const PluginList = memo(function PluginList({
isConnected ? (
<ActionButton
id={plugin.id}
onClick={handleStarPlugin}
onClick={handleEnablePlugin}
title="Disable plugin"
icon={
<MinusOutlined size={16} style={{marginRight: 0}} />
@@ -285,7 +285,7 @@ export const PluginList = memo(function PluginList({
<ActionButton
id={plugin.id}
title="Enable plugin"
onClick={handleStarPlugin}
onClick={handleEnablePlugin}
icon={
<PlusOutlined size={16} style={{marginRight: 0}} />
}

View File

@@ -24,7 +24,7 @@ import {
registerMarketplacePlugins,
registerPlugins,
} from '../../../reducers/plugins';
import {starPlugin} from '../../../reducers/pluginManager';
import {switchPlugin} from '../../../reducers/pluginManager';
// eslint-disable-next-line
import * as LogsPluginModule from '../../../../../plugins/logs/index';
@@ -174,8 +174,8 @@ describe('basic findBestDevice with metro present', () => {
metro,
flipper.client,
state.plugins,
state.connections.userStarredPlugins,
state.connections.userStarredDevicePlugins,
state.connections.enabledPlugins,
state.connections.enabledDevicePlugins,
),
).toEqual({
downloadablePlugins: [],
@@ -286,8 +286,8 @@ describe('basic findBestDevice with metro present', () => {
metro,
flipper.client,
state.plugins,
state.connections.userStarredPlugins,
state.connections.userStarredDevicePlugins,
state.connections.enabledPlugins,
state.connections.enabledDevicePlugins,
);
expect(pluginLists).toEqual({
devicePlugins: [logsPlugin],
@@ -316,7 +316,7 @@ describe('basic findBestDevice with metro present', () => {
});
flipper.store.dispatch(
starPlugin({
switchPlugin({
plugin: plugin2,
selectedApp: flipper.client.query.app,
}),
@@ -328,8 +328,8 @@ describe('basic findBestDevice with metro present', () => {
metro,
flipper.client,
state.plugins,
state.connections.userStarredPlugins,
state.connections.userStarredDevicePlugins,
state.connections.enabledPlugins,
state.connections.enabledDevicePlugins,
),
).toMatchObject({
enabledPlugins: [plugin2],

View File

@@ -126,7 +126,7 @@ export default class MockFlipper {
});
device.loadDevicePlugins(
this._store.getState().plugins.devicePlugins,
this.store.getState().connections.userStarredDevicePlugins,
this.store.getState().connections.enabledDevicePlugins,
);
this._devices.push(device);
return device;

View File

@@ -31,7 +31,7 @@ import {PluginDefinition} from '../plugin';
import PluginContainer from '../PluginContainer';
import {getPluginKey, isDevicePluginDefinition} from '../utils/pluginUtils';
import MockFlipper from './MockFlipper';
import {starPlugin} from '../reducers/pluginManager';
import {switchPlugin} from '../reducers/pluginManager';
export type MockFlipperResult = {
client: Client;
@@ -71,11 +71,9 @@ function isPluginEnabled(
(!isDevicePluginDefinition(pluginClazz) &&
store
.getState()
.connections.userStarredPlugins[selectedApp]?.includes(
pluginClazz.id,
)) ||
.connections.enabledPlugins[selectedApp]?.includes(pluginClazz.id)) ||
(isDevicePluginDefinition(pluginClazz) &&
store.getState().connections.userStarredDevicePlugins.has(pluginClazz.id))
store.getState().connections.enabledDevicePlugins.has(pluginClazz.id))
);
}
@@ -108,7 +106,7 @@ export async function createMockFlipperWithPlugin(
// enable the plugin
if (!isPluginEnabled(store, pluginClazz, name)) {
store.dispatch(
starPlugin({
switchPlugin({
plugin: pluginClazz,
selectedApp: client.query.app,
}),
@@ -118,7 +116,7 @@ export async function createMockFlipperWithPlugin(
options?.additionalPlugins?.forEach((plugin) => {
if (!isPluginEnabled(store, plugin, name)) {
store.dispatch(
starPlugin({
switchPlugin({
plugin,
selectedApp: client.query.app,
}),
@@ -172,7 +170,7 @@ export async function createMockFlipperWithPlugin(
throw new Error('unknown plugin ' + id);
}
store.dispatch(
starPlugin({
switchPlugin({
plugin,
selectedApp: client.query.app,
}),

View File

@@ -23,7 +23,7 @@ import pluginMessageQueue, {
queueMessages,
} from '../../reducers/pluginMessageQueue';
import {registerPlugins} from '../../reducers/plugins';
import {starPlugin} from '../../reducers/pluginManager';
import {switchPlugin} from '../../reducers/pluginManager';
interface PersistedState {
count: 1;
@@ -54,9 +54,9 @@ class TestPlugin extends FlipperPlugin<any, any, any> {
}
}
function starTestPlugin(store: Store, client: Client) {
function switchTestPlugin(store: Store, client: Client) {
store.dispatch(
starPlugin({
switchPlugin({
plugin: TestPlugin,
selectedApp: client.query.app,
}),
@@ -174,8 +174,8 @@ test('queue - events are NOT processed immediately if plugin is NOT selected (bu
[pluginKey]: [],
});
// unstar, but, messages still arrives because selected
starTestPlugin(store, client);
// disable, but, messages still arrives because selected
switchTestPlugin(store, client);
selectTestPlugin(store, client);
sendMessage('inc', {delta: 3});
client.flushMessageBuffer();
@@ -186,14 +186,14 @@ test('queue - events are NOT processed immediately if plugin is NOT selected (bu
},
});
// different plugin, and not starred, message will never arrive
// different plugin, and not enabled, message will never arrive
selectDeviceLogs(store);
sendMessage('inc', {delta: 4});
client.flushMessageBuffer();
expect(store.getState().pluginMessageQueue).toEqual({});
// star again, plugin still not selected, message is queued
starTestPlugin(store, client);
switchTestPlugin(store, client);
sendMessage('inc', {delta: 5});
client.flushMessageBuffer();
@@ -686,14 +686,14 @@ test('queue - messages that have not yet flushed be lost when disabling the plug
`);
// disable
starTestPlugin(store, client);
switchTestPlugin(store, client);
expect(client.messageBuffer).toMatchInlineSnapshot(`Object {}`);
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(
`Object {}`,
);
// re-enable, no messages arrive
starTestPlugin(store, client);
switchTestPlugin(store, client);
client.flushMessageBuffer();
processMessageQueue(TestPlugin, pluginKey, store);
expect(store.getState().pluginStates).toMatchInlineSnapshot(`Object {}`);

View File

@@ -25,7 +25,7 @@ import {
PluginClient,
_SandyPluginInstance,
} from 'flipper-plugin';
import {starPlugin} from '../../reducers/pluginManager';
import {switchPlugin} from '../../reducers/pluginManager';
type Events = {
inc: {
@@ -57,9 +57,9 @@ const TestPlugin = new _SandyPluginDefinition(
},
);
function starTestPlugin(store: Store, client: Client) {
function switchTestPlugin(store: Store, client: Client) {
store.dispatch(
starPlugin({
switchPlugin({
plugin: TestPlugin,
selectedApp: client.query.app,
}),
@@ -184,8 +184,8 @@ test('queue - events are NOT processed immediately if plugin is NOT selected (bu
[pluginKey]: [],
});
// unstar. Messages don't arrive anymore
starTestPlugin(store, client);
// disable. Messages don't arrive anymore
switchTestPlugin(store, client);
// weird state...
selectTestPlugin(store, client);
sendMessage('inc', {delta: 3});
@@ -193,7 +193,7 @@ test('queue - events are NOT processed immediately if plugin is NOT selected (bu
// active, immediately processed
expect(client.sandyPluginStates.has(TestPlugin.id)).toBe(false);
// different plugin, and not starred, message will never arrive
// different plugin, and not enabled, message will never arrive
selectDeviceLogs(store);
sendMessage('inc', {delta: 4});
client.flushMessageBuffer();
@@ -201,7 +201,7 @@ test('queue - events are NOT processed immediately if plugin is NOT selected (bu
expect(store.getState().pluginMessageQueue).toEqual({});
// star again, plugin still not selected, message is queued
starTestPlugin(store, client);
switchTestPlugin(store, client);
sendMessage('inc', {delta: 5});
client.flushMessageBuffer();
@@ -230,13 +230,12 @@ test('queue - events ARE processed immediately if plugin is NOT selected / enabl
selectDeviceLogs(store);
expect(store.getState().connections.selectedPlugin).toBe('DeviceLogs');
store.dispatch(
starPlugin({
switchPlugin({
plugin: NavigationPlugin,
selectedApp: client.query.app,
}),
);
expect(store.getState().connections.userStarredPlugins)
.toMatchInlineSnapshot(`
expect(store.getState().connections.enabledPlugins).toMatchInlineSnapshot(`
Object {
"TestApp": Array [],
}
@@ -728,14 +727,14 @@ test('queue - messages that have not yet flushed be lost when disabling the plug
`);
// disable
starTestPlugin(store, client);
switchTestPlugin(store, client);
expect(client.messageBuffer).toMatchInlineSnapshot(`Object {}`);
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(
`Object {}`,
);
// re-enable, no messages arrive
starTestPlugin(store, client);
switchTestPlugin(store, client);
client.flushMessageBuffer();
processMessageQueue(
client.sandyPluginStates.get(TestPlugin.id)!,

View File

@@ -802,7 +802,7 @@ export function importDataToStore(source: string, data: string, store: Store) {
});
archivedDevice.loadDevicePlugins(
store.getState().plugins.devicePlugins,
store.getState().connections.userStarredDevicePlugins,
store.getState().connections.enabledDevicePlugins,
deserializeObject(device.pluginStates),
);
store.dispatch({

View File

@@ -47,9 +47,7 @@ export function initializeFlipperLibImplementation(
if (
store
.getState()
.connections.userStarredPlugins[client.query.app]?.includes(
pluginId,
)
.connections.enabledPlugins[client.query.app]?.includes(pluginId)
) {
return true;
}

View File

@@ -21,7 +21,7 @@ import {
DEFAULT_MAX_QUEUE_SIZE,
} from '../reducers/pluginMessageQueue';
import {IdlerImpl} from './Idler';
import {pluginIsStarred, getSelectedPluginKey} from '../reducers/connections';
import {isPluginEnabled, getSelectedPluginKey} from '../reducers/connections';
import {deconstructPluginKey} from './clientUtils';
import {defaultEnabledBackgroundPlugins} from './pluginUtils';
import {batch, Idler, _SandyPluginInstance} from 'flipper-plugin';
@@ -133,9 +133,9 @@ export function processMessagesLater(
case plugin instanceof _SandyPluginInstance:
case plugin instanceof FlipperDevicePlugin:
case (plugin as any).prototype instanceof FlipperDevicePlugin:
case pluginIsStarred(
store.getState().connections.userStarredPlugins,
store.getState().connections.userStarredDevicePlugins,
case isPluginEnabled(
store.getState().connections.enabledPlugins,
store.getState().connections.enabledDevicePlugins,
deconstructPluginKey(pluginKey).client,
pluginId,
):

View File

@@ -83,8 +83,8 @@ export function getExportablePlugins(
undefined,
client,
state.plugins,
state.connections.userStarredPlugins,
state.connections.userStarredDevicePlugins,
state.connections.enabledPlugins,
state.connections.enabledDevicePlugins,
);
return [
@@ -179,8 +179,8 @@ export function computePluginLists(
metroDevice: BaseDevice | undefined,
client: Client | undefined,
plugins: State['plugins'],
userStarredPlugins: State['connections']['userStarredPlugins'],
userStarredDevicePlugins: Set<string>,
enabledPluginsState: State['connections']['enabledPlugins'],
enabledDevicePluginsState: Set<string>,
_pluginsChanged?: number, // this argument is purely used to invalidate the memoization cache
) {
const uninstalledMarketplacePlugins = filterNewestVersionOfEachPlugin(
@@ -191,12 +191,12 @@ export function computePluginLists(
...plugins.devicePlugins.values(),
]
.filter((p) => device?.supportsPlugin(p))
.filter((p) => userStarredDevicePlugins.has(p.id));
.filter((p) => enabledDevicePluginsState.has(p.id));
const metroPlugins: DevicePluginDefinition[] = [
...plugins.devicePlugins.values(),
]
.filter((p) => metroDevice?.supportsPlugin(p))
.filter((p) => userStarredDevicePlugins.has(p.id));
.filter((p) => enabledDevicePluginsState.has(p.id));
const enabledPlugins: ClientPluginDefinition[] = [];
const disabledPlugins: PluginDefinition[] = [
...plugins.devicePlugins.values(),
@@ -206,7 +206,7 @@ export function computePluginLists(
device?.supportsPlugin(p.details) ||
metroDevice?.supportsPlugin(p.details),
)
.filter((p) => !userStarredDevicePlugins.has(p.id));
.filter((p) => !enabledDevicePluginsState.has(p.id));
const unavailablePlugins: [plugin: PluginDetails, reason: string][] = [];
const downloadablePlugins: (
| DownloadablePluginDetails
@@ -263,7 +263,7 @@ export function computePluginLists(
device,
client,
clientPlugins,
client && userStarredPlugins[client.query.app],
client && enabledPluginsState[client.query.app],
true,
);
clientPlugins.forEach((plugin) => {
@@ -323,7 +323,7 @@ function getFavoritePlugins(
device: BaseDevice,
client: Client,
allPlugins: PluginDefinition[],
starredPlugins: undefined | string[],
enabledPlugins: undefined | string[],
returnFavoredPlugins: boolean, // if false, unfavoried plugins are returned
): PluginDefinition[] {
if (device.isArchived) {
@@ -335,11 +335,11 @@ function getFavoritePlugins(
(plugin) => client.plugins.indexOf(plugin.id) !== -1,
);
}
if (!starredPlugins || !starredPlugins.length) {
if (!enabledPlugins || !enabledPlugins.length) {
return returnFavoredPlugins ? [] : allPlugins;
}
return allPlugins.filter((plugin) => {
const idx = starredPlugins.indexOf(plugin.id);
const idx = enabledPlugins.indexOf(plugin.id);
return idx === -1 ? !returnFavoredPlugins : returnFavoredPlugins;
});
}

View File

@@ -31,7 +31,7 @@ const {version} = require('../package.json');
const dev = process.env.NODE_ENV !== 'production';
// For insiders builds we bundle top 5 popular device plugins,
// plus top 10 popular "universal" plugins starred by more than 100 users.
// plus top 10 popular "universal" plugins enabled by more than 100 users.
const hardcodedPlugins = new Set<string>([
// Popular device plugins
'DeviceLogs',