diff --git a/src/authentication/gitpodServer.ts b/src/authentication/gitpodServer.ts index f43357c..fea7485 100644 --- a/src/authentication/gitpodServer.ts +++ b/src/authentication/gitpodServer.ts @@ -29,6 +29,9 @@ async function getUserInfo(token: string, serviceUrl: string, logger: ILogServic }; } +const ACTION_COPY = 'Copy to clipboard'; +const ACTION_CANCEL = 'Cancel'; + export default class GitpodServer extends Disposable { public static AUTH_COMPLETE_PATH = '/complete-gitpod-auth'; @@ -76,8 +79,16 @@ export default class GitpodServer extends Disposable { location: vscode.ProgressLocation.Window, title: `Signing in to ${this._serviceUrl}...`, }, async () => { - await vscode.env.openExternal(uri as any); - // this._logger.trace(">> URL ", uri); + const success = await vscode.env.openExternal(uri as any); + if (!success) { + // Handle the case where the extension can't open a browser window + const action = await vscode.window.showWarningMessage('There was a problem opening the login URL in your browser. Please copy it into your browser manually.', ACTION_COPY, ACTION_CANCEL); + if (action === ACTION_COPY) { + await vscode.env.clipboard.writeText(uri); + } else if (action === ACTION_CANCEL) { + throw new Error('Signin cancelled by user'); + } + } // Register a single listener for the URI callback, in case the user starts the login process multiple times // before completing it.