From b3e5bf6de206bd34060b7cc2f39fdeb26786e561 Mon Sep 17 00:00:00 2001 From: Rachel Macfarlane Date: Wed, 15 Apr 2020 17:10:53 -0700 Subject: [PATCH] Show confirmation dialog on sign out listing everything using the account --- .../api/browser/mainThreadAuthentication.ts | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/api/browser/mainThreadAuthentication.ts b/src/vs/workbench/api/browser/mainThreadAuthentication.ts index 0aedb3630e1..b3e79970032 100644 --- a/src/vs/workbench/api/browser/mainThreadAuthentication.ts +++ b/src/vs/workbench/api/browser/mainThreadAuthentication.ts @@ -150,6 +150,7 @@ export class MainThreadAuthenticationProvider extends Disposable { handler: (accessor, args) => { const quickInputService = accessor.get(IQuickInputService); const storageService = accessor.get(IStorageService); + const dialogService = accessor.get(IDialogService); const quickPick = quickInputService.createQuickPick(); const showUsage = nls.localize('showUsage', "Show Extensions and Features Using This Account"); @@ -162,8 +163,7 @@ export class MainThreadAuthenticationProvider extends Disposable { quickPick.onDidAccept(e => { const selected = quickPick.selectedItems[0]; if (selected.label === signOut) { - const sessionsForAccount = this._accounts.get(session.accountName); - sessionsForAccount?.forEach(sessionId => this.logout(sessionId)); + this.signOut(dialogService, session); } if (selected.label === manage) { @@ -188,6 +188,27 @@ export class MainThreadAuthenticationProvider extends Disposable { this._sessionMenuItems.set(session.accountName, [menuItem, manageCommand]); } + async signOut(dialogService: IDialogService, session: modes.AuthenticationSession): Promise { + const providerUsage = accountUsages.get(this.id); + const accountUsage = (providerUsage || {})[session.accountName] || []; + const sessionsForAccount = this._accounts.get(session.accountName); + + // Skip dialog if nothing is using the account + if (!accountUsage.length) { + sessionsForAccount?.forEach(sessionId => this.logout(sessionId)); + return; + } + + const result = await dialogService.confirm({ + title: nls.localize('signOutConfirm', "Sign out of {0}", session.accountName), + message: nls.localize('signOutMessage', "The account {0} is currently used by: \n\n{1}\n\n Sign out of these features?", session.accountName, accountUsage.join('\n')) + }); + + if (result.confirmed) { + sessionsForAccount?.forEach(sessionId => this.logout(sessionId)); + } + } + async getSessions(): Promise> { return (await this._proxy.$getSessions(this.id)).map(session => { return {