Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/vs/workbench/api/browser/mainThreadAuthentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,14 @@ export class MainThreadAuthenticationProvider extends Disposable {
private readonly notificationService: INotificationService
) {
super();
}

public async initialize(): Promise<void> {
return this.registerCommandsAndContextMenuItems();
}

this.registerCommandsAndContextMenuItems();
public hasSessions(): boolean {
return !!this._sessions.size;
}

private manageTrustedExtensions(quickInputService: IQuickInputService, storageService: IStorageService, accountName: string) {
Expand Down Expand Up @@ -310,6 +316,7 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu

async $registerAuthenticationProvider(id: string, displayName: string, supportsMultipleAccounts: boolean): Promise<void> {
const provider = new MainThreadAuthenticationProvider(this._proxy, id, displayName, supportsMultipleAccounts, this.notificationService);
await provider.initialize();
this.authenticationService.registerAuthenticationProvider(id, provider);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface IAuthenticationService {
export class AuthenticationService extends Disposable implements IAuthenticationService {
_serviceBrand: undefined;
private _placeholderMenuItem: IDisposable | undefined;
private _noAccountsMenuItem: IDisposable | undefined;

private _authenticationProviders: Map<string, MainThreadAuthenticationProvider> = new Map<string, MainThreadAuthenticationProvider>();

Expand All @@ -56,6 +57,28 @@ export class AuthenticationService extends Disposable implements IAuthentication
});
}

private updateAccountsMenuItem(): void {
let hasSession = false;
this._authenticationProviders.forEach(async provider => {
hasSession = hasSession || provider.hasSessions();
});

if (hasSession && this._noAccountsMenuItem) {
this._noAccountsMenuItem.dispose();
this._noAccountsMenuItem = undefined;
}

if (!hasSession && !this._noAccountsMenuItem) {
this._noAccountsMenuItem = MenuRegistry.appendMenuItem(MenuId.AccountsContext, {
group: '0_accounts',
command: {
id: 'noAccounts',
title: nls.localize('noAccounts', "You are not signed in to any accounts")
},
});
}
}

registerAuthenticationProvider(id: string, authenticationProvider: MainThreadAuthenticationProvider): void {
this._authenticationProviders.set(id, authenticationProvider);
this._onDidRegisterAuthenticationProvider.fire(id);
Expand All @@ -64,6 +87,8 @@ export class AuthenticationService extends Disposable implements IAuthentication
this._placeholderMenuItem.dispose();
this._placeholderMenuItem = undefined;
}

this.updateAccountsMenuItem();
}

unregisterAuthenticationProvider(id: string): void {
Expand All @@ -72,6 +97,7 @@ export class AuthenticationService extends Disposable implements IAuthentication
provider.dispose();
this._authenticationProviders.delete(id);
this._onDidUnregisterAuthenticationProvider.fire(id);
this.updateAccountsMenuItem();
}

if (!this._authenticationProviders.size) {
Expand All @@ -84,11 +110,12 @@ export class AuthenticationService extends Disposable implements IAuthentication
}
}

sessionsUpdate(id: string, event: AuthenticationSessionsChangeEvent): void {
async sessionsUpdate(id: string, event: AuthenticationSessionsChangeEvent): Promise<void> {
this._onDidChangeSessions.fire({ providerId: id, event: event });
const provider = this._authenticationProviders.get(id);
if (provider) {
provider.updateSessionItems(event);
await provider.updateSessionItems(event);
this.updateAccountsMenuItem();
}
}

Expand Down