From 8e164973eed00025128d7c6917b7908fc06ac35a Mon Sep 17 00:00:00 2001 From: Amir Omidi Date: Wed, 8 Apr 2020 12:53:48 -0700 Subject: [PATCH] Login spinner (#9892) * Add a notification for handling logins * No need to catch and rethrow * Make it optional * use testNotificationService --- .../browser/accountManagementService.ts | 47 ++++++++++++------- .../browser/accountManagementService.test.ts | 5 +- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/sql/workbench/services/accountManagement/browser/accountManagementService.ts b/src/sql/workbench/services/accountManagement/browser/accountManagementService.ts index 4f42f48250..93718e1ae3 100644 --- a/src/sql/workbench/services/accountManagement/browser/accountManagementService.ts +++ b/src/sql/workbench/services/accountManagement/browser/accountManagementService.ts @@ -24,6 +24,7 @@ import { firstIndex } from 'vs/base/common/arrays'; import { values } from 'vs/base/common/collections'; import { onUnexpectedError } from 'vs/base/common/errors'; import { ILogService } from 'vs/platform/log/common/log'; +import { INotificationService, Severity, INotification } from 'vs/platform/notification/common/notification'; export class AccountManagementService implements IAccountManagementService { // CONSTANTS /////////////////////////////////////////////////////////// @@ -54,7 +55,8 @@ export class AccountManagementService implements IAccountManagementService { @IStorageService private _storageService: IStorageService, @IClipboardService private _clipboardService: IClipboardService, @IOpenerService private _openerService: IOpenerService, - @ILogService private readonly logService: ILogService + @ILogService private readonly _logService: ILogService, + @INotificationService private readonly _notificationService, ) { // Create the account store if (!this._mementoObj) { @@ -117,24 +119,35 @@ export class AccountManagementService implements IAccountManagementService { * @return Promise to return an account */ public addAccount(providerId: string): Thenable { - let self = this; + const loginNotification: INotification = { + severity: Severity.Info, + message: localize('loggingIn', "Adding account..."), + progress: { + infinite: true + } + }; return this.doWithProvider(providerId, async (provider) => { - let account = await provider.provider.prompt(); - if (self.isCanceledResult(account)) { - return; - } + const notificationHandler = this._notificationService.notify(loginNotification); + try { + let account = await provider.provider.prompt(); + if (this.isCanceledResult(account)) { + return; + } - let result = await self._accountStore.addOrUpdate(account); - if (result.accountAdded) { - // Add the account to the list - provider.accounts.push(result.changedAccount); - } - if (result.accountModified) { - self.spliceModifiedAccount(provider, result.changedAccount); - } + let result = await this._accountStore.addOrUpdate(account); + if (result.accountAdded) { + // Add the account to the list + provider.accounts.push(result.changedAccount); + } + if (result.accountModified) { + this.spliceModifiedAccount(provider, result.changedAccount); + } - self.fireAccountListUpdate(provider, result.accountAdded); + this.fireAccountListUpdate(provider, result.accountAdded); + } finally { + notificationHandler.close(); + } }); } @@ -268,7 +281,7 @@ export class AccountManagementService implements IAccountManagementService { for (const account of accounts) { const removeResult = await this.removeAccount(account.key); if (removeResult === false) { - this.logService.info('Error when removing %s.', account.key); + this._logService.info('Error when removing %s.', account.key); finalResult = false; } } @@ -324,7 +337,7 @@ export class AccountManagementService implements IAccountManagementService { this.doWithProvider(providerId, provider => provider.provider.autoOAuthCancelled()) .then( // Swallow errors null, - err => { this.logService.warn(`Error when cancelling auto OAuth: ${err}`); } + err => { this._logService.warn(`Error when cancelling auto OAuth: ${err}`); } ) .then(() => this.autoOAuthDialogController.closeAutoOAuthDialog()); } diff --git a/src/sql/workbench/services/accountManagement/test/browser/accountManagementService.test.ts b/src/sql/workbench/services/accountManagement/test/browser/accountManagementService.test.ts index 55852fa2c0..e732b527ca 100644 --- a/src/sql/workbench/services/accountManagement/test/browser/accountManagementService.test.ts +++ b/src/sql/workbench/services/accountManagement/test/browser/accountManagementService.test.ts @@ -15,6 +15,7 @@ import { AccountProviderStub } from 'sql/platform/accounts/test/common/testAccou import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService'; import { TestStorageService } from 'vs/workbench/test/common/workbenchTestServices'; import { EventVerifierSingle } from 'sql/base/test/common/event'; +import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService'; // SUITE CONSTANTS ///////////////////////////////////////////////////////// const hasAccountProvider: azdata.AccountProviderMetadata = { @@ -505,8 +506,10 @@ function getTestState(): AccountManagementState { // Create mock memento let mockMemento = {}; + const testNotificationService = new TestNotificationService(); + // Create the account management service - let ams = new AccountManagementService(mockMemento, mockInstantiationService.object, new TestStorageService(), null, null, undefined); + let ams = new AccountManagementService(mockMemento, mockInstantiationService.object, new TestStorageService(), null, null, undefined, testNotificationService); // Wire up event handlers let evUpdate = new EventVerifierSingle();