@@ -25,6 +25,8 @@ import { AuthenticationExt, AuthenticationMain, MAIN_RPC_CONTEXT } from '../../c
2525import { RPCProtocol } from '../../common/rpc-protocol' ;
2626import { MessageService } from '@theia/core/lib/common/message-service' ;
2727import { ConfirmDialog , Dialog , StorageService } from '@theia/core/lib/browser' ;
28+ import { Disposable } from '@theia/core/lib/common/disposable' ;
29+ import { Emitter , Event } from '@theia/core/lib/common/event' ;
2830import {
2931 AuthenticationProvider ,
3032 AuthenticationProviderSessionOptions ,
@@ -47,6 +49,7 @@ export class AuthenticationMainImpl implements AuthenticationMain {
4749 private readonly storageService : StorageService ;
4850 private readonly authenticationService : AuthenticationService ;
4951 private readonly quickPickService : QuickPickService ;
52+ private readonly providers : Map < string , AuthenticationProviderImpl > = new Map ( ) ;
5053 constructor ( rpc : RPCProtocol , container : interfaces . Container ) {
5154 this . proxy = rpc . getProxy ( MAIN_RPC_CONTEXT . AUTHENTICATION_EXT ) ;
5255 this . messageService = container . get ( MessageService ) ;
@@ -61,11 +64,15 @@ export class AuthenticationMainImpl implements AuthenticationMain {
6164
6265 async $registerAuthenticationProvider ( id : string , label : string , supportsMultipleAccounts : boolean ) : Promise < void > {
6366 const provider = new AuthenticationProviderImpl ( this . proxy , id , label , supportsMultipleAccounts , this . storageService , this . messageService ) ;
67+ this . providers . set ( id , provider ) ;
6468 this . authenticationService . registerAuthenticationProvider ( id , provider ) ;
6569 }
6670
6771 async $unregisterAuthenticationProvider ( id : string ) : Promise < void > {
6872 this . authenticationService . unregisterAuthenticationProvider ( id ) ;
73+ const provider = this . providers . get ( id ) ;
74+ provider ?. dispose ( ) ;
75+ this . providers . delete ( id ) ;
6976 }
7077
7178 async $updateSessions ( id : string , event : theia . AuthenticationProviderAuthenticationSessionsChangeEvent ) : Promise < void > {
@@ -248,7 +255,12 @@ export class AuthenticationMainImpl implements AuthenticationMain {
248255 }
249256
250257 $onDidChangeSessions ( providerId : string , event : theia . AuthenticationProviderAuthenticationSessionsChangeEvent ) : void {
251- this . authenticationService . updateSessions ( providerId , event ) ;
258+ const provider = this . providers . get ( providerId ) ;
259+ if ( provider ) {
260+ provider . fireSessionsChanged ( event ) ;
261+ } else {
262+ console . warn ( `No authentication provider found for id '${ providerId } ' when firing session change event.` ) ;
263+ }
252264 }
253265}
254266
@@ -284,13 +296,14 @@ interface AccountUsage {
284296 lastUsed : number ;
285297}
286298
287- export class AuthenticationProviderImpl implements AuthenticationProvider {
299+ export class AuthenticationProviderImpl implements AuthenticationProvider , Disposable {
288300 /** map from account name to session ids */
289301 private accounts = new Map < string , string [ ] > ( ) ;
290302 /** map from session id to account name */
291303 private sessions = new Map < string , string > ( ) ;
292304
293- readonly onDidChangeSessions : theia . Event < theia . AuthenticationProviderAuthenticationSessionsChangeEvent > ;
305+ private readonly onDidChangeSessionsEmitter = new Emitter < theia . AuthenticationProviderAuthenticationSessionsChangeEvent > ( ) ;
306+ readonly onDidChangeSessions : Event < theia . AuthenticationProviderAuthenticationSessionsChangeEvent > = this . onDidChangeSessionsEmitter . event ;
294307
295308 constructor (
296309 private readonly proxy : AuthenticationExt ,
@@ -301,6 +314,14 @@ export class AuthenticationProviderImpl implements AuthenticationProvider {
301314 private readonly messageService : MessageService
302315 ) { }
303316
317+ dispose ( ) : void {
318+ this . onDidChangeSessionsEmitter . dispose ( ) ;
319+ }
320+
321+ fireSessionsChanged ( event : theia . AuthenticationProviderAuthenticationSessionsChangeEvent ) : void {
322+ this . onDidChangeSessionsEmitter . fire ( event ) ;
323+ }
324+
304325 public hasSessions ( ) : boolean {
305326 return ! ! this . sessions . size ;
306327 }
0 commit comments