Persist uninstalled plugins list

Summary: This diff changes uninstallation procedure for plugins. Instead of deleting plugin files immediately we are keeping them, but mark them as "uninstalled". This makes it possible to re-install plugins quickly in case when user clicked "delete" by mistake.

Reviewed By: mweststrate

Differential Revision: D25493479

fbshipit-source-id: 9ff29d717cdd5401c55388f24d479599579c8dd3
This commit is contained in:
Anton Nikolaev
2020-12-15 09:28:58 -08:00
committed by Facebook GitHub Bot
parent df03ccbeab
commit c3d61cc32d
9 changed files with 81 additions and 93 deletions

View File

@@ -9,22 +9,20 @@
import {Store} from '../reducers/index';
import {Logger} from '../fb-interfaces/Logger';
import {
pluginFilesRemoved,
registerInstalledPlugins,
} from '../reducers/pluginManager';
import {registerInstalledPlugins} from '../reducers/pluginManager';
import {
getInstalledPlugins,
cleanupOldInstalledPluginVersions,
removePlugin,
removePlugins,
} from 'flipper-plugin-lib';
import {sideEffect} from '../utils/sideEffect';
import pMap from 'p-map';
const maxInstalledPluginVersionsToKeep = 2;
function refreshInstalledPlugins(store: Store) {
cleanupOldInstalledPluginVersions(maxInstalledPluginVersionsToKeep)
removePlugins(store.getState().pluginManager.uninstalledPlugins.values())
.then(() =>
cleanupOldInstalledPluginVersions(maxInstalledPluginVersionsToKeep),
)
.then(() => getInstalledPlugins())
.then((plugins) => store.dispatch(registerInstalledPlugins(plugins)));
}
@@ -34,26 +32,4 @@ export default (store: Store, _logger: Logger) => {
window.requestIdleCallback(() => {
refreshInstalledPlugins(store);
});
sideEffect(
store,
{
name: 'removeUninstalledPluginFiles',
throttleMs: 1000,
fireImmediately: true,
},
(state) => state.pluginManager.removedPlugins,
(removedPlugins) => {
pMap(removedPlugins, (p) => {
removePlugin(p.name)
.then(() => pluginFilesRemoved(p))
.catch((e) =>
console.error(
`Error while removing files of uninstalled plugin ${p.title}`,
e,
),
);
}).then(() => refreshInstalledPlugins(store));
},
);
};