mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-11 10:38:31 -05:00
Merge from vscode 073a24de05773f2261f89172987002dc0ae2f1cd (#9711)
This commit is contained in:
@@ -3,12 +3,14 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as nls from 'vs/nls';
|
||||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { AuthenticationSession } from 'vs/editor/common/modes';
|
||||
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { AuthenticationSession, AuthenticationSessionsChangeEvent } from 'vs/editor/common/modes';
|
||||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { MainThreadAuthenticationProvider } from 'vs/workbench/api/browser/mainThreadAuthentication';
|
||||
import { MenuRegistry, MenuId } from 'vs/platform/actions/common/actions';
|
||||
|
||||
export const IAuthenticationService = createDecorator<IAuthenticationService>('IAuthenticationService');
|
||||
|
||||
@@ -17,12 +19,12 @@ export interface IAuthenticationService {
|
||||
|
||||
registerAuthenticationProvider(id: string, provider: MainThreadAuthenticationProvider): void;
|
||||
unregisterAuthenticationProvider(id: string): void;
|
||||
sessionsUpdate(providerId: string): void;
|
||||
sessionsUpdate(providerId: string, event: AuthenticationSessionsChangeEvent): void;
|
||||
|
||||
readonly onDidRegisterAuthenticationProvider: Event<string>;
|
||||
readonly onDidUnregisterAuthenticationProvider: Event<string>;
|
||||
|
||||
readonly onDidChangeSessions: Event<string>;
|
||||
readonly onDidChangeSessions: Event<{ providerId: string, event: AuthenticationSessionsChangeEvent }>;
|
||||
getSessions(providerId: string): Promise<ReadonlyArray<AuthenticationSession> | undefined>;
|
||||
getDisplayName(providerId: string): string;
|
||||
login(providerId: string, scopes: string[]): Promise<AuthenticationSession>;
|
||||
@@ -31,6 +33,7 @@ export interface IAuthenticationService {
|
||||
|
||||
export class AuthenticationService extends Disposable implements IAuthenticationService {
|
||||
_serviceBrand: undefined;
|
||||
private _placeholderMenuItem: IDisposable | undefined;
|
||||
|
||||
private _authenticationProviders: Map<string, MainThreadAuthenticationProvider> = new Map<string, MainThreadAuthenticationProvider>();
|
||||
|
||||
@@ -40,25 +43,53 @@ export class AuthenticationService extends Disposable implements IAuthentication
|
||||
private _onDidUnregisterAuthenticationProvider: Emitter<string> = this._register(new Emitter<string>());
|
||||
readonly onDidUnregisterAuthenticationProvider: Event<string> = this._onDidUnregisterAuthenticationProvider.event;
|
||||
|
||||
private _onDidChangeSessions: Emitter<string> = this._register(new Emitter<string>());
|
||||
readonly onDidChangeSessions: Event<string> = this._onDidChangeSessions.event;
|
||||
private _onDidChangeSessions: Emitter<{ providerId: string, event: AuthenticationSessionsChangeEvent }> = this._register(new Emitter<{ providerId: string, event: AuthenticationSessionsChangeEvent }>());
|
||||
readonly onDidChangeSessions: Event<{ providerId: string, event: AuthenticationSessionsChangeEvent }> = this._onDidChangeSessions.event;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this._placeholderMenuItem = MenuRegistry.appendMenuItem(MenuId.AccountsContext, {
|
||||
command: {
|
||||
id: 'noAuthenticationProviders',
|
||||
title: nls.localize('noAuthenticationProviders', "No authentication providers registered")
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
registerAuthenticationProvider(id: string, authenticationProvider: MainThreadAuthenticationProvider): void {
|
||||
this._authenticationProviders.set(id, authenticationProvider);
|
||||
this._onDidRegisterAuthenticationProvider.fire(id);
|
||||
|
||||
if (authenticationProvider.dependents.length && this._placeholderMenuItem) {
|
||||
this._placeholderMenuItem.dispose();
|
||||
this._placeholderMenuItem = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
unregisterAuthenticationProvider(id: string): void {
|
||||
this._authenticationProviders.delete(id);
|
||||
this._onDidUnregisterAuthenticationProvider.fire(id);
|
||||
const provider = this._authenticationProviders.get(id);
|
||||
if (provider) {
|
||||
provider.dispose();
|
||||
this._authenticationProviders.delete(id);
|
||||
this._onDidUnregisterAuthenticationProvider.fire(id);
|
||||
}
|
||||
|
||||
if (!this._authenticationProviders.size) {
|
||||
this._placeholderMenuItem = MenuRegistry.appendMenuItem(MenuId.AccountsContext, {
|
||||
command: {
|
||||
id: 'noAuthenticationProviders',
|
||||
title: nls.localize('noAuthenticationProviders', "No authentication providers registered")
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
sessionsUpdate(id: string): void {
|
||||
this._onDidChangeSessions.fire(id);
|
||||
sessionsUpdate(id: string, event: AuthenticationSessionsChangeEvent): void {
|
||||
this._onDidChangeSessions.fire({ providerId: id, event: event });
|
||||
const provider = this._authenticationProviders.get(id);
|
||||
if (provider) {
|
||||
provider.updateSessionItems();
|
||||
}
|
||||
}
|
||||
|
||||
getDisplayName(id: string): string {
|
||||
|
||||
Reference in New Issue
Block a user