Files
flipper/static/setup.js
Pascal Hartig e53f8fa98d Provide clearer message about launcher delegation (#373)
Summary:
To make it more obvious how to disable this if unwanted (e.g. when
testing local builds).
Pull Request resolved: https://github.com/facebook/flipper/pull/373

Reviewed By: jknoxville

Differential Revision: D14130771

Pulled By: passy

fbshipit-source-id: 82c83c1ad14737c8c7791de71a1ee23fcea5ec18
2019-02-19 03:27:31 -08:00

87 lines
2.2 KiB
JavaScript

/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
const path = require('path');
const os = require('os');
const fs = require('fs');
const {spawn} = require('child_process');
const isProduction = () =>
!/node_modules[\\/]electron[\\/]/.test(process.execPath);
const isLauncherInstalled = () => {
if (os.type() == 'Darwin') {
const receipt = 'com.facebook.flipper.launcher';
const plistLocation = '/Applications/Flipper.app/Contents/Info.plist';
return (
fs.existsSync(plistLocation) &&
fs.readFileSync(plistLocation).indexOf(receipt) > 0
);
}
return false;
};
const startLauncher = () => {
if (os.type() == 'Darwin') {
spawn('open', ['/Applications/Flipper.app']);
}
};
module.exports = function(argv) {
if (argv.launcher && isProduction() && isLauncherInstalled()) {
console.warn('Delegating to Flipper Launcher ...');
console.warn(
`You can disable this behavior by passing '--no-launcher' at startup.`,
);
startLauncher();
process.exit(0);
}
if (!process.env.ANDROID_HOME) {
process.env.ANDROID_HOME = '/opt/android_sdk';
}
// emulator/emulator is more reliable than tools/emulator, so prefer it if
// it exists
process.env.PATH = `${process.env.ANDROID_HOME}/emulator:${
process.env.ANDROID_HOME
}/tools:${process.env.PATH}`;
// ensure .flipper folder and config exist
const flipperDir = path.join(os.homedir(), '.flipper');
if (!fs.existsSync(flipperDir)) {
fs.mkdirSync(flipperDir);
}
const configPath = path.join(flipperDir, 'config.json');
let config = {
pluginPaths: [],
disabledPlugins: [],
lastWindowPosition: {},
};
try {
config = {
...config,
...JSON.parse(fs.readFileSync(configPath)),
};
} catch (e) {
// file not readable or not parsable, overwrite it with the new config
fs.writeFileSync(configPath, JSON.stringify(config));
}
// Non-persistent CLI arguments.
config = {
...config,
updaterEnabled: argv.updater,
launcherMsg: argv.launcherMsg,
};
return {config, configPath, flipperDir};
};