From a41d8eb4f8126ec0c7323ac2ba8819689cbea0a6 Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Thu, 14 Feb 2019 02:24:35 -0800 Subject: [PATCH] Delegate to launcher app on startup Summary: For the production version, if the Launcher is installed and no `--no-launcher` (note the double-negation) is supplied, then let the launcher start the app instead. The launcher will pass the `--no-launcher` option back to prevent this from looping. Reviewed By: jknoxville Differential Revision: D14066620 fbshipit-source-id: 27d305efac36005e5e1082076829f10ef14aba0d --- static/setup.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/static/setup.js b/static/setup.js index 7bc8459ec..2d7429c32 100644 --- a/static/setup.js +++ b/static/setup.js @@ -8,8 +8,37 @@ 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'; }