(url: string, io?: AuthIo)
| 541 | } |
| 542 | |
| 543 | async function openBrowser(url: string, io?: AuthIo): Promise<void> { |
| 544 | if (io?.openBrowser) { |
| 545 | await io.openBrowser(url); |
| 546 | return; |
| 547 | } |
| 548 | const platform = process.platform; |
| 549 | try { |
| 550 | if (platform === 'darwin') { |
| 551 | await runCmd('open', [url], { allowFailure: true, timeoutMs: 5000 }); |
| 552 | } else if (platform === 'win32') { |
| 553 | await runCmd('cmd', ['/c', 'start', '', url], { allowFailure: true, timeoutMs: 5000 }); |
| 554 | } else { |
| 555 | await runCmd('xdg-open', [url], { allowFailure: true, timeoutMs: 5000 }); |
| 556 | } |
| 557 | } catch { |
| 558 | writeStderr(io, `Open this URL on your machine:\n${url}\n`); |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | function writeStderr(io: AuthIo | undefined, text: string): void { |
| 563 | (io?.stderr ?? process.stderr).write(text); |
no test coverage detected