Enable Marketplace for Flipper (#3491)

Summary:
This is PR on top of: https://github.com/facebook/flipper/pull/3473

It adds an option to Settings to allow distribution of marketplace plugins.

Also includes a simple fetch function to retrieve data from external API/server.

## Changelog

Allow marketplace plugins

Pull Request resolved: https://github.com/facebook/flipper/pull/3491

Test Plan:
1. Enable marketplace
2. Provide custom marketplace server (it will serve the list of internal plugins with downloadURL)
3. Test if can see Available plugins and can download/remove the plugin
4. If new update for the plugin, it should also allow auto update

Reviewed By: antonk52

Differential Revision: D34586339

Pulled By: nikoant

fbshipit-source-id: c887982aa0f0f9abd3b5360f22e8692a2445d345
This commit is contained in:
Anton Nikolaev
2022-03-07 02:49:49 -08:00
committed by Facebook GitHub Bot
parent 5b6000b424
commit 37ff34390a
9 changed files with 175 additions and 19 deletions

View File

@@ -320,7 +320,7 @@ async function verifyPluginStatus(
if (!isTest() && !store.getState().plugins.marketplacePlugins.length) {
// plugins not yet fetched
// updates plugins from marketplace (if logged in), and stores them
await loadPluginsFromMarketplace();
await loadPluginsFromMarketplace(store);
}
// while true loop; after pressing install or add GK, we want to check again if plugin is available
while (true) {

View File

@@ -27,6 +27,7 @@ import {isConnectivityOrAuthError} from 'flipper-common';
import {isLoggedIn} from '../fb-stubs/user';
import {getRenderHostInstance} from '..';
// TODO: provide this value from settings
export const pollingIntervalMs = getRenderHostInstance().serverConfig.env
.FLIPPER_PLUGIN_AUTO_UPDATE_POLLING_INTERVAL
? parseInt(
@@ -36,25 +37,31 @@ export const pollingIntervalMs = getRenderHostInstance().serverConfig.env
) // for manual testing we could set smaller interval
: 300000; // 5 min by default
function isAutoUpdateDisabled() {
function isAutoUpdateDisabled(store: Store) {
return (
!getFlipperLib().isFB ||
// for open-source version auto-updates must be explicitly enabled in Settings
(!getFlipperLib().isFB &&
!store.getState().settingsState.enablePluginMarketplaceAutoUpdate) ||
// for internal build we disable auto-updates in case user is not logged
(getFlipperLib().isFB && !isLoggedIn().get()) ||
getRenderHostInstance().GK('flipper_disable_plugin_auto_update') ||
getRenderHostInstance().serverConfig.env.FLIPPER_NO_PLUGIN_AUTO_UPDATE !==
undefined
);
}
function isPluginMarketplaceDisabled() {
function isPluginMarketplaceDisabled(store: Store) {
return (
!getFlipperLib().isFB ||
// for open-source version marketplace must be explicitly enabled in Settings
(!getFlipperLib().isFB &&
!store.getState().settingsState.enablePluginMarketplace) ||
getRenderHostInstance().GK('flipper_disable_plugin_marketplace') ||
getRenderHostInstance().serverConfig.env.FLIPPER_NO_PLUGIN_MARKETPLACE
);
}
export default (store: Store) => {
if (isPluginMarketplaceDisabled()) {
if (isPluginMarketplaceDisabled(store)) {
console.warn(
'Loading plugins from Plugin Marketplace disabled by GK or env var',
);
@@ -98,10 +105,10 @@ export default (store: Store) => {
};
};
export async function loadPluginsFromMarketplace(): Promise<
MarketplacePluginDetails[]
> {
const availablePlugins = await loadAvailablePlugins();
export async function loadPluginsFromMarketplace(
store: Store,
): Promise<MarketplacePluginDetails[]> {
const availablePlugins = await loadAvailablePlugins(store);
return selectCompatibleMarketplaceVersions(availablePlugins);
}
@@ -111,7 +118,7 @@ async function refreshMarketplacePlugins(store: Store): Promise<void> {
return;
}
try {
const plugins = await loadPluginsFromMarketplace();
const plugins = await loadPluginsFromMarketplace(store);
store.dispatch(registerMarketplacePlugins(plugins));
autoUpdatePlugins(store, plugins);
} catch (err) {
@@ -177,7 +184,7 @@ export function autoUpdatePlugins(
}
}
}
if (isAutoUpdateDisabled() || !isLoggedIn().get()) {
if (isAutoUpdateDisabled(store)) {
return;
}
for (const plugin of marketplacePlugins) {