mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
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:
@@ -24,6 +24,7 @@ import { firstIndex } from 'vs/base/common/arrays';
|
|||||||
import { values } from 'vs/base/common/collections';
|
import { values } from 'vs/base/common/collections';
|
||||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||||
import { ILogService } from 'vs/platform/log/common/log';
|
import { ILogService } from 'vs/platform/log/common/log';
|
||||||
|
import { INotificationService, Severity, INotification } from 'vs/platform/notification/common/notification';
|
||||||
|
|
||||||
export class AccountManagementService implements IAccountManagementService {
|
export class AccountManagementService implements IAccountManagementService {
|
||||||
// CONSTANTS ///////////////////////////////////////////////////////////
|
// CONSTANTS ///////////////////////////////////////////////////////////
|
||||||
@@ -54,7 +55,8 @@ export class AccountManagementService implements IAccountManagementService {
|
|||||||
@IStorageService private _storageService: IStorageService,
|
@IStorageService private _storageService: IStorageService,
|
||||||
@IClipboardService private _clipboardService: IClipboardService,
|
@IClipboardService private _clipboardService: IClipboardService,
|
||||||
@IOpenerService private _openerService: IOpenerService,
|
@IOpenerService private _openerService: IOpenerService,
|
||||||
@ILogService private readonly logService: ILogService
|
@ILogService private readonly _logService: ILogService,
|
||||||
|
@INotificationService private readonly _notificationService,
|
||||||
) {
|
) {
|
||||||
// Create the account store
|
// Create the account store
|
||||||
if (!this._mementoObj) {
|
if (!this._mementoObj) {
|
||||||
@@ -117,24 +119,35 @@ export class AccountManagementService implements IAccountManagementService {
|
|||||||
* @return Promise to return an account
|
* @return Promise to return an account
|
||||||
*/
|
*/
|
||||||
public addAccount(providerId: string): Thenable<void> {
|
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) => {
|
return this.doWithProvider(providerId, async (provider) => {
|
||||||
|
const notificationHandler = this._notificationService.notify(loginNotification);
|
||||||
|
try {
|
||||||
let account = await provider.provider.prompt();
|
let account = await provider.provider.prompt();
|
||||||
if (self.isCanceledResult(account)) {
|
if (this.isCanceledResult(account)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = await self._accountStore.addOrUpdate(account);
|
let result = await this._accountStore.addOrUpdate(account);
|
||||||
if (result.accountAdded) {
|
if (result.accountAdded) {
|
||||||
// Add the account to the list
|
// Add the account to the list
|
||||||
provider.accounts.push(result.changedAccount);
|
provider.accounts.push(result.changedAccount);
|
||||||
}
|
}
|
||||||
if (result.accountModified) {
|
if (result.accountModified) {
|
||||||
self.spliceModifiedAccount(provider, result.changedAccount);
|
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) {
|
for (const account of accounts) {
|
||||||
const removeResult = await this.removeAccount(account.key);
|
const removeResult = await this.removeAccount(account.key);
|
||||||
if (removeResult === false) {
|
if (removeResult === false) {
|
||||||
this.logService.info('Error when removing %s.', account.key);
|
this._logService.info('Error when removing %s.', account.key);
|
||||||
finalResult = false;
|
finalResult = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -324,7 +337,7 @@ export class AccountManagementService implements IAccountManagementService {
|
|||||||
this.doWithProvider(providerId, provider => provider.provider.autoOAuthCancelled())
|
this.doWithProvider(providerId, provider => provider.provider.autoOAuthCancelled())
|
||||||
.then( // Swallow errors
|
.then( // Swallow errors
|
||||||
null,
|
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());
|
.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 { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
|
||||||
import { TestStorageService } from 'vs/workbench/test/common/workbenchTestServices';
|
import { TestStorageService } from 'vs/workbench/test/common/workbenchTestServices';
|
||||||
import { EventVerifierSingle } from 'sql/base/test/common/event';
|
import { EventVerifierSingle } from 'sql/base/test/common/event';
|
||||||
|
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
|
||||||
|
|
||||||
// SUITE CONSTANTS /////////////////////////////////////////////////////////
|
// SUITE CONSTANTS /////////////////////////////////////////////////////////
|
||||||
const hasAccountProvider: azdata.AccountProviderMetadata = {
|
const hasAccountProvider: azdata.AccountProviderMetadata = {
|
||||||
@@ -505,8 +506,10 @@ function getTestState(): AccountManagementState {
|
|||||||
// Create mock memento
|
// Create mock memento
|
||||||
let mockMemento = {};
|
let mockMemento = {};
|
||||||
|
|
||||||
|
const testNotificationService = new TestNotificationService();
|
||||||
|
|
||||||
// Create the account management service
|
// 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
|
// Wire up event handlers
|
||||||
let evUpdate = new EventVerifierSingle<UpdateAccountListEventParams>();
|
let evUpdate = new EventVerifierSingle<UpdateAccountListEventParams>();
|
||||||
|
|||||||
Reference in New Issue
Block a user