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
96 lines
2.5 KiB
TypeScript
96 lines
2.5 KiB
TypeScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
import path from 'path';
|
|
import os from 'os';
|
|
import fs from 'fs';
|
|
|
|
const flipperHomeDir = path.join(os.homedir(), '.flipper');
|
|
export const configPath = path.join(flipperHomeDir, 'config.json');
|
|
export const defaultConfig: Config = {
|
|
pluginPaths: [],
|
|
disabledPlugins: [],
|
|
darkMode: 'light',
|
|
suppressPluginUpdateNotifications: false,
|
|
};
|
|
|
|
export type Config = {
|
|
pluginPaths?: string[];
|
|
disabledPlugins?: string[];
|
|
lastWindowPosition?: {
|
|
x: number;
|
|
y: number;
|
|
width: number;
|
|
height: number;
|
|
};
|
|
updater?: boolean | undefined;
|
|
launcherMsg?: string | undefined;
|
|
updaterEnabled?: boolean;
|
|
launcherEnabled?: boolean;
|
|
darkMode: 'system' | 'light' | 'dark';
|
|
suppressPluginUpdateNotifications?: boolean;
|
|
};
|
|
|
|
const ensureConfigDirExists = async (path: fs.PathLike) => {
|
|
try {
|
|
await fs.promises.access(path);
|
|
} catch (e) {
|
|
console.warn('Config directory not found, creating config directory.');
|
|
try {
|
|
await fs.promises.mkdir(path);
|
|
} catch (e) {
|
|
console.error('Failed to create config directory', e);
|
|
}
|
|
}
|
|
};
|
|
|
|
const readConfigFile = async (configPath: fs.PathLike) => {
|
|
let config = defaultConfig;
|
|
|
|
try {
|
|
config = {
|
|
...config,
|
|
...JSON.parse((await fs.promises.readFile(configPath)).toString()),
|
|
};
|
|
} catch (e) {
|
|
// file not readable or not parsable, overwrite it with the new config
|
|
console.warn(`Failed to read ${configPath}: ${e}`);
|
|
console.info('Writing new default config.');
|
|
await fs.promises.writeFile(configPath, JSON.stringify(config));
|
|
}
|
|
return config;
|
|
};
|
|
|
|
export default async function setup(argv: any) {
|
|
// ensure .flipper folder and config exist
|
|
await ensureConfigDirExists(flipperHomeDir);
|
|
|
|
let config = await readConfigFile(configPath);
|
|
|
|
// Non-persistent CLI arguments.
|
|
config = {
|
|
...config,
|
|
darkMode:
|
|
typeof config.darkMode === 'boolean'
|
|
? config.darkMode // normalise darkmode from old format
|
|
? 'dark'
|
|
: 'light'
|
|
: config.darkMode,
|
|
updaterEnabled: argv.updater,
|
|
launcherEnabled: argv.launcher,
|
|
launcherMsg: argv.launcherMsg,
|
|
suppressPluginUpdateNotifications:
|
|
typeof config.suppressPluginUpdateNotifications === 'boolean'
|
|
? config.suppressPluginUpdateNotifications
|
|
: false,
|
|
};
|
|
|
|
return config;
|
|
}
|