Skip to content

Commit 2ffe187

Browse files
authored
[signing] Sigin: Offer manual fallback in case the extension can't open a browser (#119)
Tool: gitpod/catfood.gitpod.cloud
1 parent 08488a5 commit 2ffe187

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/authentication/gitpodServer.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ async function getUserInfo(token: string, serviceUrl: string, logger: ILogServic
2929
};
3030
}
3131

32+
const ACTION_COPY = 'Copy to clipboard';
33+
const ACTION_CANCEL = 'Cancel';
34+
3235
export default class GitpodServer extends Disposable {
3336

3437
public static AUTH_COMPLETE_PATH = '/complete-gitpod-auth';
@@ -76,8 +79,16 @@ export default class GitpodServer extends Disposable {
7679
location: vscode.ProgressLocation.Window,
7780
title: `Signing in to ${this._serviceUrl}...`,
7881
}, async () => {
79-
await vscode.env.openExternal(uri as any);
80-
// this._logger.trace(">> URL ", uri);
82+
const success = await vscode.env.openExternal(uri as any);
83+
if (!success) {
84+
// Handle the case where the extension can't open a browser window
85+
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);
86+
if (action === ACTION_COPY) {
87+
await vscode.env.clipboard.writeText(uri);
88+
} else if (action === ACTION_CANCEL) {
89+
throw new Error('Signin cancelled by user');
90+
}
91+
}
8192

8293
// Register a single listener for the URI callback, in case the user starts the login process multiple times
8394
// before completing it.

0 commit comments

Comments
 (0)