Skip to content

Commit

Permalink
Just use the users default browser (react-native-community#1257)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrew Coates <[email protected]>
  • Loading branch information
acoates-ms and Andrew Coates authored Aug 26, 2020
1 parent fbfb055 commit 9bfe424
Showing 1 changed file with 1 addition and 65 deletions.
66 changes: 1 addition & 65 deletions packages/tools/src/launchDebugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,74 +7,10 @@
* @format
*/

import open from 'open';
import {execSync} from 'child_process';
import logger from './logger';
import launchDefaultBrowser from './launchDefaultBrowser';
import chalk from 'chalk';

function commandExistsUnixSync(commandName: string) {
try {
const stdout = execSync(
`command -v ${commandName} 2>/dev/null` +
` && { echo >&1 '${commandName} found'; exit 0; }`,
);
return !!stdout;
} catch (error) {
return false;
}
}

function getChromeAppName(): string {
switch (process.platform) {
case 'darwin':
return 'google chrome';
case 'win32': {
const possibleDebuggingApps = ['chrome.exe', 'msedge.exe'];
const output = execSync(
'tasklist /NH /FO CSV /FI "SESSIONNAME ne Services"',
).toString();
const runningProcesses = output
.split('\n')
.map((line: string) => line.replace(/^"|".*\r$/gm, ''));

for (const app of possibleDebuggingApps) {
if (runningProcesses.includes(app)) {
return app;
}
}
return 'chrome';
}
case 'linux':
if (commandExistsUnixSync('google-chrome')) {
return 'google-chrome';
}
if (commandExistsUnixSync('chromium-browser')) {
return 'chromium-browser';
}
return 'chromium';

default:
return 'google-chrome';
}
}

function launchChrome(url: string) {
return open(url, {app: [getChromeAppName()], wait: true});
}

async function launchDebugger(url: string) {
try {
await launchChrome(url);
} catch (error) {
logger.debug(error);
logger.info(
`For a better debugging experience please install Google Chrome from: ${chalk.underline.dim(
'https://www.google.com/chrome/',
)}`,
);
launchDefaultBrowser(url);
}
return launchDefaultBrowser(url);
}

export default launchDebugger;

0 comments on commit 9bfe424

Please sign in to comment.