Skip to content

Commit

Permalink
perf: check default paths first when running on Mac (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann authored Jun 26, 2020
1 parent aef9494 commit f3669f4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/chrome-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ const newLineRegex = /\r?\n/;

type Priorities = Array<{regex: RegExp, weight: number}>;

/**
* check for MacOS default app paths
*/
function getDarwinDefaultInstallations(): string[] {
// list of the possibilities in priority order
return [
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
'/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary'
].filter((path) => canAccess(path));
}

export function darwin() {
const suffixes = ['/Contents/MacOS/Google Chrome Canary', '/Contents/MacOS/Google Chrome'];

Expand All @@ -32,6 +43,19 @@ export function darwin() {
installations.push(customChromePath);
}

const defaultPaths = getDarwinDefaultInstallations()
if (defaultPaths.length) {
installations.push(...defaultPaths);
}

/**
* don't do expensive lsregister dump if we have already found
* a Chrome app by now
*/
if (installations.length) {
return installations
}

execSync(
`${LSREGISTER} -dump` +
' | grep -i \'google chrome\\( canary\\)\\?\\.app\'' +
Expand Down

0 comments on commit f3669f4

Please sign in to comment.