1+ import type { Event } from 'vscode' ;
2+ import { EventEmitter } from 'vscode' ;
13import type { IntegrationId } from '../../../constants.integrations' ;
24import { HostingIntegrationId } from '../../../constants.integrations' ;
35import type { StoredConfiguredIntegrationDescriptor } from '../../../constants.storage' ;
46import type { Container } from '../../../container' ;
7+ import { debounce } from '../../../system/function' ;
58import { flatten } from '../../../system/iterable' ;
69import { getBuiltInIntegrationSession } from '../../gk/utils/-webview/integrationAuthentication.utils' ;
710import { isSelfHostedIntegrationId , providersMetadata } from '../providers/models' ;
@@ -24,7 +27,16 @@ interface StoredSession {
2427
2528export type ConfiguredIntegrationType = 'cloud' | 'local' ;
2629
30+ export interface ConfiguredIntegrationChangeEvent {
31+ ids : IntegrationId [ ] ;
32+ }
33+
2734export class ConfiguredIntegrationService {
35+ private readonly _onDidChangeConfiguredIntegrations = new EventEmitter < ConfiguredIntegrationChangeEvent > ( ) ;
36+ get onDidChangeConfiguredIntegrations ( ) : Event < ConfiguredIntegrationChangeEvent > {
37+ return this . _onDidChangeConfiguredIntegrations . event ;
38+ }
39+
2840 private _configured ?: Map < IntegrationId , ConfiguredIntegrationDescriptor [ ] > ;
2941
3042 constructor ( private readonly container : Container ) { }
@@ -165,6 +177,7 @@ export class ConfiguredIntegrationService {
165177
166178 descriptors . push ( descriptor ) ;
167179 this . configured . set ( descriptor . integrationId , descriptors ) ;
180+ this . queueDidChange ( descriptor . integrationId ) ;
168181 await this . storeConfigured ( ) ;
169182 }
170183
@@ -187,6 +200,7 @@ export class ConfiguredIntegrationService {
187200 }
188201
189202 this . configured . set ( id , descriptors ?? [ ] ) ;
203+ this . queueDidChange ( id ) ;
190204 await this . storeConfigured ( ) ;
191205 }
192206
@@ -346,6 +360,18 @@ export class ConfiguredIntegrationService {
346360 getSessionId ( descriptor : IntegrationAuthenticationSessionDescriptor ) : string {
347361 return descriptor . domain ;
348362 }
363+
364+ private changedIds = new Set < IntegrationId > ( ) ;
365+ private debouncedFireDidChange ?: ( ) => void ;
366+ private queueDidChange ( id : IntegrationId ) {
367+ this . debouncedFireDidChange ??= debounce ( ( ) => {
368+ this . _onDidChangeConfiguredIntegrations . fire ( { ids : [ ...this . changedIds ] } ) ;
369+ this . changedIds . clear ( ) ;
370+ } , 300 ) ;
371+
372+ this . changedIds . add ( id ) ;
373+ this . debouncedFireDidChange ( ) ;
374+ }
349375}
350376
351377function convertStoredSessionToSession (
0 commit comments