Skip to content

Commit

Permalink
support chrome dev/beta on macos
Browse files Browse the repository at this point in the history
For microsoft/vscode-js-debug#1489

Also, cache lsregister lookup since it's slow and we do it twice.
  • Loading branch information
connor4312 committed Dec 27, 2022
1 parent 3b6f80d commit 143c989
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
24 changes: 18 additions & 6 deletions src/darwinChrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ export class DarwinChromeBrowserFinder extends DarwinFinderBase {
},
];

/**
* @override
*/
public async findAll() {
const suffixes = ['/Contents/MacOS/Google Chrome Canary', '/Contents/MacOS/Google Chrome'];
protected override async findAllInner() {
const suffixes = [
'/Contents/MacOS/Google Chrome Canary',
'/Contents/MacOS/Google Chrome Beta',
'/Contents/MacOS/Google Chrome Dev',
'/Contents/MacOS/Google Chrome',
];
const defaultPaths = [
'/Applications/Google Chrome.app',
'/Applications/Google Chrome Canary.app',
];
const installations = await this.findLaunchRegisteredApps(
'google chrome\\( canary\\)\\?.app',
'google chrome[A-Za-z() ]*.app',
defaultPaths,
suffixes,
);
Expand All @@ -60,6 +62,16 @@ export class DarwinChromeBrowserFinder extends DarwinFinderBase {
weight: 1,
quality: Quality.Canary,
},
{
name: 'Chrome Beta.app',
weight: 2,
quality: Quality.Beta,
},
{
name: 'Chrome Dev.app',
weight: 3,
quality: Quality.Dev,
},
]),
);
}
Expand Down
5 changes: 1 addition & 4 deletions src/darwinEdge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ export class DarwinEdgeBrowserFinder extends DarwinFinderBase {
},
];

/**
* @override
*/
public async findAll() {
protected override async findAllInner() {
const suffixes = [
'/Contents/MacOS/Microsoft Edge Canary',
'/Contents/MacOS/Microsoft Edge Beta',
Expand Down
16 changes: 14 additions & 2 deletions src/darwinFinderBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export abstract class DarwinFinderBase implements IBrowserFinder {
*/
protected wellKnownPaths: ReadonlyArray<IExecutable> = [];

private foundAll: Promise<IExecutable[]> | undefined;

constructor(
protected readonly env: NodeJS.ProcessEnv,
private readonly fs: typeof fsPromises,
Expand All @@ -48,7 +50,15 @@ export abstract class DarwinFinderBase implements IBrowserFinder {
/**
* @inheritdoc
*/
public abstract findAll(): Promise<IExecutable[]>;
public findAll(): Promise<IExecutable[]> {
this.foundAll ??= this.findAllInner();
return this.foundAll;
}

/**
* findAll implementation. Cached.
*/
protected abstract findAllInner(): Promise<IExecutable[]>;

/**
* Returns the environment-configured custom path, if any.
Expand All @@ -64,7 +74,9 @@ export abstract class DarwinFinderBase implements IBrowserFinder {
suffixes: ReadonlyArray<string>,
) {
const { stdout } = await this.execa.command(
`${this.lsRegisterCommand} | awk '$0 ~ /${pattern}${pathSuffixRe.source}?$/ { $1=""; print $0 }'`,
`${this.lsRegisterCommand} | awk 'tolower($0) ~ /${pattern.toLowerCase()}${
pathSuffixRe.source
}?$/ { $1=""; print $0 }'`,
{ shell: true, stdio: 'pipe' },
);

Expand Down

0 comments on commit 143c989

Please sign in to comment.