From fa9ba6f2d03eb5eaa5d5f757aa272105a6b433fb Mon Sep 17 00:00:00 2001 From: Ken Yee <586670+kenyee@users.noreply.github.com> Date: Wed, 21 Sep 2022 09:47:44 -0700 Subject: [PATCH] Adds a notifyAvailableUpdate flag to config.json to disable update (#3992) Summary: We would like to version control Flipper and some of our custom plugins that are installed on developers' systems. Flipper by default prompts users to upgrade so they sometimes do the update and then all our custom plugins break because they were compiled for an older version. See https://github.com/facebook/flipper/issues/3947 for feature request info. ## Changelog Adds notifyAvailable flag to config.json to disable prompting for users that "an update is available" Pull Request resolved: https://github.com/facebook/flipper/pull/3992 Test Plan: Tested by running locally. Had to comment out the isProduction() check to confirm this it worked properly because this flag is false on dev versions. Couldn't figure out how to manually test the handleOpenPluginDeeplink.tsx change but made a similar change there; happy to test that if you can tell me how to exercise that path. Reviewed By: antonk52 Differential Revision: D39654481 Pulled By: antonk52 fbshipit-source-id: cef6b48d870915c48f620269c42d24b8ef1f4c29 --- desktop/flipper-common/src/settings.tsx | 4 +++- .../src/utils/__tests__/processConfig.node.tsx | 3 +++ desktop/flipper-server-core/src/utils/processConfig.tsx | 4 ++++ desktop/flipper-ui-core/src/chrome/UpdateIndicator.tsx | 8 +++++++- .../src/dispatcher/handleOpenPluginDeeplink.tsx | 3 ++- desktop/scripts/jest-setup-after.tsx | 1 + desktop/static/main.tsx | 2 +- desktop/static/setup.tsx | 6 ++++++ 8 files changed, 27 insertions(+), 4 deletions(-) diff --git a/desktop/flipper-common/src/settings.tsx b/desktop/flipper-common/src/settings.tsx index 02b72f8c0..de730cc13 100644 --- a/desktop/flipper-common/src/settings.tsx +++ b/desktop/flipper-common/src/settings.tsx @@ -76,7 +76,7 @@ export type LauncherSettings = { ignoreLocalPin: boolean; }; -// Settings that primarily only apply to Eelectron atm +// Settings that primarily only apply to Electron atm // TODO: further separte between flipper-ui config and Electron config export type ProcessConfig = { disabledPlugins: string[]; @@ -90,6 +90,8 @@ export type ProcessConfig = { launcherMsg: string | null; // Controls whether to delegate to the launcher if present. launcherEnabled: boolean; + // Control whether to suppress "update available" notifications + suppressPluginUpdateNotifications?: boolean; }; export type Platform = diff --git a/desktop/flipper-server-core/src/utils/__tests__/processConfig.node.tsx b/desktop/flipper-server-core/src/utils/__tests__/processConfig.node.tsx index 2a1d6af63..0f41b8865 100644 --- a/desktop/flipper-server-core/src/utils/__tests__/processConfig.node.tsx +++ b/desktop/flipper-server-core/src/utils/__tests__/processConfig.node.tsx @@ -17,6 +17,7 @@ test('config is decoded from env', () => { launcherMsg: 'wubba lubba dub dub', screenCapturePath: '/my/screenshot/path', launcherEnabled: false, + suppressPluginUpdateNotifications: true, }), }); @@ -26,6 +27,7 @@ test('config is decoded from env', () => { launcherMsg: 'wubba lubba dub dub', screenCapturePath: '/my/screenshot/path', launcherEnabled: false, + suppressPluginUpdateNotifications: true, }); }); @@ -36,5 +38,6 @@ test('config is decoded from env with defaults', () => { launcherMsg: undefined, screenCapturePath: undefined, launcherEnabled: true, + suppressPluginUpdateNotifications: false, }); }); diff --git a/desktop/flipper-server-core/src/utils/processConfig.tsx b/desktop/flipper-server-core/src/utils/processConfig.tsx index 71085f59a..547be1755 100644 --- a/desktop/flipper-server-core/src/utils/processConfig.tsx +++ b/desktop/flipper-server-core/src/utils/processConfig.tsx @@ -18,5 +18,9 @@ export function loadProcessConfig(env: NodeJS.ProcessEnv): ProcessConfig { screenCapturePath: json.screenCapturePath, launcherEnabled: typeof json.launcherEnabled === 'boolean' ? json.launcherEnabled : true, + suppressPluginUpdateNotifications: + typeof json.suppressPluginUpdateNotifications === 'boolean' + ? json.suppressPluginUpdateNotifications + : false, }; } diff --git a/desktop/flipper-ui-core/src/chrome/UpdateIndicator.tsx b/desktop/flipper-ui-core/src/chrome/UpdateIndicator.tsx index fee3675cb..caf69eb71 100644 --- a/desktop/flipper-ui-core/src/chrome/UpdateIndicator.tsx +++ b/desktop/flipper-ui-core/src/chrome/UpdateIndicator.tsx @@ -15,6 +15,7 @@ import fbConfig from '../fb-stubs/config'; import {useStore} from '../utils/useStore'; import {getAppVersion} from '../utils/info'; import {checkForUpdate} from '../fb-stubs/checkForUpdate'; +import {getRenderHostInstance} from 'flipper-frontend-core'; export type VersionCheckResult = | { @@ -63,6 +64,7 @@ export default function UpdateIndicator() { // trigger the update check, unless there is a launcher message already useEffect(() => { const version = getAppVersion(); + const config = getRenderHostInstance().serverConfig.processConfig; if (launcherMsg && launcherMsg.message) { if (launcherMsg.severity === 'error') { notification.error({ @@ -81,7 +83,11 @@ export default function UpdateIndicator() { duration: null, }); } - } else if (version && isProduction()) { + } else if ( + version && + !config.suppressPluginUpdateNotifications && + isProduction() + ) { reportPlatformFailures( checkForUpdate(version).then((res) => { if (res.kind === 'error') { diff --git a/desktop/flipper-ui-core/src/dispatcher/handleOpenPluginDeeplink.tsx b/desktop/flipper-ui-core/src/dispatcher/handleOpenPluginDeeplink.tsx index 5daa14ef8..68ecb76ec 100644 --- a/desktop/flipper-ui-core/src/dispatcher/handleOpenPluginDeeplink.tsx +++ b/desktop/flipper-ui-core/src/dispatcher/handleOpenPluginDeeplink.tsx @@ -274,7 +274,8 @@ async function waitForLogin(store: Store) { } async function verifyFlipperIsUpToDate(title: string) { - if (!isProduction() || isTest()) { + const config = getRenderHostInstance().serverConfig.processConfig; + if (!isProduction() || isTest() || config.suppressPluginUpdateNotifications) { return; } const currentVersion = getAppVersion(); diff --git a/desktop/scripts/jest-setup-after.tsx b/desktop/scripts/jest-setup-after.tsx index a19544147..cdd708565 100644 --- a/desktop/scripts/jest-setup-after.tsx +++ b/desktop/scripts/jest-setup-after.tsx @@ -137,6 +137,7 @@ function createStubRenderHost(): RenderHost { launcherEnabled: false, launcherMsg: null, screenCapturePath: `/dev/null`, + suppressPluginUpdateNotifications: false, }, settings: { androidHome: `/dev/null`, diff --git a/desktop/static/main.tsx b/desktop/static/main.tsx index ba1a78f01..df44dfcac 100644 --- a/desktop/static/main.tsx +++ b/desktop/static/main.tsx @@ -216,7 +216,7 @@ app.on('ready', async () => { {allowFileAccess: true}, ); } catch (e) { - console.error('Failed to loa React devtools from disk: ', e); + console.error('Failed to load React devtools from disk: ', e); } } else { try { diff --git a/desktop/static/setup.tsx b/desktop/static/setup.tsx index d64c24617..ccf3904ef 100644 --- a/desktop/static/setup.tsx +++ b/desktop/static/setup.tsx @@ -17,6 +17,7 @@ export const defaultConfig: Config = { pluginPaths: [], disabledPlugins: [], darkMode: 'light', + suppressPluginUpdateNotifications: false, }; export type Config = { @@ -33,6 +34,7 @@ export type Config = { updaterEnabled?: boolean; launcherEnabled?: boolean; darkMode: 'system' | 'light' | 'dark'; + suppressPluginUpdateNotifications?: boolean; }; const ensureConfigDirExists = async (path: fs.PathLike) => { @@ -83,6 +85,10 @@ export default async function setup(argv: any) { updaterEnabled: argv.updater, launcherEnabled: argv.launcher, launcherMsg: argv.launcherMsg, + suppressPluginUpdateNotifications: + typeof config.suppressPluginUpdateNotifications === 'boolean' + ? config.suppressPluginUpdateNotifications + : false, }; return config;