Login spinner (#9892)
* Add a notification for handling logins * No need to catch and rethrow * Make it optional * use testNotificationService
This commit is contained in:
Родитель
fca2344c2e
Коммит
8e164973ee
|
@ -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<void> {
|
||||
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());
|
||||
}
|
||||
|
|
|
@ -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<UpdateAccountListEventParams>();
|
||||
|
|
Загрузка…
Ссылка в новой задаче