Summary: Changes where we delegate to the launcher to a later point so we can successfully intercept file open events and custom URI events. There's more information in Phase 1 in this paragraph of the doc: https://fb.quip.com/tpqnAbxnJw1w#UNZACAnVVGs Reviewed By: danielbuechele Differential Revision: D14563585 fbshipit-source-id: a8757a6072386e56102f15b0668456369a44aad7
57 lines
1.4 KiB
JavaScript
57 lines
1.4 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 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 = argv => {
|
|
const args = [];
|
|
if (argv.file) {
|
|
args.push('--file', argv.file);
|
|
}
|
|
if (argv.url) {
|
|
args.push('--url', argv.url);
|
|
}
|
|
if (os.type() == 'Darwin') {
|
|
spawn('open', ['/Applications/Flipper.app', '--args'].concat(args));
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Runs the launcher if required and returns a boolean based on whether
|
|
* it has. You should shut down this instance of the app in that case.
|
|
*/
|
|
module.exports = function delegateToLauncher(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(argv);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
};
|