diff --git a/src/Client.tsx b/src/Client.tsx index 4b0253697..1d6c76fd5 100644 --- a/src/Client.tsx +++ b/src/Client.tsx @@ -175,6 +175,20 @@ export default class Client extends EventEmitter { } } + /// Sort plugins by LRU order stored in lessPlugins; if not, sort by alphabet + byClientLRU(a: typeof FlipperPlugin, b: typeof FlipperPlugin): number { + const hasA = this.lessPlugins.includes(a.id); + const hasB = this.lessPlugins.includes(b.id); + if (hasA && hasB) { + return this.lessPlugins.indexOf(a.id) > this.lessPlugins.indexOf(b.id) + ? 1 + : -1; + } else if (hasA !== hasB) { + return hasB ? 1 : -1; + } + return (a.title || a.id) > (b.title || b.id) ? 1 : -1; + } + /* All clients should have a corresponding Device in the store. However, clients can connect before a device is registered, so wait a while for the device to be registered if it isn't already. */ diff --git a/src/chrome/MainSidebar.tsx b/src/chrome/MainSidebar.tsx index 5ae699098..d057a1da7 100644 --- a/src/chrome/MainSidebar.tsx +++ b/src/chrome/MainSidebar.tsx @@ -13,7 +13,6 @@ import {FlipperBasePlugin} from '../plugin'; import {PluginNotification} from '../reducers/notifications'; import {ActiveSheet} from '../reducers/application'; import {State as Store} from '../reducers'; -import {isTopUsedPlugin} from '../fb-stubs/pluginUsage'; import { Sidebar, @@ -318,13 +317,12 @@ class MainSidebar extends PureComponent { {Array.from(this.props.clientPlugins.values()) .filter( (p: typeof FlipperDevicePlugin) => - client.plugins.indexOf(p.id) > -1, + (client.showAllPlugins + ? client.plugins + : client.lessPlugins + ).indexOf(p.id) > -1, ) - .filter( - (p: typeof FlipperDevicePlugin) => - client.showAllPlugins || isTopUsedPlugin(p.title, 5), - ) - .sort(byPluginNameOrId) + .sort((a, b) => client.byClientLRU(a, b)) .map((plugin: typeof FlipperDevicePlugin) => ( { - return name === pluginName; - }); - return rank >= 0 && rank < range; -} diff --git a/src/reducers/connections.tsx b/src/reducers/connections.tsx index 8256a8702..c5062e313 100644 --- a/src/reducers/connections.tsx +++ b/src/reducers/connections.tsx @@ -215,10 +215,11 @@ const reducer = (state: State = INITAL_STATE, action: Action): State => { performance.mark(`activePlugin-${selectedPlugin}`); } - const LRUPlugins = - state.userLRUPlugins[selectedApp || state.userPreferredApp] || []; + const LRUPlugins = ( + state.userLRUPlugins[selectedApp || state.userPreferredApp] || [] + ).slice(); const idxLRU = LRUPlugins.indexOf(selectedPlugin); - if (idxLRU > 0) { + if (idxLRU >= 0) { LRUPlugins.splice(idxLRU, 1); } LRUPlugins.unshift(selectedPlugin); @@ -241,13 +242,13 @@ const reducer = (state: State = INITAL_STATE, action: Action): State => { const {userPreferredApp, userPreferredPlugin, userLRUPlugins} = state; let {selectedApp, selectedPlugin} = state; - const lessPlugins = userLRUPlugins[payload.id]; + const lessPlugins = (userLRUPlugins[payload.id] || []).slice(); if (lessPlugins) { payload.lessPlugins = lessPlugins.concat( payload.plugins.filter(p => !lessPlugins.includes(p)), ); } else { - payload.lessPlugins = payload.plugins; + payload.lessPlugins = payload.plugins.slice(); } payload.lessPlugins = payload.lessPlugins.slice(0, MAX_MINIMUM_PLUGINS);