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:
committed by
Facebook GitHub Bot
parent
e9bab76614
commit
fa3ff83595
@@ -222,7 +222,7 @@ export default class Client extends EventEmitter {
|
|||||||
isEnabledPlugin(pluginId: string) {
|
isEnabledPlugin(pluginId: string) {
|
||||||
return this.store
|
return this.store
|
||||||
.getState()
|
.getState()
|
||||||
.connections.userStarredPlugins[this.query.app]?.includes(pluginId);
|
.connections.enabledPlugins[this.query.app]?.includes(pluginId);
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldConnectAsBackgroundPlugin(pluginId: string) {
|
shouldConnectAsBackgroundPlugin(pluginId: string) {
|
||||||
@@ -294,7 +294,7 @@ export default class Client extends EventEmitter {
|
|||||||
plugin: PluginDefinition | undefined,
|
plugin: PluginDefinition | undefined,
|
||||||
isEnabled = plugin ? this.isEnabledPlugin(plugin.id) : false,
|
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 (
|
if (
|
||||||
isSandyPlugin(plugin) &&
|
isSandyPlugin(plugin) &&
|
||||||
(isEnabled || defaultEnabledBackgroundPlugins.includes(plugin.id)) &&
|
(isEnabled || defaultEnabledBackgroundPlugins.includes(plugin.id)) &&
|
||||||
@@ -375,7 +375,7 @@ export default class Client extends EventEmitter {
|
|||||||
!newBackgroundPlugins.includes(plugin) &&
|
!newBackgroundPlugins.includes(plugin) &&
|
||||||
this.store
|
this.store
|
||||||
.getState()
|
.getState()
|
||||||
.connections.userStarredPlugins[this.query.app]?.includes(plugin)
|
.connections.enabledPlugins[this.query.app]?.includes(plugin)
|
||||||
) {
|
) {
|
||||||
this.deinitPlugin(plugin);
|
this.deinitPlugin(plugin);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ import {
|
|||||||
import {
|
import {
|
||||||
StaticView,
|
StaticView,
|
||||||
setStaticView,
|
setStaticView,
|
||||||
pluginIsStarred,
|
isPluginEnabled,
|
||||||
} from './reducers/connections';
|
} from './reducers/connections';
|
||||||
import {starPlugin} from './reducers/pluginManager';
|
import {switchPlugin} from './reducers/pluginManager';
|
||||||
import React, {PureComponent} from 'react';
|
import React, {PureComponent} from 'react';
|
||||||
import {connect, ReactReduxContext} from 'react-redux';
|
import {connect, ReactReduxContext} from 'react-redux';
|
||||||
import {setPluginState} from './reducers/pluginStates';
|
import {setPluginState} from './reducers/pluginStates';
|
||||||
@@ -127,7 +127,7 @@ type DispatchFromProps = {
|
|||||||
}) => any;
|
}) => any;
|
||||||
setPluginState: (payload: {pluginKey: string; state: any}) => void;
|
setPluginState: (payload: {pluginKey: string; state: any}) => void;
|
||||||
setStaticView: (payload: StaticView) => void;
|
setStaticView: (payload: StaticView) => void;
|
||||||
starPlugin: typeof starPlugin;
|
enablePlugin: typeof switchPlugin;
|
||||||
loadPlugin: typeof loadPlugin;
|
loadPlugin: typeof loadPlugin;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -315,7 +315,7 @@ class PluginContainer extends PureComponent<Props, State> {
|
|||||||
<ToggleButton
|
<ToggleButton
|
||||||
toggled={false}
|
toggled={false}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
this.props.starPlugin({
|
this.props.enablePlugin({
|
||||||
plugin: activePlugin,
|
plugin: activePlugin,
|
||||||
selectedApp: (this.props.target as Client)?.query?.app,
|
selectedApp: (this.props.target as Client)?.query?.app,
|
||||||
});
|
});
|
||||||
@@ -552,8 +552,8 @@ export default connect<StateFromProps, DispatchFromProps, OwnProps, Store>(
|
|||||||
selectedApp,
|
selectedApp,
|
||||||
clients,
|
clients,
|
||||||
deepLinkPayload,
|
deepLinkPayload,
|
||||||
userStarredPlugins,
|
enabledPlugins,
|
||||||
userStarredDevicePlugins,
|
enabledDevicePlugins,
|
||||||
},
|
},
|
||||||
pluginStates,
|
pluginStates,
|
||||||
plugins: {devicePlugins, clientPlugins, installedPlugins},
|
plugins: {devicePlugins, clientPlugins, installedPlugins},
|
||||||
@@ -580,9 +580,9 @@ export default connect<StateFromProps, DispatchFromProps, OwnProps, Store>(
|
|||||||
}
|
}
|
||||||
pluginIsEnabled =
|
pluginIsEnabled =
|
||||||
activePlugin !== undefined &&
|
activePlugin !== undefined &&
|
||||||
pluginIsStarred(
|
isPluginEnabled(
|
||||||
userStarredPlugins,
|
enabledPlugins,
|
||||||
userStarredDevicePlugins,
|
enabledDevicePlugins,
|
||||||
selectedApp,
|
selectedApp,
|
||||||
activePlugin.id,
|
activePlugin.id,
|
||||||
);
|
);
|
||||||
@@ -619,7 +619,7 @@ export default connect<StateFromProps, DispatchFromProps, OwnProps, Store>(
|
|||||||
setPluginState,
|
setPluginState,
|
||||||
selectPlugin,
|
selectPlugin,
|
||||||
setStaticView,
|
setStaticView,
|
||||||
starPlugin,
|
enablePlugin: switchPlugin,
|
||||||
loadPlugin: loadPlugin,
|
loadPlugin,
|
||||||
},
|
},
|
||||||
)(PluginContainer);
|
)(PluginContainer);
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import {
|
|||||||
} from 'flipper-plugin';
|
} from 'flipper-plugin';
|
||||||
import {selectPlugin} from '../reducers/connections';
|
import {selectPlugin} from '../reducers/connections';
|
||||||
import {updateSettings} from '../reducers/settings';
|
import {updateSettings} from '../reducers/settings';
|
||||||
import {starPlugin} from '../reducers/pluginManager';
|
import {switchPlugin} from '../reducers/pluginManager';
|
||||||
|
|
||||||
interface PersistedState {
|
interface PersistedState {
|
||||||
count: 1;
|
count: 1;
|
||||||
@@ -287,7 +287,7 @@ test('PluginContainer can render Sandy plugins', async () => {
|
|||||||
// disable
|
// disable
|
||||||
act(() => {
|
act(() => {
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
plugin: definition,
|
plugin: definition,
|
||||||
selectedApp: client.query.app,
|
selectedApp: client.query.app,
|
||||||
}),
|
}),
|
||||||
@@ -302,7 +302,7 @@ test('PluginContainer can render Sandy plugins', async () => {
|
|||||||
// re-enable
|
// re-enable
|
||||||
act(() => {
|
act(() => {
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
plugin: definition,
|
plugin: definition,
|
||||||
selectedApp: client.query.app,
|
selectedApp: client.query.app,
|
||||||
}),
|
}),
|
||||||
@@ -402,7 +402,7 @@ test('PluginContainer triggers correct lifecycles for background plugin', async
|
|||||||
// disable
|
// disable
|
||||||
act(() => {
|
act(() => {
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
plugin: definition,
|
plugin: definition,
|
||||||
selectedApp: client.query.app,
|
selectedApp: client.query.app,
|
||||||
}),
|
}),
|
||||||
@@ -427,7 +427,7 @@ test('PluginContainer triggers correct lifecycles for background plugin', async
|
|||||||
// re-enable
|
// re-enable
|
||||||
act(() => {
|
act(() => {
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
plugin: definition,
|
plugin: definition,
|
||||||
selectedApp: client.query.app,
|
selectedApp: client.query.app,
|
||||||
}),
|
}),
|
||||||
@@ -962,7 +962,7 @@ test('Sandy plugins support isPluginSupported + selectPlugin', async () => {
|
|||||||
expect(linksSeen).toEqual([]);
|
expect(linksSeen).toEqual([]);
|
||||||
|
|
||||||
// star and navigate to a device plugin
|
// star and navigate to a device plugin
|
||||||
store.dispatch(starPlugin({plugin: definition3}));
|
store.dispatch(switchPlugin({plugin: definition3}));
|
||||||
pluginInstance.selectPlugin(definition3.id);
|
pluginInstance.selectPlugin(definition3.id);
|
||||||
expect(pluginInstance.isPluginAvailable(definition3.id)).toBeTruthy();
|
expect(pluginInstance.isPluginAvailable(definition3.id)).toBeTruthy();
|
||||||
expect(store.getState().connections.selectedPlugin).toBe(definition3.id);
|
expect(store.getState().connections.selectedPlugin).toBe(definition3.id);
|
||||||
@@ -984,13 +984,13 @@ test('Sandy plugins support isPluginSupported + selectPlugin', async () => {
|
|||||||
`);
|
`);
|
||||||
expect(linksSeen).toEqual(['data']);
|
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);
|
pluginInstance.selectPlugin(definition2.id);
|
||||||
expect(store.getState().connections.selectedPlugin).toBe(definition.id);
|
expect(store.getState().connections.selectedPlugin).toBe(definition.id);
|
||||||
|
|
||||||
// star plugin 2 and navigate to plugin 2
|
// star plugin 2 and navigate to plugin 2
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
plugin: definition2,
|
plugin: definition2,
|
||||||
selectedApp: client.query.app,
|
selectedApp: client.query.app,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -24,6 +24,18 @@ Object {
|
|||||||
"title": "MockAndroidDevice",
|
"title": "MockAndroidDevice",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
"enabledDevicePlugins": Set {
|
||||||
|
"DeviceLogs",
|
||||||
|
"CrashReporter",
|
||||||
|
"MobileBuilds",
|
||||||
|
"Hermesdebuggerrn",
|
||||||
|
"React",
|
||||||
|
},
|
||||||
|
"enabledPlugins": Object {
|
||||||
|
"TestApp": Array [
|
||||||
|
"TestPlugin",
|
||||||
|
],
|
||||||
|
},
|
||||||
"selectedApp": "TestApp#Android#MockAndroidDevice#serial",
|
"selectedApp": "TestApp#Android#MockAndroidDevice#serial",
|
||||||
"selectedDevice": Object {
|
"selectedDevice": Object {
|
||||||
"deviceType": "physical",
|
"deviceType": "physical",
|
||||||
@@ -37,18 +49,6 @@ Object {
|
|||||||
"userPreferredApp": "TestApp#Android#MockAndroidDevice#serial",
|
"userPreferredApp": "TestApp#Android#MockAndroidDevice#serial",
|
||||||
"userPreferredDevice": "MockAndroidDevice",
|
"userPreferredDevice": "MockAndroidDevice",
|
||||||
"userPreferredPlugin": "TestPlugin",
|
"userPreferredPlugin": "TestPlugin",
|
||||||
"userStarredDevicePlugins": Set {
|
|
||||||
"DeviceLogs",
|
|
||||||
"CrashReporter",
|
|
||||||
"MobileBuilds",
|
|
||||||
"Hermesdebuggerrn",
|
|
||||||
"React",
|
|
||||||
},
|
|
||||||
"userStarredPlugins": Object {
|
|
||||||
"TestApp": Array [
|
|
||||||
"TestPlugin",
|
|
||||||
],
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ test('New device with same serial removes & cleans the old one', async () => {
|
|||||||
});
|
});
|
||||||
device2.loadDevicePlugins(
|
device2.loadDevicePlugins(
|
||||||
store.getState().plugins.devicePlugins,
|
store.getState().plugins.devicePlugins,
|
||||||
store.getState().connections.userStarredDevicePlugins,
|
store.getState().connections.enabledDevicePlugins,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(device.isArchived).toBe(false);
|
expect(device.isArchived).toBe(false);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ jest.mock('../plugins');
|
|||||||
jest.mock('../../utils/electronModuleCache');
|
jest.mock('../../utils/electronModuleCache');
|
||||||
import {
|
import {
|
||||||
loadPlugin,
|
loadPlugin,
|
||||||
starPlugin,
|
switchPlugin,
|
||||||
uninstallPlugin,
|
uninstallPlugin,
|
||||||
} from '../../reducers/pluginManager';
|
} from '../../reducers/pluginManager';
|
||||||
import {requirePlugin} from '../plugins';
|
import {requirePlugin} from '../plugins';
|
||||||
@@ -189,35 +189,35 @@ test('star plugin', async () => {
|
|||||||
loadPlugin({plugin: pluginDetails1, enable: false, notifyIfFailed: false}),
|
loadPlugin({plugin: pluginDetails1, enable: false, notifyIfFailed: false}),
|
||||||
);
|
);
|
||||||
mockFlipper.dispatch(
|
mockFlipper.dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
plugin: pluginDefinition1,
|
plugin: pluginDefinition1,
|
||||||
selectedApp: mockClient.query.app,
|
selectedApp: mockClient.query.app,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
mockFlipper.getState().connections.userStarredPlugins[mockClient.query.app],
|
mockFlipper.getState().connections.enabledPlugins[mockClient.query.app],
|
||||||
).toContain('plugin1');
|
).toContain('plugin1');
|
||||||
expect(mockClient.sandyPluginStates.has('plugin1')).toBeTruthy();
|
expect(mockClient.sandyPluginStates.has('plugin1')).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('unstar plugin', async () => {
|
test('disable plugin', async () => {
|
||||||
mockFlipper.dispatch(
|
mockFlipper.dispatch(
|
||||||
loadPlugin({plugin: pluginDetails1, enable: false, notifyIfFailed: false}),
|
loadPlugin({plugin: pluginDetails1, enable: false, notifyIfFailed: false}),
|
||||||
);
|
);
|
||||||
mockFlipper.dispatch(
|
mockFlipper.dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
plugin: pluginDefinition1,
|
plugin: pluginDefinition1,
|
||||||
selectedApp: mockClient.query.app,
|
selectedApp: mockClient.query.app,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
mockFlipper.dispatch(
|
mockFlipper.dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
plugin: pluginDefinition1,
|
plugin: pluginDefinition1,
|
||||||
selectedApp: mockClient.query.app,
|
selectedApp: mockClient.query.app,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
mockFlipper.getState().connections.userStarredPlugins[mockClient.query.app],
|
mockFlipper.getState().connections.enabledPlugins[mockClient.query.app],
|
||||||
).not.toContain('plugin1');
|
).not.toContain('plugin1');
|
||||||
expect(mockClient.sandyPluginStates.has('plugin1')).toBeFalsy();
|
expect(mockClient.sandyPluginStates.has('plugin1')).toBeFalsy();
|
||||||
});
|
});
|
||||||
@@ -231,17 +231,17 @@ test('star device plugin', async () => {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
mockFlipper.dispatch(
|
mockFlipper.dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
plugin: devicePluginDefinition,
|
plugin: devicePluginDefinition,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
mockFlipper.getState().connections.userStarredDevicePlugins.has('device'),
|
mockFlipper.getState().connections.enabledDevicePlugins.has('device'),
|
||||||
).toBeTruthy();
|
).toBeTruthy();
|
||||||
expect(mockDevice.sandyPluginStates.has('device')).toBeTruthy();
|
expect(mockDevice.sandyPluginStates.has('device')).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('unstar device plugin', async () => {
|
test('disable device plugin', async () => {
|
||||||
mockFlipper.dispatch(
|
mockFlipper.dispatch(
|
||||||
loadPlugin({
|
loadPlugin({
|
||||||
plugin: devicePluginDetails,
|
plugin: devicePluginDetails,
|
||||||
@@ -250,17 +250,17 @@ test('unstar device plugin', async () => {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
mockFlipper.dispatch(
|
mockFlipper.dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
plugin: devicePluginDefinition,
|
plugin: devicePluginDefinition,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
mockFlipper.dispatch(
|
mockFlipper.dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
plugin: devicePluginDefinition,
|
plugin: devicePluginDefinition,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
mockFlipper.getState().connections.userStarredDevicePlugins.has('device'),
|
mockFlipper.getState().connections.enabledDevicePlugins.has('device'),
|
||||||
).toBeFalsy();
|
).toBeFalsy();
|
||||||
expect(mockDevice.sandyPluginStates.has('device')).toBeFalsy();
|
expect(mockDevice.sandyPluginStates.has('device')).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ export default (store: Store, logger: Logger) => {
|
|||||||
|
|
||||||
androidDevice.loadDevicePlugins(
|
androidDevice.loadDevicePlugins(
|
||||||
store.getState().plugins.devicePlugins,
|
store.getState().plugins.devicePlugins,
|
||||||
store.getState().connections.userStarredDevicePlugins,
|
store.getState().connections.enabledDevicePlugins,
|
||||||
);
|
);
|
||||||
store.dispatch({
|
store.dispatch({
|
||||||
type: 'REGISTER_DEVICE',
|
type: 'REGISTER_DEVICE',
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export default (store: Store, _logger: Logger) => {
|
|||||||
}
|
}
|
||||||
device.loadDevicePlugins(
|
device.loadDevicePlugins(
|
||||||
store.getState().plugins.devicePlugins,
|
store.getState().plugins.devicePlugins,
|
||||||
store.getState().connections.userStarredDevicePlugins,
|
store.getState().connections.enabledDevicePlugins,
|
||||||
);
|
);
|
||||||
store.dispatch({
|
store.dispatch({
|
||||||
type: 'REGISTER_DEVICE',
|
type: 'REGISTER_DEVICE',
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ function processDevices(
|
|||||||
const iOSDevice = new IOSDevice(udid, type, name);
|
const iOSDevice = new IOSDevice(udid, type, name);
|
||||||
iOSDevice.loadDevicePlugins(
|
iOSDevice.loadDevicePlugins(
|
||||||
store.getState().plugins.devicePlugins,
|
store.getState().plugins.devicePlugins,
|
||||||
store.getState().connections.userStarredDevicePlugins,
|
store.getState().connections.enabledDevicePlugins,
|
||||||
);
|
);
|
||||||
store.dispatch({
|
store.dispatch({
|
||||||
type: 'REGISTER_DEVICE',
|
type: 'REGISTER_DEVICE',
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ export async function registerMetroDevice(
|
|||||||
|
|
||||||
metroDevice.loadDevicePlugins(
|
metroDevice.loadDevicePlugins(
|
||||||
store.getState().plugins.devicePlugins,
|
store.getState().plugins.devicePlugins,
|
||||||
store.getState().connections.userStarredDevicePlugins,
|
store.getState().connections.enabledDevicePlugins,
|
||||||
);
|
);
|
||||||
store.dispatch({
|
store.dispatch({
|
||||||
type: 'REGISTER_DEVICE',
|
type: 'REGISTER_DEVICE',
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ function pluginIsDisabledForAllConnectedClients(
|
|||||||
return (
|
return (
|
||||||
!state.plugins.clientPlugins.has(plugin.id) ||
|
!state.plugins.clientPlugins.has(plugin.id) ||
|
||||||
!state.connections.clients.some((c) =>
|
!state.connections.clients.some((c) =>
|
||||||
state.connections.userStarredPlugins[c.query.app]?.includes(plugin.id),
|
state.connections.enabledPlugins[c.query.app]?.includes(plugin.id),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
UninstallPluginActionPayload,
|
UninstallPluginActionPayload,
|
||||||
UpdatePluginActionPayload,
|
UpdatePluginActionPayload,
|
||||||
pluginCommandsProcessed,
|
pluginCommandsProcessed,
|
||||||
StarPluginActionPayload,
|
SwitchPluginActionPayload,
|
||||||
PluginCommand,
|
PluginCommand,
|
||||||
} from '../reducers/pluginManager';
|
} from '../reducers/pluginManager';
|
||||||
import {
|
import {
|
||||||
@@ -42,10 +42,10 @@ import {
|
|||||||
} from '../reducers/plugins';
|
} from '../reducers/plugins';
|
||||||
import {_SandyPluginDefinition} from 'flipper-plugin';
|
import {_SandyPluginDefinition} from 'flipper-plugin';
|
||||||
import {
|
import {
|
||||||
devicePluginStarred,
|
setDevicePluginEnabled,
|
||||||
devicePluginUnstarred,
|
setDevicePluginDisabled,
|
||||||
pluginStarred,
|
setPluginEnabled,
|
||||||
pluginUnstarred,
|
setPluginDisabled,
|
||||||
} from '../reducers/connections';
|
} from '../reducers/connections';
|
||||||
import {deconstructClientId} from '../utils/clientUtils';
|
import {deconstructClientId} from '../utils/clientUtils';
|
||||||
import {clearMessageQueue} from '../reducers/pluginMessageQueue';
|
import {clearMessageQueue} from '../reducers/pluginMessageQueue';
|
||||||
@@ -112,8 +112,8 @@ export function processPluginCommandsQueue(
|
|||||||
case 'UPDATE_PLUGIN':
|
case 'UPDATE_PLUGIN':
|
||||||
updatePlugin(store, command.payload);
|
updatePlugin(store, command.payload);
|
||||||
break;
|
break;
|
||||||
case 'STAR_PLUGIN':
|
case 'SWITCH_PLUGIN':
|
||||||
starPlugin(store, command.payload);
|
switchPlugin(store, command.payload);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.error('Unexpected plugin command', command);
|
console.error('Unexpected plugin command', command);
|
||||||
@@ -181,18 +181,18 @@ function getSelectedAppId(store: Store) {
|
|||||||
return selectedApp;
|
return selectedApp;
|
||||||
}
|
}
|
||||||
|
|
||||||
function starPlugin(
|
function switchPlugin(
|
||||||
store: Store,
|
store: Store,
|
||||||
{plugin, selectedApp}: StarPluginActionPayload,
|
{plugin, selectedApp}: SwitchPluginActionPayload,
|
||||||
) {
|
) {
|
||||||
if (isDevicePluginDefinition(plugin)) {
|
if (isDevicePluginDefinition(plugin)) {
|
||||||
starDevicePlugin(store, plugin);
|
switchDevicePlugin(store, plugin);
|
||||||
} else {
|
} else {
|
||||||
starClientPlugin(store, plugin, selectedApp);
|
switchClientPlugin(store, plugin, selectedApp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function starClientPlugin(
|
function switchClientPlugin(
|
||||||
store: Store,
|
store: Store,
|
||||||
plugin: ClientPluginDefinition,
|
plugin: ClientPluginDefinition,
|
||||||
selectedApp: string | undefined,
|
selectedApp: string | undefined,
|
||||||
@@ -205,7 +205,7 @@ function starClientPlugin(
|
|||||||
const clients = connections.clients.filter(
|
const clients = connections.clients.filter(
|
||||||
(client) => client.query.app === selectedApp,
|
(client) => client.query.app === selectedApp,
|
||||||
);
|
);
|
||||||
if (connections.userStarredPlugins[selectedApp]?.includes(plugin.id)) {
|
if (connections.enabledPlugins[selectedApp]?.includes(plugin.id)) {
|
||||||
clients.forEach((client) => {
|
clients.forEach((client) => {
|
||||||
stopPlugin(client, plugin.id);
|
stopPlugin(client, plugin.id);
|
||||||
const pluginKey = getPluginKey(
|
const pluginKey = getPluginKey(
|
||||||
@@ -215,30 +215,30 @@ function starClientPlugin(
|
|||||||
);
|
);
|
||||||
store.dispatch(clearMessageQueue(pluginKey));
|
store.dispatch(clearMessageQueue(pluginKey));
|
||||||
});
|
});
|
||||||
store.dispatch(pluginUnstarred(plugin.id, selectedApp));
|
store.dispatch(setPluginDisabled(plugin.id, selectedApp));
|
||||||
} else {
|
} else {
|
||||||
clients.forEach((client) => {
|
clients.forEach((client) => {
|
||||||
startPlugin(client, plugin);
|
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 {connections} = store.getState();
|
||||||
const devicesWithPlugin = connections.devices.filter((d) =>
|
const devicesWithPlugin = connections.devices.filter((d) =>
|
||||||
d.supportsPlugin(plugin.details),
|
d.supportsPlugin(plugin.details),
|
||||||
);
|
);
|
||||||
if (connections.userStarredDevicePlugins.has(plugin.id)) {
|
if (connections.enabledDevicePlugins.has(plugin.id)) {
|
||||||
devicesWithPlugin.forEach((d) => {
|
devicesWithPlugin.forEach((d) => {
|
||||||
d.unloadDevicePlugin(plugin.id);
|
d.unloadDevicePlugin(plugin.id);
|
||||||
});
|
});
|
||||||
store.dispatch(devicePluginUnstarred(plugin.id));
|
store.dispatch(setDevicePluginDisabled(plugin.id));
|
||||||
} else {
|
} else {
|
||||||
devicesWithPlugin.forEach((d) => {
|
devicesWithPlugin.forEach((d) => {
|
||||||
d.loadDevicePlugin(plugin);
|
d.loadDevicePlugin(plugin);
|
||||||
});
|
});
|
||||||
store.dispatch(devicePluginStarred(plugin.id));
|
store.dispatch(setDevicePluginEnabled(plugin.id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,7 +251,7 @@ function updateClientPlugin(
|
|||||||
if (enable) {
|
if (enable) {
|
||||||
const selectedApp = getSelectedAppId(store);
|
const selectedApp = getSelectedAppId(store);
|
||||||
if (selectedApp) {
|
if (selectedApp) {
|
||||||
store.dispatch(pluginStarred(plugin.id, selectedApp));
|
store.dispatch(setPluginEnabled(plugin.id, selectedApp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const clientsWithEnabledPlugin = clients.filter((c) => {
|
const clientsWithEnabledPlugin = clients.filter((c) => {
|
||||||
@@ -259,7 +259,7 @@ function updateClientPlugin(
|
|||||||
c.supportsPlugin(plugin.id) &&
|
c.supportsPlugin(plugin.id) &&
|
||||||
store
|
store
|
||||||
.getState()
|
.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);
|
const previousVersion = store.getState().plugins.clientPlugins.get(plugin.id);
|
||||||
@@ -283,7 +283,7 @@ function updateDevicePlugin(
|
|||||||
enable: boolean,
|
enable: boolean,
|
||||||
) {
|
) {
|
||||||
if (enable) {
|
if (enable) {
|
||||||
store.dispatch(devicePluginStarred(plugin.id));
|
store.dispatch(setDevicePluginEnabled(plugin.id));
|
||||||
}
|
}
|
||||||
const connections = store.getState().connections;
|
const connections = store.getState().connections;
|
||||||
const devicesWithEnabledPlugin = connections.devices.filter((d) =>
|
const devicesWithEnabledPlugin = connections.devices.filter((d) =>
|
||||||
|
|||||||
@@ -145,12 +145,18 @@ export default (store: Store, logger: Logger) => {
|
|||||||
logger.track('usage', TIME_SPENT_EVENT, usageSummary[key], key);
|
logger.track('usage', TIME_SPENT_EVENT, usageSummary[key], key);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.entries(state.connections.userStarredPlugins).forEach(
|
Object.entries(state.connections.enabledPlugins).forEach(
|
||||||
([app, plugins]) =>
|
([app, plugins]) => {
|
||||||
|
// TODO: remove "starred-plugns" event in favor of "enabled-plugins" after some transition period
|
||||||
logger.track('usage', 'starred-plugins', {
|
logger.track('usage', 'starred-plugins', {
|
||||||
app: app,
|
app,
|
||||||
starredPlugins: plugins,
|
starredPlugins: plugins,
|
||||||
}),
|
});
|
||||||
|
logger.track('usage', 'enabled-plugins', {
|
||||||
|
app,
|
||||||
|
enabledPugins: plugins,
|
||||||
|
});
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const bgStats = getPluginBackgroundStats();
|
const bgStats = getPluginBackgroundStats();
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import {
|
|||||||
PluginClient,
|
PluginClient,
|
||||||
TestUtils,
|
TestUtils,
|
||||||
} from 'flipper-plugin';
|
} from 'flipper-plugin';
|
||||||
import {starPlugin} from '../pluginManager';
|
import {switchPlugin} from '../pluginManager';
|
||||||
|
|
||||||
const pluginDetails = TestUtils.createMockPluginDetails();
|
const pluginDetails = TestUtils.createMockPluginDetails();
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ type PluginApi = ReturnType<typeof plugin>;
|
|||||||
|
|
||||||
function starTestPlugin(store: Store, client: Client) {
|
function starTestPlugin(store: Store, client: Client) {
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
plugin: TestPlugin,
|
plugin: TestPlugin,
|
||||||
selectedApp: client.query.app,
|
selectedApp: client.query.app,
|
||||||
}),
|
}),
|
||||||
@@ -110,7 +110,7 @@ test('it should cleanup a plugin if disabled', async () => {
|
|||||||
client.initPlugin(TestPlugin.id);
|
client.initPlugin(TestPlugin.id);
|
||||||
expect(pluginInstance.connectStub).toHaveBeenCalledTimes(1);
|
expect(pluginInstance.connectStub).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
// unstar
|
// disable
|
||||||
starTestPlugin(store, client);
|
starTestPlugin(store, client);
|
||||||
expect(client.sandyPluginStates.has(TestPlugin.id)).toBeFalsy();
|
expect(client.sandyPluginStates.has(TestPlugin.id)).toBeFalsy();
|
||||||
expect(pluginInstance.disconnectStub).toHaveBeenCalledTimes(1);
|
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);
|
expect(Plugin2.asPluginModule().plugin).toBeCalledTimes(0);
|
||||||
|
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
plugin: Plugin2,
|
plugin: Plugin2,
|
||||||
selectedApp: client.query.app,
|
selectedApp: client.query.app,
|
||||||
}),
|
}),
|
||||||
@@ -193,7 +193,7 @@ test('it should not initialize a sandy plugin if not enabled', async () => {
|
|||||||
|
|
||||||
// disable plugin again
|
// disable plugin again
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
plugin: Plugin2,
|
plugin: Plugin2,
|
||||||
selectedApp: client.query.app,
|
selectedApp: client.query.app,
|
||||||
}),
|
}),
|
||||||
@@ -278,7 +278,7 @@ test('it should initialize "Navigation" plugin if not enabled', async () => {
|
|||||||
expect(Plugin2.asPluginModule().plugin).toBeCalledTimes(1);
|
expect(Plugin2.asPluginModule().plugin).toBeCalledTimes(1);
|
||||||
|
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
plugin: Plugin2,
|
plugin: Plugin2,
|
||||||
selectedApp: client.query.app,
|
selectedApp: client.query.app,
|
||||||
}),
|
}),
|
||||||
@@ -292,7 +292,7 @@ test('it should initialize "Navigation" plugin if not enabled', async () => {
|
|||||||
|
|
||||||
// disable plugin again
|
// disable plugin again
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
plugin: Plugin2,
|
plugin: Plugin2,
|
||||||
selectedApp: client.query.app,
|
selectedApp: client.query.app,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -31,7 +31,22 @@ export type StaticView =
|
|||||||
| ComponentType<StaticViewProps>
|
| ComponentType<StaticViewProps>
|
||||||
| React.FunctionComponent<any>;
|
| 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>;
|
devices: Array<BaseDevice>;
|
||||||
androidEmulators: Array<string>;
|
androidEmulators: Array<string>;
|
||||||
selectedDevice: null | BaseDevice;
|
selectedDevice: null | BaseDevice;
|
||||||
@@ -40,8 +55,8 @@ export type State = {
|
|||||||
userPreferredDevice: null | string;
|
userPreferredDevice: null | string;
|
||||||
userPreferredPlugin: null | string;
|
userPreferredPlugin: null | string;
|
||||||
userPreferredApp: null | string;
|
userPreferredApp: null | string;
|
||||||
userStarredPlugins: {[client: string]: string[]};
|
enabledPlugins: {[client: string]: string[]};
|
||||||
userStarredDevicePlugins: Set<string>;
|
enabledDevicePlugins: Set<string>;
|
||||||
clients: Array<Client>;
|
clients: Array<Client>;
|
||||||
uninitializedClients: Array<{
|
uninitializedClients: Array<{
|
||||||
client: UninitializedClient;
|
client: UninitializedClient;
|
||||||
@@ -52,6 +67,11 @@ export type State = {
|
|||||||
staticView: StaticView;
|
staticView: StaticView;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type StateV0 = Omit<StateV1, 'enabledPlugins' | 'enabledDevicePlugins'> & {
|
||||||
|
userStarredPlugins: {[client: string]: string[]};
|
||||||
|
userStarredDevicePlugins: Set<string>;
|
||||||
|
};
|
||||||
|
|
||||||
export type Action =
|
export type Action =
|
||||||
| {
|
| {
|
||||||
type: 'UNREGISTER_DEVICES';
|
type: 'UNREGISTER_DEVICES';
|
||||||
@@ -109,27 +129,27 @@ export type Action =
|
|||||||
deepLinkPayload: unknown;
|
deepLinkPayload: unknown;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
type: 'PLUGIN_STARRED';
|
type: 'SET_PLUGIN_ENABLED';
|
||||||
payload: {
|
payload: {
|
||||||
pluginId: string;
|
pluginId: string;
|
||||||
selectedApp: string;
|
selectedApp: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
type: 'DEVICE_PLUGIN_STARRED';
|
type: 'SET_DEVICE_PLUGIN_ENABLED';
|
||||||
payload: {
|
payload: {
|
||||||
pluginId: string;
|
pluginId: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
type: 'PLUGIN_UNSTARRED';
|
type: 'SET_PLUGIN_DISABLED';
|
||||||
payload: {
|
payload: {
|
||||||
pluginId: string;
|
pluginId: string;
|
||||||
selectedApp: string;
|
selectedApp: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
type: 'DEVICE_PLUGIN_UNSTARRED';
|
type: 'SET_DEVICE_PLUGIN_DISABLED';
|
||||||
payload: {
|
payload: {
|
||||||
pluginId: string;
|
pluginId: string;
|
||||||
};
|
};
|
||||||
@@ -151,8 +171,8 @@ const INITAL_STATE: State = {
|
|||||||
userPreferredDevice: null,
|
userPreferredDevice: null,
|
||||||
userPreferredPlugin: null,
|
userPreferredPlugin: null,
|
||||||
userPreferredApp: null,
|
userPreferredApp: null,
|
||||||
userStarredPlugins: {},
|
enabledPlugins: {},
|
||||||
userStarredDevicePlugins: new Set([
|
enabledDevicePlugins: new Set([
|
||||||
'DeviceLogs',
|
'DeviceLogs',
|
||||||
'CrashReporter',
|
'CrashReporter',
|
||||||
'MobileBuilds',
|
'MobileBuilds',
|
||||||
@@ -384,42 +404,42 @@ export default (state: State = INITAL_STATE, action: Actions): State => {
|
|||||||
});
|
});
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
case 'PLUGIN_STARRED': {
|
case 'SET_PLUGIN_ENABLED': {
|
||||||
const {pluginId, selectedApp} = action.payload;
|
const {pluginId, selectedApp} = action.payload;
|
||||||
return produce(state, (draft) => {
|
return produce(state, (draft) => {
|
||||||
if (!draft.userStarredPlugins[selectedApp]) {
|
if (!draft.enabledPlugins[selectedApp]) {
|
||||||
draft.userStarredPlugins[selectedApp] = [];
|
draft.enabledPlugins[selectedApp] = [];
|
||||||
}
|
}
|
||||||
const plugins = draft.userStarredPlugins[selectedApp];
|
const plugins = draft.enabledPlugins[selectedApp];
|
||||||
const idx = plugins.indexOf(pluginId);
|
const idx = plugins.indexOf(pluginId);
|
||||||
if (idx === -1) {
|
if (idx === -1) {
|
||||||
plugins.push(pluginId);
|
plugins.push(pluginId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
case 'DEVICE_PLUGIN_STARRED': {
|
case 'SET_DEVICE_PLUGIN_ENABLED': {
|
||||||
const {pluginId} = action.payload;
|
const {pluginId} = action.payload;
|
||||||
return produce(state, (draft) => {
|
return produce(state, (draft) => {
|
||||||
draft.userStarredDevicePlugins.add(pluginId);
|
draft.enabledDevicePlugins.add(pluginId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
case 'PLUGIN_UNSTARRED': {
|
case 'SET_PLUGIN_DISABLED': {
|
||||||
const {pluginId, selectedApp} = action.payload;
|
const {pluginId, selectedApp} = action.payload;
|
||||||
return produce(state, (draft) => {
|
return produce(state, (draft) => {
|
||||||
if (!draft.userStarredPlugins[selectedApp]) {
|
if (!draft.enabledPlugins[selectedApp]) {
|
||||||
draft.userStarredPlugins[selectedApp] = [];
|
draft.enabledPlugins[selectedApp] = [];
|
||||||
}
|
}
|
||||||
const plugins = draft.userStarredPlugins[selectedApp];
|
const plugins = draft.enabledPlugins[selectedApp];
|
||||||
const idx = plugins.indexOf(pluginId);
|
const idx = plugins.indexOf(pluginId);
|
||||||
if (idx !== -1) {
|
if (idx !== -1) {
|
||||||
plugins.splice(idx, 1);
|
plugins.splice(idx, 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
case 'DEVICE_PLUGIN_UNSTARRED': {
|
case 'SET_DEVICE_PLUGIN_DISABLED': {
|
||||||
const {pluginId} = action.payload;
|
const {pluginId} = action.payload;
|
||||||
return produce(state, (draft) => {
|
return produce(state, (draft) => {
|
||||||
draft.userStarredDevicePlugins.delete(pluginId);
|
draft.enabledDevicePlugins.delete(pluginId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -467,30 +487,30 @@ export const selectClient = (clientId: string | null): Action => ({
|
|||||||
payload: clientId,
|
payload: clientId,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const pluginStarred = (pluginId: string, appId: string): Action => ({
|
export const setPluginEnabled = (pluginId: string, appId: string): Action => ({
|
||||||
type: 'PLUGIN_STARRED',
|
type: 'SET_PLUGIN_ENABLED',
|
||||||
payload: {
|
payload: {
|
||||||
pluginId,
|
pluginId,
|
||||||
selectedApp: appId,
|
selectedApp: appId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const devicePluginStarred = (pluginId: string): Action => ({
|
export const setDevicePluginEnabled = (pluginId: string): Action => ({
|
||||||
type: 'DEVICE_PLUGIN_STARRED',
|
type: 'SET_DEVICE_PLUGIN_ENABLED',
|
||||||
payload: {
|
payload: {
|
||||||
pluginId,
|
pluginId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const devicePluginUnstarred = (pluginId: string): Action => ({
|
export const setDevicePluginDisabled = (pluginId: string): Action => ({
|
||||||
type: 'DEVICE_PLUGIN_UNSTARRED',
|
type: 'SET_DEVICE_PLUGIN_DISABLED',
|
||||||
payload: {
|
payload: {
|
||||||
pluginId,
|
pluginId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const pluginUnstarred = (pluginId: string, appId: string): Action => ({
|
export const setPluginDisabled = (pluginId: string, appId: string): Action => ({
|
||||||
type: 'PLUGIN_UNSTARRED',
|
type: 'SET_PLUGIN_DISABLED',
|
||||||
payload: {
|
payload: {
|
||||||
pluginId,
|
pluginId,
|
||||||
selectedApp: appId,
|
selectedApp: appId,
|
||||||
@@ -618,19 +638,19 @@ export function getSelectedPluginKey(state: State): string | undefined {
|
|||||||
: undefined;
|
: undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function pluginIsStarred(
|
export function isPluginEnabled(
|
||||||
userStarredPlugins: State['userStarredPlugins'],
|
enabledPlugins: State['enabledPlugins'],
|
||||||
userStarredDevicePlugins: State['userStarredDevicePlugins'],
|
enabledDevicePlugins: State['enabledDevicePlugins'],
|
||||||
app: string | null,
|
app: string | null,
|
||||||
pluginId: string,
|
pluginId: string,
|
||||||
): boolean {
|
): boolean {
|
||||||
if (userStarredDevicePlugins.has(pluginId)) {
|
if (enabledDevicePlugins.has(pluginId)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!app) {
|
if (!app) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const appInfo = deconstructClientId(app);
|
const appInfo = deconstructClientId(app);
|
||||||
const starred = userStarredPlugins[appInfo.app];
|
const starred = enabledPlugins[appInfo.app];
|
||||||
return starred && starred.indexOf(pluginId) > -1;
|
return starred && starred.indexOf(pluginId) > -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import application, {
|
|||||||
import connections, {
|
import connections, {
|
||||||
State as DevicesState,
|
State as DevicesState,
|
||||||
Action as DevicesAction,
|
Action as DevicesAction,
|
||||||
|
persistMigrations as devicesPersistMigrations,
|
||||||
|
persistVersion as devicesPersistVersion,
|
||||||
} from './connections';
|
} from './connections';
|
||||||
import pluginStates, {
|
import pluginStates, {
|
||||||
State as PluginStatesState,
|
State as PluginStatesState,
|
||||||
@@ -67,7 +69,7 @@ import {launcherConfigDir} from '../utils/launcher';
|
|||||||
import os from 'os';
|
import os from 'os';
|
||||||
import {resolve} from 'path';
|
import {resolve} from 'path';
|
||||||
import xdg from 'xdg-basedir';
|
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 {PersistPartial} from 'redux-persist/es/persistReducer';
|
||||||
|
|
||||||
import {Store as ReduxStore, MiddlewareAPI as ReduxMiddlewareAPI} from 'redux';
|
import {Store as ReduxStore, MiddlewareAPI as ReduxMiddlewareAPI} from 'redux';
|
||||||
@@ -140,10 +142,16 @@ export default combineReducers<State, Actions>({
|
|||||||
'userPreferredDevice',
|
'userPreferredDevice',
|
||||||
'userPreferredPlugin',
|
'userPreferredPlugin',
|
||||||
'userPreferredApp',
|
'userPreferredApp',
|
||||||
'userStarredPlugins',
|
'enabledPlugins',
|
||||||
'userStarredDevicePlugins',
|
'enabledDevicePlugins',
|
||||||
],
|
],
|
||||||
transforms: [setTransformer({whitelist: ['userStarredDevicePlugins']})],
|
transforms: [
|
||||||
|
setTransformer({
|
||||||
|
whitelist: ['enabledDevicePlugins', 'userStarredDevicePlugins'],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
version: devicesPersistVersion,
|
||||||
|
migrate: createMigrate(devicesPersistMigrations),
|
||||||
},
|
},
|
||||||
connections,
|
connections,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export type PluginCommand =
|
|||||||
| LoadPluginAction
|
| LoadPluginAction
|
||||||
| UninstallPluginAction
|
| UninstallPluginAction
|
||||||
| UpdatePluginAction
|
| UpdatePluginAction
|
||||||
| StarPluginAction;
|
| SwitchPluginAction;
|
||||||
|
|
||||||
export type LoadPluginActionPayload = {
|
export type LoadPluginActionPayload = {
|
||||||
plugin: ActivatablePluginDetails;
|
plugin: ActivatablePluginDetails;
|
||||||
@@ -52,14 +52,14 @@ export type UpdatePluginAction = {
|
|||||||
payload: UpdatePluginActionPayload;
|
payload: UpdatePluginActionPayload;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type StarPluginActionPayload = {
|
export type SwitchPluginActionPayload = {
|
||||||
plugin: PluginDefinition;
|
plugin: PluginDefinition;
|
||||||
selectedApp?: string;
|
selectedApp?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type StarPluginAction = {
|
export type SwitchPluginAction = {
|
||||||
type: 'STAR_PLUGIN';
|
type: 'SWITCH_PLUGIN';
|
||||||
payload: StarPluginActionPayload;
|
payload: SwitchPluginActionPayload;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Action =
|
export type Action =
|
||||||
@@ -81,7 +81,7 @@ export default function reducer(
|
|||||||
case 'LOAD_PLUGIN':
|
case 'LOAD_PLUGIN':
|
||||||
case 'UNINSTALL_PLUGIN':
|
case 'UNINSTALL_PLUGIN':
|
||||||
case 'UPDATE_PLUGIN':
|
case 'UPDATE_PLUGIN':
|
||||||
case 'STAR_PLUGIN':
|
case 'SWITCH_PLUGIN':
|
||||||
return produce(state, (draft) => {
|
return produce(state, (draft) => {
|
||||||
draft.pluginCommandsQueue.push(action);
|
draft.pluginCommandsQueue.push(action);
|
||||||
});
|
});
|
||||||
@@ -118,7 +118,7 @@ export const registerPluginUpdate = (
|
|||||||
payload,
|
payload,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const starPlugin = (payload: StarPluginActionPayload): Action => ({
|
export const switchPlugin = (payload: SwitchPluginActionPayload): Action => ({
|
||||||
type: 'STAR_PLUGIN',
|
type: 'SWITCH_PLUGIN',
|
||||||
payload,
|
payload,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
import {Actions, Store} from './';
|
import {Actions, Store} from './';
|
||||||
import {setStaticView} from './connections';
|
import {setStaticView} from './connections';
|
||||||
import {deconstructClientId} from '../utils/clientUtils';
|
import {deconstructClientId} from '../utils/clientUtils';
|
||||||
import {starPlugin as setStarPlugin} from './pluginManager';
|
import {switchPlugin} from './pluginManager';
|
||||||
import {showStatusUpdatesForDuration} from '../utils/promiseTimeout';
|
import {showStatusUpdatesForDuration} from '../utils/promiseTimeout';
|
||||||
import {selectedPlugins as setSelectedPlugins} from './plugins';
|
import {selectedPlugins as setSelectedPlugins} from './plugins';
|
||||||
import {addStatusMessage, removeStatusMessage} from './application';
|
import {addStatusMessage, removeStatusMessage} from './application';
|
||||||
@@ -125,7 +125,7 @@ export class Group {
|
|||||||
if (selectedApp) {
|
if (selectedApp) {
|
||||||
const {app} = deconstructClientId(selectedApp);
|
const {app} = deconstructClientId(selectedApp);
|
||||||
const enabledPlugins: Array<string> | null = store.getState().connections
|
const enabledPlugins: Array<string> | null = store.getState().connections
|
||||||
.userStarredPlugins[app];
|
.enabledPlugins[app];
|
||||||
const unsupportedPlugins = [];
|
const unsupportedPlugins = [];
|
||||||
for (const requiredPlugin of this.requiredPlugins) {
|
for (const requiredPlugin of this.requiredPlugins) {
|
||||||
const requiredPluginEnabled =
|
const requiredPluginEnabled =
|
||||||
@@ -139,7 +139,7 @@ export class Group {
|
|||||||
store.getState().plugins.clientPlugins.get(requiredPlugin) ||
|
store.getState().plugins.clientPlugins.get(requiredPlugin) ||
|
||||||
store.getState().plugins.devicePlugins.get(requiredPlugin)!;
|
store.getState().plugins.devicePlugins.get(requiredPlugin)!;
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
setStarPlugin({
|
switchPlugin({
|
||||||
selectedApp: app,
|
selectedApp: app,
|
||||||
plugin,
|
plugin,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ import {
|
|||||||
} from '../../reducers/pluginDownloads';
|
} from '../../reducers/pluginDownloads';
|
||||||
import {
|
import {
|
||||||
loadPlugin,
|
loadPlugin,
|
||||||
starPlugin,
|
switchPlugin,
|
||||||
uninstallPlugin,
|
uninstallPlugin,
|
||||||
} from '../../reducers/pluginManager';
|
} from '../../reducers/pluginManager';
|
||||||
import {BundledPluginDetails} from 'plugin-lib';
|
import {BundledPluginDetails} from 'plugin-lib';
|
||||||
@@ -86,8 +86,8 @@ export const PluginList = memo(function PluginList({
|
|||||||
metroDevice,
|
metroDevice,
|
||||||
client,
|
client,
|
||||||
plugins,
|
plugins,
|
||||||
connections.userStarredPlugins,
|
connections.enabledPlugins,
|
||||||
connections.userStarredDevicePlugins,
|
connections.enabledDevicePlugins,
|
||||||
pluginsChanged,
|
pluginsChanged,
|
||||||
]);
|
]);
|
||||||
const isConnected = useValue(activeDevice?.connected, false);
|
const isConnected = useValue(activeDevice?.connected, false);
|
||||||
@@ -142,12 +142,12 @@ export const PluginList = memo(function PluginList({
|
|||||||
},
|
},
|
||||||
[dispatch, metroDevice, connections.selectedApp],
|
[dispatch, metroDevice, connections.selectedApp],
|
||||||
);
|
);
|
||||||
const handleStarPlugin = useCallback(
|
const handleEnablePlugin = useCallback(
|
||||||
(id: string) => {
|
(id: string) => {
|
||||||
const plugin = (plugins.clientPlugins.get(id) ??
|
const plugin = (plugins.clientPlugins.get(id) ??
|
||||||
plugins.devicePlugins.get(id))!;
|
plugins.devicePlugins.get(id))!;
|
||||||
dispatch(
|
dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
selectedApp: client?.query.app,
|
selectedApp: client?.query.app,
|
||||||
plugin,
|
plugin,
|
||||||
}),
|
}),
|
||||||
@@ -207,7 +207,7 @@ export const PluginList = memo(function PluginList({
|
|||||||
isArchived ? null : (
|
isArchived ? null : (
|
||||||
<ActionButton
|
<ActionButton
|
||||||
id={plugin.id}
|
id={plugin.id}
|
||||||
onClick={handleStarPlugin}
|
onClick={handleEnablePlugin}
|
||||||
title="Disable plugin"
|
title="Disable plugin"
|
||||||
icon={
|
icon={
|
||||||
<MinusOutlined size={16} style={{marginRight: 0}} />
|
<MinusOutlined size={16} style={{marginRight: 0}} />
|
||||||
@@ -250,7 +250,7 @@ export const PluginList = memo(function PluginList({
|
|||||||
isConnected ? (
|
isConnected ? (
|
||||||
<ActionButton
|
<ActionButton
|
||||||
id={plugin.id}
|
id={plugin.id}
|
||||||
onClick={handleStarPlugin}
|
onClick={handleEnablePlugin}
|
||||||
title="Disable plugin"
|
title="Disable plugin"
|
||||||
icon={
|
icon={
|
||||||
<MinusOutlined size={16} style={{marginRight: 0}} />
|
<MinusOutlined size={16} style={{marginRight: 0}} />
|
||||||
@@ -285,7 +285,7 @@ export const PluginList = memo(function PluginList({
|
|||||||
<ActionButton
|
<ActionButton
|
||||||
id={plugin.id}
|
id={plugin.id}
|
||||||
title="Enable plugin"
|
title="Enable plugin"
|
||||||
onClick={handleStarPlugin}
|
onClick={handleEnablePlugin}
|
||||||
icon={
|
icon={
|
||||||
<PlusOutlined size={16} style={{marginRight: 0}} />
|
<PlusOutlined size={16} style={{marginRight: 0}} />
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import {
|
|||||||
registerMarketplacePlugins,
|
registerMarketplacePlugins,
|
||||||
registerPlugins,
|
registerPlugins,
|
||||||
} from '../../../reducers/plugins';
|
} from '../../../reducers/plugins';
|
||||||
import {starPlugin} from '../../../reducers/pluginManager';
|
import {switchPlugin} from '../../../reducers/pluginManager';
|
||||||
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
import * as LogsPluginModule from '../../../../../plugins/logs/index';
|
import * as LogsPluginModule from '../../../../../plugins/logs/index';
|
||||||
@@ -174,8 +174,8 @@ describe('basic findBestDevice with metro present', () => {
|
|||||||
metro,
|
metro,
|
||||||
flipper.client,
|
flipper.client,
|
||||||
state.plugins,
|
state.plugins,
|
||||||
state.connections.userStarredPlugins,
|
state.connections.enabledPlugins,
|
||||||
state.connections.userStarredDevicePlugins,
|
state.connections.enabledDevicePlugins,
|
||||||
),
|
),
|
||||||
).toEqual({
|
).toEqual({
|
||||||
downloadablePlugins: [],
|
downloadablePlugins: [],
|
||||||
@@ -286,8 +286,8 @@ describe('basic findBestDevice with metro present', () => {
|
|||||||
metro,
|
metro,
|
||||||
flipper.client,
|
flipper.client,
|
||||||
state.plugins,
|
state.plugins,
|
||||||
state.connections.userStarredPlugins,
|
state.connections.enabledPlugins,
|
||||||
state.connections.userStarredDevicePlugins,
|
state.connections.enabledDevicePlugins,
|
||||||
);
|
);
|
||||||
expect(pluginLists).toEqual({
|
expect(pluginLists).toEqual({
|
||||||
devicePlugins: [logsPlugin],
|
devicePlugins: [logsPlugin],
|
||||||
@@ -316,7 +316,7 @@ describe('basic findBestDevice with metro present', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
flipper.store.dispatch(
|
flipper.store.dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
plugin: plugin2,
|
plugin: plugin2,
|
||||||
selectedApp: flipper.client.query.app,
|
selectedApp: flipper.client.query.app,
|
||||||
}),
|
}),
|
||||||
@@ -328,8 +328,8 @@ describe('basic findBestDevice with metro present', () => {
|
|||||||
metro,
|
metro,
|
||||||
flipper.client,
|
flipper.client,
|
||||||
state.plugins,
|
state.plugins,
|
||||||
state.connections.userStarredPlugins,
|
state.connections.enabledPlugins,
|
||||||
state.connections.userStarredDevicePlugins,
|
state.connections.enabledDevicePlugins,
|
||||||
),
|
),
|
||||||
).toMatchObject({
|
).toMatchObject({
|
||||||
enabledPlugins: [plugin2],
|
enabledPlugins: [plugin2],
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ export default class MockFlipper {
|
|||||||
});
|
});
|
||||||
device.loadDevicePlugins(
|
device.loadDevicePlugins(
|
||||||
this._store.getState().plugins.devicePlugins,
|
this._store.getState().plugins.devicePlugins,
|
||||||
this.store.getState().connections.userStarredDevicePlugins,
|
this.store.getState().connections.enabledDevicePlugins,
|
||||||
);
|
);
|
||||||
this._devices.push(device);
|
this._devices.push(device);
|
||||||
return device;
|
return device;
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import {PluginDefinition} from '../plugin';
|
|||||||
import PluginContainer from '../PluginContainer';
|
import PluginContainer from '../PluginContainer';
|
||||||
import {getPluginKey, isDevicePluginDefinition} from '../utils/pluginUtils';
|
import {getPluginKey, isDevicePluginDefinition} from '../utils/pluginUtils';
|
||||||
import MockFlipper from './MockFlipper';
|
import MockFlipper from './MockFlipper';
|
||||||
import {starPlugin} from '../reducers/pluginManager';
|
import {switchPlugin} from '../reducers/pluginManager';
|
||||||
|
|
||||||
export type MockFlipperResult = {
|
export type MockFlipperResult = {
|
||||||
client: Client;
|
client: Client;
|
||||||
@@ -71,11 +71,9 @@ function isPluginEnabled(
|
|||||||
(!isDevicePluginDefinition(pluginClazz) &&
|
(!isDevicePluginDefinition(pluginClazz) &&
|
||||||
store
|
store
|
||||||
.getState()
|
.getState()
|
||||||
.connections.userStarredPlugins[selectedApp]?.includes(
|
.connections.enabledPlugins[selectedApp]?.includes(pluginClazz.id)) ||
|
||||||
pluginClazz.id,
|
|
||||||
)) ||
|
|
||||||
(isDevicePluginDefinition(pluginClazz) &&
|
(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
|
// enable the plugin
|
||||||
if (!isPluginEnabled(store, pluginClazz, name)) {
|
if (!isPluginEnabled(store, pluginClazz, name)) {
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
plugin: pluginClazz,
|
plugin: pluginClazz,
|
||||||
selectedApp: client.query.app,
|
selectedApp: client.query.app,
|
||||||
}),
|
}),
|
||||||
@@ -118,7 +116,7 @@ export async function createMockFlipperWithPlugin(
|
|||||||
options?.additionalPlugins?.forEach((plugin) => {
|
options?.additionalPlugins?.forEach((plugin) => {
|
||||||
if (!isPluginEnabled(store, plugin, name)) {
|
if (!isPluginEnabled(store, plugin, name)) {
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
plugin,
|
plugin,
|
||||||
selectedApp: client.query.app,
|
selectedApp: client.query.app,
|
||||||
}),
|
}),
|
||||||
@@ -172,7 +170,7 @@ export async function createMockFlipperWithPlugin(
|
|||||||
throw new Error('unknown plugin ' + id);
|
throw new Error('unknown plugin ' + id);
|
||||||
}
|
}
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
plugin,
|
plugin,
|
||||||
selectedApp: client.query.app,
|
selectedApp: client.query.app,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import pluginMessageQueue, {
|
|||||||
queueMessages,
|
queueMessages,
|
||||||
} from '../../reducers/pluginMessageQueue';
|
} from '../../reducers/pluginMessageQueue';
|
||||||
import {registerPlugins} from '../../reducers/plugins';
|
import {registerPlugins} from '../../reducers/plugins';
|
||||||
import {starPlugin} from '../../reducers/pluginManager';
|
import {switchPlugin} from '../../reducers/pluginManager';
|
||||||
|
|
||||||
interface PersistedState {
|
interface PersistedState {
|
||||||
count: 1;
|
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(
|
store.dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
plugin: TestPlugin,
|
plugin: TestPlugin,
|
||||||
selectedApp: client.query.app,
|
selectedApp: client.query.app,
|
||||||
}),
|
}),
|
||||||
@@ -174,8 +174,8 @@ test('queue - events are NOT processed immediately if plugin is NOT selected (bu
|
|||||||
[pluginKey]: [],
|
[pluginKey]: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
// unstar, but, messages still arrives because selected
|
// disable, but, messages still arrives because selected
|
||||||
starTestPlugin(store, client);
|
switchTestPlugin(store, client);
|
||||||
selectTestPlugin(store, client);
|
selectTestPlugin(store, client);
|
||||||
sendMessage('inc', {delta: 3});
|
sendMessage('inc', {delta: 3});
|
||||||
client.flushMessageBuffer();
|
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);
|
selectDeviceLogs(store);
|
||||||
sendMessage('inc', {delta: 4});
|
sendMessage('inc', {delta: 4});
|
||||||
client.flushMessageBuffer();
|
client.flushMessageBuffer();
|
||||||
expect(store.getState().pluginMessageQueue).toEqual({});
|
expect(store.getState().pluginMessageQueue).toEqual({});
|
||||||
|
|
||||||
// star again, plugin still not selected, message is queued
|
// star again, plugin still not selected, message is queued
|
||||||
starTestPlugin(store, client);
|
switchTestPlugin(store, client);
|
||||||
sendMessage('inc', {delta: 5});
|
sendMessage('inc', {delta: 5});
|
||||||
client.flushMessageBuffer();
|
client.flushMessageBuffer();
|
||||||
|
|
||||||
@@ -686,14 +686,14 @@ test('queue - messages that have not yet flushed be lost when disabling the plug
|
|||||||
`);
|
`);
|
||||||
|
|
||||||
// disable
|
// disable
|
||||||
starTestPlugin(store, client);
|
switchTestPlugin(store, client);
|
||||||
expect(client.messageBuffer).toMatchInlineSnapshot(`Object {}`);
|
expect(client.messageBuffer).toMatchInlineSnapshot(`Object {}`);
|
||||||
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(
|
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(
|
||||||
`Object {}`,
|
`Object {}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
// re-enable, no messages arrive
|
// re-enable, no messages arrive
|
||||||
starTestPlugin(store, client);
|
switchTestPlugin(store, client);
|
||||||
client.flushMessageBuffer();
|
client.flushMessageBuffer();
|
||||||
processMessageQueue(TestPlugin, pluginKey, store);
|
processMessageQueue(TestPlugin, pluginKey, store);
|
||||||
expect(store.getState().pluginStates).toMatchInlineSnapshot(`Object {}`);
|
expect(store.getState().pluginStates).toMatchInlineSnapshot(`Object {}`);
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import {
|
|||||||
PluginClient,
|
PluginClient,
|
||||||
_SandyPluginInstance,
|
_SandyPluginInstance,
|
||||||
} from 'flipper-plugin';
|
} from 'flipper-plugin';
|
||||||
import {starPlugin} from '../../reducers/pluginManager';
|
import {switchPlugin} from '../../reducers/pluginManager';
|
||||||
|
|
||||||
type Events = {
|
type Events = {
|
||||||
inc: {
|
inc: {
|
||||||
@@ -57,9 +57,9 @@ const TestPlugin = new _SandyPluginDefinition(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
function starTestPlugin(store: Store, client: Client) {
|
function switchTestPlugin(store: Store, client: Client) {
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
plugin: TestPlugin,
|
plugin: TestPlugin,
|
||||||
selectedApp: client.query.app,
|
selectedApp: client.query.app,
|
||||||
}),
|
}),
|
||||||
@@ -184,8 +184,8 @@ test('queue - events are NOT processed immediately if plugin is NOT selected (bu
|
|||||||
[pluginKey]: [],
|
[pluginKey]: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
// unstar. Messages don't arrive anymore
|
// disable. Messages don't arrive anymore
|
||||||
starTestPlugin(store, client);
|
switchTestPlugin(store, client);
|
||||||
// weird state...
|
// weird state...
|
||||||
selectTestPlugin(store, client);
|
selectTestPlugin(store, client);
|
||||||
sendMessage('inc', {delta: 3});
|
sendMessage('inc', {delta: 3});
|
||||||
@@ -193,7 +193,7 @@ test('queue - events are NOT processed immediately if plugin is NOT selected (bu
|
|||||||
// active, immediately processed
|
// active, immediately processed
|
||||||
expect(client.sandyPluginStates.has(TestPlugin.id)).toBe(false);
|
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);
|
selectDeviceLogs(store);
|
||||||
sendMessage('inc', {delta: 4});
|
sendMessage('inc', {delta: 4});
|
||||||
client.flushMessageBuffer();
|
client.flushMessageBuffer();
|
||||||
@@ -201,7 +201,7 @@ test('queue - events are NOT processed immediately if plugin is NOT selected (bu
|
|||||||
expect(store.getState().pluginMessageQueue).toEqual({});
|
expect(store.getState().pluginMessageQueue).toEqual({});
|
||||||
|
|
||||||
// star again, plugin still not selected, message is queued
|
// star again, plugin still not selected, message is queued
|
||||||
starTestPlugin(store, client);
|
switchTestPlugin(store, client);
|
||||||
sendMessage('inc', {delta: 5});
|
sendMessage('inc', {delta: 5});
|
||||||
client.flushMessageBuffer();
|
client.flushMessageBuffer();
|
||||||
|
|
||||||
@@ -230,13 +230,12 @@ test('queue - events ARE processed immediately if plugin is NOT selected / enabl
|
|||||||
selectDeviceLogs(store);
|
selectDeviceLogs(store);
|
||||||
expect(store.getState().connections.selectedPlugin).toBe('DeviceLogs');
|
expect(store.getState().connections.selectedPlugin).toBe('DeviceLogs');
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
starPlugin({
|
switchPlugin({
|
||||||
plugin: NavigationPlugin,
|
plugin: NavigationPlugin,
|
||||||
selectedApp: client.query.app,
|
selectedApp: client.query.app,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
expect(store.getState().connections.userStarredPlugins)
|
expect(store.getState().connections.enabledPlugins).toMatchInlineSnapshot(`
|
||||||
.toMatchInlineSnapshot(`
|
|
||||||
Object {
|
Object {
|
||||||
"TestApp": Array [],
|
"TestApp": Array [],
|
||||||
}
|
}
|
||||||
@@ -728,14 +727,14 @@ test('queue - messages that have not yet flushed be lost when disabling the plug
|
|||||||
`);
|
`);
|
||||||
|
|
||||||
// disable
|
// disable
|
||||||
starTestPlugin(store, client);
|
switchTestPlugin(store, client);
|
||||||
expect(client.messageBuffer).toMatchInlineSnapshot(`Object {}`);
|
expect(client.messageBuffer).toMatchInlineSnapshot(`Object {}`);
|
||||||
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(
|
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(
|
||||||
`Object {}`,
|
`Object {}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
// re-enable, no messages arrive
|
// re-enable, no messages arrive
|
||||||
starTestPlugin(store, client);
|
switchTestPlugin(store, client);
|
||||||
client.flushMessageBuffer();
|
client.flushMessageBuffer();
|
||||||
processMessageQueue(
|
processMessageQueue(
|
||||||
client.sandyPluginStates.get(TestPlugin.id)!,
|
client.sandyPluginStates.get(TestPlugin.id)!,
|
||||||
|
|||||||
@@ -802,7 +802,7 @@ export function importDataToStore(source: string, data: string, store: Store) {
|
|||||||
});
|
});
|
||||||
archivedDevice.loadDevicePlugins(
|
archivedDevice.loadDevicePlugins(
|
||||||
store.getState().plugins.devicePlugins,
|
store.getState().plugins.devicePlugins,
|
||||||
store.getState().connections.userStarredDevicePlugins,
|
store.getState().connections.enabledDevicePlugins,
|
||||||
deserializeObject(device.pluginStates),
|
deserializeObject(device.pluginStates),
|
||||||
);
|
);
|
||||||
store.dispatch({
|
store.dispatch({
|
||||||
|
|||||||
@@ -47,9 +47,7 @@ export function initializeFlipperLibImplementation(
|
|||||||
if (
|
if (
|
||||||
store
|
store
|
||||||
.getState()
|
.getState()
|
||||||
.connections.userStarredPlugins[client.query.app]?.includes(
|
.connections.enabledPlugins[client.query.app]?.includes(pluginId)
|
||||||
pluginId,
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import {
|
|||||||
DEFAULT_MAX_QUEUE_SIZE,
|
DEFAULT_MAX_QUEUE_SIZE,
|
||||||
} from '../reducers/pluginMessageQueue';
|
} from '../reducers/pluginMessageQueue';
|
||||||
import {IdlerImpl} from './Idler';
|
import {IdlerImpl} from './Idler';
|
||||||
import {pluginIsStarred, getSelectedPluginKey} from '../reducers/connections';
|
import {isPluginEnabled, getSelectedPluginKey} from '../reducers/connections';
|
||||||
import {deconstructPluginKey} from './clientUtils';
|
import {deconstructPluginKey} from './clientUtils';
|
||||||
import {defaultEnabledBackgroundPlugins} from './pluginUtils';
|
import {defaultEnabledBackgroundPlugins} from './pluginUtils';
|
||||||
import {batch, Idler, _SandyPluginInstance} from 'flipper-plugin';
|
import {batch, Idler, _SandyPluginInstance} from 'flipper-plugin';
|
||||||
@@ -133,9 +133,9 @@ export function processMessagesLater(
|
|||||||
case plugin instanceof _SandyPluginInstance:
|
case plugin instanceof _SandyPluginInstance:
|
||||||
case plugin instanceof FlipperDevicePlugin:
|
case plugin instanceof FlipperDevicePlugin:
|
||||||
case (plugin as any).prototype instanceof FlipperDevicePlugin:
|
case (plugin as any).prototype instanceof FlipperDevicePlugin:
|
||||||
case pluginIsStarred(
|
case isPluginEnabled(
|
||||||
store.getState().connections.userStarredPlugins,
|
store.getState().connections.enabledPlugins,
|
||||||
store.getState().connections.userStarredDevicePlugins,
|
store.getState().connections.enabledDevicePlugins,
|
||||||
deconstructPluginKey(pluginKey).client,
|
deconstructPluginKey(pluginKey).client,
|
||||||
pluginId,
|
pluginId,
|
||||||
):
|
):
|
||||||
|
|||||||
@@ -83,8 +83,8 @@ export function getExportablePlugins(
|
|||||||
undefined,
|
undefined,
|
||||||
client,
|
client,
|
||||||
state.plugins,
|
state.plugins,
|
||||||
state.connections.userStarredPlugins,
|
state.connections.enabledPlugins,
|
||||||
state.connections.userStarredDevicePlugins,
|
state.connections.enabledDevicePlugins,
|
||||||
);
|
);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@@ -179,8 +179,8 @@ export function computePluginLists(
|
|||||||
metroDevice: BaseDevice | undefined,
|
metroDevice: BaseDevice | undefined,
|
||||||
client: Client | undefined,
|
client: Client | undefined,
|
||||||
plugins: State['plugins'],
|
plugins: State['plugins'],
|
||||||
userStarredPlugins: State['connections']['userStarredPlugins'],
|
enabledPluginsState: State['connections']['enabledPlugins'],
|
||||||
userStarredDevicePlugins: Set<string>,
|
enabledDevicePluginsState: Set<string>,
|
||||||
_pluginsChanged?: number, // this argument is purely used to invalidate the memoization cache
|
_pluginsChanged?: number, // this argument is purely used to invalidate the memoization cache
|
||||||
) {
|
) {
|
||||||
const uninstalledMarketplacePlugins = filterNewestVersionOfEachPlugin(
|
const uninstalledMarketplacePlugins = filterNewestVersionOfEachPlugin(
|
||||||
@@ -191,12 +191,12 @@ export function computePluginLists(
|
|||||||
...plugins.devicePlugins.values(),
|
...plugins.devicePlugins.values(),
|
||||||
]
|
]
|
||||||
.filter((p) => device?.supportsPlugin(p))
|
.filter((p) => device?.supportsPlugin(p))
|
||||||
.filter((p) => userStarredDevicePlugins.has(p.id));
|
.filter((p) => enabledDevicePluginsState.has(p.id));
|
||||||
const metroPlugins: DevicePluginDefinition[] = [
|
const metroPlugins: DevicePluginDefinition[] = [
|
||||||
...plugins.devicePlugins.values(),
|
...plugins.devicePlugins.values(),
|
||||||
]
|
]
|
||||||
.filter((p) => metroDevice?.supportsPlugin(p))
|
.filter((p) => metroDevice?.supportsPlugin(p))
|
||||||
.filter((p) => userStarredDevicePlugins.has(p.id));
|
.filter((p) => enabledDevicePluginsState.has(p.id));
|
||||||
const enabledPlugins: ClientPluginDefinition[] = [];
|
const enabledPlugins: ClientPluginDefinition[] = [];
|
||||||
const disabledPlugins: PluginDefinition[] = [
|
const disabledPlugins: PluginDefinition[] = [
|
||||||
...plugins.devicePlugins.values(),
|
...plugins.devicePlugins.values(),
|
||||||
@@ -206,7 +206,7 @@ export function computePluginLists(
|
|||||||
device?.supportsPlugin(p.details) ||
|
device?.supportsPlugin(p.details) ||
|
||||||
metroDevice?.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 unavailablePlugins: [plugin: PluginDetails, reason: string][] = [];
|
||||||
const downloadablePlugins: (
|
const downloadablePlugins: (
|
||||||
| DownloadablePluginDetails
|
| DownloadablePluginDetails
|
||||||
@@ -263,7 +263,7 @@ export function computePluginLists(
|
|||||||
device,
|
device,
|
||||||
client,
|
client,
|
||||||
clientPlugins,
|
clientPlugins,
|
||||||
client && userStarredPlugins[client.query.app],
|
client && enabledPluginsState[client.query.app],
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
clientPlugins.forEach((plugin) => {
|
clientPlugins.forEach((plugin) => {
|
||||||
@@ -323,7 +323,7 @@ function getFavoritePlugins(
|
|||||||
device: BaseDevice,
|
device: BaseDevice,
|
||||||
client: Client,
|
client: Client,
|
||||||
allPlugins: PluginDefinition[],
|
allPlugins: PluginDefinition[],
|
||||||
starredPlugins: undefined | string[],
|
enabledPlugins: undefined | string[],
|
||||||
returnFavoredPlugins: boolean, // if false, unfavoried plugins are returned
|
returnFavoredPlugins: boolean, // if false, unfavoried plugins are returned
|
||||||
): PluginDefinition[] {
|
): PluginDefinition[] {
|
||||||
if (device.isArchived) {
|
if (device.isArchived) {
|
||||||
@@ -335,11 +335,11 @@ function getFavoritePlugins(
|
|||||||
(plugin) => client.plugins.indexOf(plugin.id) !== -1,
|
(plugin) => client.plugins.indexOf(plugin.id) !== -1,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!starredPlugins || !starredPlugins.length) {
|
if (!enabledPlugins || !enabledPlugins.length) {
|
||||||
return returnFavoredPlugins ? [] : allPlugins;
|
return returnFavoredPlugins ? [] : allPlugins;
|
||||||
}
|
}
|
||||||
return allPlugins.filter((plugin) => {
|
return allPlugins.filter((plugin) => {
|
||||||
const idx = starredPlugins.indexOf(plugin.id);
|
const idx = enabledPlugins.indexOf(plugin.id);
|
||||||
return idx === -1 ? !returnFavoredPlugins : returnFavoredPlugins;
|
return idx === -1 ? !returnFavoredPlugins : returnFavoredPlugins;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ const {version} = require('../package.json');
|
|||||||
const dev = process.env.NODE_ENV !== 'production';
|
const dev = process.env.NODE_ENV !== 'production';
|
||||||
|
|
||||||
// For insiders builds we bundle top 5 popular device plugins,
|
// 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>([
|
const hardcodedPlugins = new Set<string>([
|
||||||
// Popular device plugins
|
// Popular device plugins
|
||||||
'DeviceLogs',
|
'DeviceLogs',
|
||||||
|
|||||||
Reference in New Issue
Block a user