diff --git a/src/vs/workbench/api/browser/mainThreadAuthentication.ts b/src/vs/workbench/api/browser/mainThreadAuthentication.ts index f6286c8656d..e426e5feae5 100644 --- a/src/vs/workbench/api/browser/mainThreadAuthentication.ts +++ b/src/vs/workbench/api/browser/mainThreadAuthentication.ts @@ -21,6 +21,8 @@ export class MainThreadAuthenticationProvider extends Disposable { private _accounts = new Map(); // Map account name to session ids private _sessions = new Map(); // Map account id to name + private _hasInitializedSessions = false; + constructor( private readonly _proxy: ExtHostAuthenticationShape, public readonly id: string, @@ -33,11 +35,6 @@ export class MainThreadAuthenticationProvider extends Disposable { ) { super(); } - - public async initialize(): Promise { - return this.registerCommandsAndContextMenuItems(); - } - public hasSessions(): boolean { return !!this._sessions.size; } @@ -83,15 +80,6 @@ export class MainThreadAuthenticationProvider extends Disposable { quickPick.show(); } - private async registerCommandsAndContextMenuItems(): Promise { - try { - const sessions = await this._proxy.$getSessions(this.id); - sessions.forEach(session => this.registerSession(session)); - } catch (_) { - // Ignore - } - } - private registerSession(session: modes.AuthenticationSession) { this._sessions.set(session.id, session.account.label); @@ -123,7 +111,13 @@ export class MainThreadAuthenticationProvider extends Disposable { } async getSessions(): Promise> { - return this._proxy.$getSessions(this.id); + const sessions = await this._proxy.$getSessions(this.id); + if (!this._hasInitializedSessions) { + sessions.forEach(session => this.registerSession(session)); + this._hasInitializedSessions = true; + } + + return sessions; } async updateSessionItems(event: modes.AuthenticationSessionsChangeEvent): Promise { @@ -195,7 +189,6 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu async $registerAuthenticationProvider(id: string, label: string, supportsMultipleAccounts: boolean): Promise { const provider = new MainThreadAuthenticationProvider(this._proxy, id, label, supportsMultipleAccounts, this.notificationService, this.storageService, this.quickInputService, this.dialogService); - await provider.initialize(); this.authenticationService.registerAuthenticationProvider(id, provider); } diff --git a/src/vs/workbench/browser/parts/activitybar/activitybarActions.ts b/src/vs/workbench/browser/parts/activitybar/activitybarActions.ts index 6fa9bb54cdf..7e1fd51d634 100644 --- a/src/vs/workbench/browser/parts/activitybar/activitybarActions.ts +++ b/src/vs/workbench/browser/parts/activitybar/activitybarActions.ts @@ -259,6 +259,11 @@ export class AccountsActivityActionViewItem extends MenuActivityActionViewItem { } }); + if (providers.length && !menus.length) { + const noAccountsAvailableAction = disposables.add(new Action('noAccountsAvailable', localize('noAccounts', "You are not signed in to any accounts"), undefined, false)); + menus.push(noAccountsAvailableAction); + } + if (menus.length && otherCommands.length) { menus.push(disposables.add(new Separator())); } diff --git a/src/vs/workbench/services/authentication/browser/authenticationService.ts b/src/vs/workbench/services/authentication/browser/authenticationService.ts index b91263aa5c6..a77ecf9c238 100644 --- a/src/vs/workbench/services/authentication/browser/authenticationService.ts +++ b/src/vs/workbench/services/authentication/browser/authenticationService.ts @@ -192,7 +192,6 @@ const authenticationExtPoint = ExtensionsRegistry.registerExtensionPoint(); private _sessionAccessRequestItems = new Map(); private _accountBadgeDisposable = this._register(new MutableDisposable()); @@ -278,29 +277,6 @@ export class AuthenticationService extends Disposable implements IAuthentication return this._authenticationProviders.has(id); } - 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"), - precondition: ContextKeyExpr.false() - }, - }); - } - } - registerAuthenticationProvider(id: string, authenticationProvider: MainThreadAuthenticationProvider): void { this._authenticationProviders.set(id, authenticationProvider); this._onDidRegisterAuthenticationProvider.fire({ id, label: authenticationProvider.label }); @@ -309,8 +285,6 @@ export class AuthenticationService extends Disposable implements IAuthentication this._placeholderMenuItem.dispose(); this._placeholderMenuItem = undefined; } - - this.updateAccountsMenuItem(); } unregisterAuthenticationProvider(id: string): void { @@ -319,7 +293,6 @@ export class AuthenticationService extends Disposable implements IAuthentication provider.dispose(); this._authenticationProviders.delete(id); this._onDidUnregisterAuthenticationProvider.fire({ id, label: provider.label }); - this.updateAccountsMenuItem(); const accessRequests = this._sessionAccessRequestItems.get(id) || {}; Object.keys(accessRequests).forEach(extensionId => { @@ -343,7 +316,6 @@ export class AuthenticationService extends Disposable implements IAuthentication if (provider) { this._onDidChangeSessions.fire({ providerId: id, label: provider.label, event: event }); await provider.updateSessionItems(event); - this.updateAccountsMenuItem(); if (event.added) { await this.updateNewSessionRequests(provider);