Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix static variables used in determineBrowserType #5919

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/razor/src/blazorDebug/blazorDebugConfigurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import showInformationMessage from '../../../shared/observers/utils/showInformat
import showErrorMessage from '../../../observers/utils/showErrorMessage';

export class BlazorDebugConfigurationProvider implements vscode.DebugConfigurationProvider {
private static readonly autoDetectUserNotice = `Run and Debug: auto-detection found {0} for a launch browser`;
private static readonly edgeBrowserType = 'msedge';
private static readonly chromeBrowserType = 'chrome';
private static readonly autoDetectUserNotice: string = `Run and Debug: auto-detection found {0} for a launch browser`;
private static readonly edgeBrowserType: string = 'msedge';
private static readonly chromeBrowserType: string = 'chrome';

constructor(private readonly logger: RazorLogger, private readonly vscodeType: typeof vscode) {}

Expand Down Expand Up @@ -172,21 +172,27 @@ export class BlazorDebugConfigurationProvider implements vscode.DebugConfigurati
}
}

public static async determineBrowserType() {
public static async determineBrowserType(): Promise<string | undefined> {
// There was no browser specified by the user, so we will do some auto-detection to find a browser,
// favoring chrome if multiple valid options are installed.
const chromeBrowserFinder = new ChromeBrowserFinder(process.env, promises, null);
const chromeInstallations = await chromeBrowserFinder.findAll();
if (chromeInstallations.length > 0) {
showInformationMessage(vscode, this.autoDetectUserNotice.replace('{0}', `'Chrome'`));
return this.chromeBrowserType;
showInformationMessage(
vscode,
BlazorDebugConfigurationProvider.autoDetectUserNotice.replace('{0}', `'Chrome'`)
);
return BlazorDebugConfigurationProvider.chromeBrowserType;
}

const edgeBrowserFinder = new EdgeBrowserFinder(process.env, promises, null);
const edgeInstallations = await edgeBrowserFinder.findAll();
if (edgeInstallations.length > 0) {
showInformationMessage(vscode, this.autoDetectUserNotice.replace('{0}', `'Edge'`));
return this.edgeBrowserType;
showInformationMessage(
vscode,
BlazorDebugConfigurationProvider.autoDetectUserNotice.replace('{0}', `'Edge'`)
);
return BlazorDebugConfigurationProvider.edgeBrowserType;
}

showErrorMessage(vscode, 'Run and Debug: A valid browser is not installed');
Expand Down