| 28 | |
| 29 | @injectable() |
| 30 | export class DefaultBrowserProvider implements IDefaultBrowserProvider { |
| 31 | constructor( |
| 32 | @inject(ExtensionLocation) private readonly location: ExtensionLocation, |
| 33 | @optional() @inject(VSCodeApi) private readonly vscode?: typeof vscodeType, |
| 34 | ) {} |
| 35 | |
| 36 | /** |
| 37 | * Cache the result of this function. This adds a few milliseconds |
| 38 | * (subprocesses out on all platforms) and people rarely change their |
| 39 | * default browser. |
| 40 | * @inheritdoc |
| 41 | */ |
| 42 | public lookup = once(async () => { |
| 43 | let name: string; |
| 44 | if (this.location === 'remote' && this.vscode) { |
| 45 | name = await this.vscode.commands.executeCommand('js-debug-companion.defaultBrowser'); |
| 46 | } else { |
| 47 | name = (await import('default-browser').then(d => d.default())).name; |
| 48 | } |
| 49 | |
| 50 | const match = [DefaultBrowser.Chrome, DefaultBrowser.Edge].find(browser => |
| 51 | name.toLowerCase().includes(browser) |
| 52 | ); |
| 53 | return match ?? DefaultBrowser.Other; |
| 54 | }); |
| 55 | } |
nothing calls this directly
no test coverage detected