Allow cancelling GitHub sign in, fixes #109101

This commit is contained in:
Rachel Macfarlane
2020-11-05 16:38:52 -08:00
parent 93d736db23
commit 4059ff428f
2 changed files with 16 additions and 3 deletions

View File

@@ -40,6 +40,15 @@ export async function activate(context: vscode.ExtensionContext) {
onDidChangeSessions.fire({ added: [session.id], removed: [], changed: [] });
return session;
} catch (e) {
// If login was cancelled, do not notify user.
if (e.message === 'Cancelled') {
/* __GDPR__
"loginCancelled" : { }
*/
telemetryReporter.sendTelemetryEvent('loginCancelled');
throw e;
}
/* __GDPR__
"loginFailed" : { }
*/

View File

@@ -23,7 +23,7 @@ class UriEventHandler extends vscode.EventEmitter<vscode.Uri> implements vscode.
export const uriHandler = new UriEventHandler;
const onDidManuallyProvideToken = new vscode.EventEmitter<string>();
const onDidManuallyProvideToken = new vscode.EventEmitter<string | undefined>();
@@ -91,7 +91,7 @@ export class GitHubServer {
return Promise.race([
existingPromise,
promiseFromEvent<string, string>(onDidManuallyProvideToken.event)
promiseFromEvent<string | undefined, string>(onDidManuallyProvideToken.event, (token: string | undefined): string => { if (!token) { throw new Error('Cancelled'); } return token; })
]).finally(() => {
this._pendingStates.delete(scopes);
this._codeExchangePromises.delete(scopes);
@@ -147,7 +147,11 @@ export class GitHubServer {
public async manuallyProvideToken() {
const uriOrToken = await vscode.window.showInputBox({ prompt: 'Token', ignoreFocusOut: true });
if (!uriOrToken) { return; }
if (!uriOrToken) {
onDidManuallyProvideToken.fire(undefined);
return;
}
try {
const uri = vscode.Uri.parse(uriOrToken);
if (!uri.scheme || uri.scheme === 'file') { throw new Error; }