Files
flipper/static/setup.js
Pascal Hartig c0b5f10693 Add --launcher-msg option to pass to desktop app
Summary:
Allows the launcher to provide messages to the user. Currently, in the form
of the red notification bar at the bottom. This is just meant as a temporary measure
during the alpha to have some clearly noticeable way of getting the user's attention.

I consider removing this a blocker for the release as this mechanism is not well
suited for this in many ways.

The current use case for this is providing a warning if a cached version is used
instead of the requested one, e.g. "Could not fetch requested Flipper version 'deadbeef', using cached version instead."

Reviewed By: jknoxville, priteshrnandgaonkar

Differential Revision: D14073687

fbshipit-source-id: 85630347027063103315eeb1286731fe2478e261
2019-02-14 06:02:44 -08:00

84 lines
2.1 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 ...');
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};
};