diff --git a/desktop/flipper-dump/src/index.tsx b/desktop/flipper-dump/src/index.tsx index 01c7aa3c6..b1fd2be0e 100644 --- a/desktop/flipper-dump/src/index.tsx +++ b/desktop/flipper-dump/src/index.tsx @@ -48,6 +48,17 @@ const argv = yargs type: 'string', demandOption: true, }, + settingsString: { + describe: `override the existing defaults settings of flipper (settings.json file) e.g "{"androidHome":"/usr/local/bin","enableAndroid":true}"`, + type: 'string', + default: '', + }, + launcherSettings: { + describe: + 'Open Flipper with the configuration stored in .config folder for the launcher', + type: 'boolean', + default: true, + }, // TODO: support filtering events // TODO: support verbose mode // TODO: support post processing messages @@ -90,9 +101,9 @@ async function start(deviceQuery: string, appName: string, pluginId: string) { execPath: process.execPath, desktopPath: `/dev/null`, }, - launcherSettings: await loadLauncherSettings(), + launcherSettings: await loadLauncherSettings(argv.launcherSettings), processConfig: loadProcessConfig(process.env), - settings: await loadSettings(), + settings: await loadSettings(argv.settingsString), validWebSocketOrigins: [], }, logger, diff --git a/desktop/flipper-server-core/src/utils/launcherSettings.tsx b/desktop/flipper-server-core/src/utils/launcherSettings.tsx index 9b996fab6..38e24fa20 100644 --- a/desktop/flipper-server-core/src/utils/launcherSettings.tsx +++ b/desktop/flipper-server-core/src/utils/launcherSettings.tsx @@ -65,7 +65,13 @@ function deserialize(content: string): LauncherSettings { }; } -export async function loadLauncherSettings(): Promise { +export async function loadLauncherSettings( + enableLauncherSettings: boolean = true, +): Promise { + if (!enableLauncherSettings) { + return defaultLauncherSettings; + } + const fileName = getLauncherSettingsFile(); try { const content = (await fs.readFile(fileName)).toString(); diff --git a/desktop/flipper-server-core/src/utils/settings.tsx b/desktop/flipper-server-core/src/utils/settings.tsx index a3a46ac19..28b02a920 100644 --- a/desktop/flipper-server-core/src/utils/settings.tsx +++ b/desktop/flipper-server-core/src/utils/settings.tsx @@ -13,7 +13,16 @@ import xdg from 'xdg-basedir'; import {Settings, Tristate} from 'flipper-common'; import {readFile, writeFile, pathExists, mkdirp} from 'fs-extra'; -export async function loadSettings(): Promise { +export async function loadSettings( + settingsString: string = '', +): Promise { + if (settingsString !== '') { + try { + return replaceDefaultSettings(JSON.parse(settingsString)); + } catch (e) { + throw new Error("couldn't read the user settingsString"); + } + } if (!pathExists(getSettingsFile())) { return getDefaultSettings(); } @@ -74,3 +83,7 @@ function getDefaultAndroidSdkPath() { function getWindowsSdkPath() { return `${os.homedir()}\\AppData\\Local\\android\\sdk`; } + +function replaceDefaultSettings(userSettings: Partial): Settings { + return {...getDefaultSettings(), ...userSettings}; +} diff --git a/desktop/flipper-server/src/index.tsx b/desktop/flipper-server/src/index.tsx index 58d7dd8c6..a83f35315 100644 --- a/desktop/flipper-server/src/index.tsx +++ b/desktop/flipper-server/src/index.tsx @@ -44,6 +44,17 @@ const argv = yargs type: 'boolean', default: false, }, + settingsString: { + describe: `override the existing defaults settings of flipper (settings.json file) e.g "{"androidHome":"/usr/local/bin","enableAndroid":true}"`, + type: 'string', + default: '', + }, + launcherSettings: { + describe: + 'Open Flipper with the configuration stored in .config folder for the launcher', + type: 'boolean', + default: true, + }, }) .version('DEV') .help() @@ -71,7 +82,12 @@ async function start() { staticDir, entry: 'index.web.dev.html', }); - const flipperServer = await startFlipperServer(rootDir, staticDir); + const flipperServer = await startFlipperServer( + rootDir, + staticDir, + argv.settingsString, + argv.launcherSettings, + ); if (argv.failFast) { flipperServer.on('server-state', ({state}) => { if (state === 'error') { diff --git a/desktop/flipper-server/src/startFlipperServer.tsx b/desktop/flipper-server/src/startFlipperServer.tsx index a439602e4..adda074e9 100644 --- a/desktop/flipper-server/src/startFlipperServer.tsx +++ b/desktop/flipper-server/src/startFlipperServer.tsx @@ -28,6 +28,8 @@ import fs from 'fs'; export async function startFlipperServer( rootDir: string, staticPath: string, + settingsString: string, + enableLauncherSettings: boolean, ): Promise { if (os.platform() === 'darwin') { // By default Node.JS has its internal certificate storage and doesn't use @@ -85,9 +87,9 @@ export async function startFlipperServer( tempPath: os.tmpdir(), desktopPath: desktopPath, }, - launcherSettings: await loadLauncherSettings(), + launcherSettings: await loadLauncherSettings(enableLauncherSettings), processConfig: loadProcessConfig(env), - settings: await loadSettings(), + settings: await loadSettings(settingsString), validWebSocketOrigins: ['localhost:', 'http://localhost:'], }, logger,