Skip to content

Commit 5bbb3d6

Browse files
committed
Updates change events for integrations in Home
1 parent 1a8975c commit 5bbb3d6

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

src/plus/integrations/authentication/configuredIntegrationService.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import type { Event } from 'vscode';
2+
import { EventEmitter } from 'vscode';
13
import type { IntegrationId } from '../../../constants.integrations';
24
import { HostingIntegrationId } from '../../../constants.integrations';
35
import type { StoredConfiguredIntegrationDescriptor } from '../../../constants.storage';
46
import type { Container } from '../../../container';
7+
import { debounce } from '../../../system/function';
58
import { flatten } from '../../../system/iterable';
69
import { getBuiltInIntegrationSession } from '../../gk/utils/-webview/integrationAuthentication.utils';
710
import { isSelfHostedIntegrationId, providersMetadata } from '../providers/models';
@@ -24,7 +27,16 @@ interface StoredSession {
2427

2528
export type ConfiguredIntegrationType = 'cloud' | 'local';
2629

30+
export interface ConfiguredIntegrationChangeEvent {
31+
ids: IntegrationId[];
32+
}
33+
2734
export 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

351377
function convertStoredSessionToSession(

src/plus/integrations/integrationService.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ import { filterMap, flatten, join } from '../../system/iterable';
2424
import { Logger } from '../../system/logger';
2525
import { getLogScope } from '../../system/logger.scope';
2626
import type { SubscriptionChangeEvent } from '../gk/subscriptionService';
27-
import type { ConfiguredIntegrationService } from './authentication/configuredIntegrationService';
27+
import type {
28+
ConfiguredIntegrationChangeEvent,
29+
ConfiguredIntegrationService,
30+
} from './authentication/configuredIntegrationService';
2831
import type { IntegrationAuthenticationService } from './authentication/integrationAuthenticationService';
2932
import type { ConfiguredIntegrationDescriptor } from './authentication/models';
3033
import {
@@ -69,6 +72,10 @@ export class IntegrationService implements Disposable {
6972
return this._onDidSyncCloudIntegrations.event;
7073
}
7174

75+
get onDidChangeConfiguredIntegrations(): Event<ConfiguredIntegrationChangeEvent> {
76+
return this.configuredIntegrationService.onDidChangeConfiguredIntegrations;
77+
}
78+
7279
private readonly _connectedCache = new Set<string>();
7380
private readonly _disposable: Disposable;
7481
private _integrations = new Map<IntegrationKey, Integration>();

src/webviews/home/homeWebview.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { showPatchesView } from '../../plus/drafts/actions';
4141
import type { Subscription } from '../../plus/gk/models/subscription';
4242
import type { SubscriptionChangeEvent } from '../../plus/gk/subscriptionService';
4343
import { isSubscriptionStatePaidOrTrial } from '../../plus/gk/utils/subscription.utils';
44+
import type { ConfiguredIntegrationChangeEvent } from '../../plus/integrations/authentication/configuredIntegrationService';
4445
import { providersMetadata } from '../../plus/integrations/providers/models';
4546
import type { LaunchpadCategorizedResult } from '../../plus/launchpad/launchpadProvider';
4647
import { getLaunchpadItemGroups } from '../../plus/launchpad/launchpadProvider';
@@ -157,7 +158,7 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
157158
: emptyDisposable,
158159
this.container.subscription.onDidChange(this.onSubscriptionChanged, this),
159160
onDidChangeContext(this.onContextChanged, this),
160-
this.container.integrations.onDidChangeConnectionState(this.onChangeConnectionState, this),
161+
this.container.integrations.onDidChangeConfiguredIntegrations(this.onChangeConnectionState, this),
161162
this.container.walkthrough.onProgressChanged(this.onWalkthroughChanged, this),
162163
configuration.onDidChange(this.onDidChangeConfig, this),
163164
this.container.launchpad.onDidChange(this.onDidLaunchpadChange, this),
@@ -217,7 +218,7 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
217218
this.notifyDidCompleteDiscoveringRepositories();
218219
}
219220

220-
private onChangeConnectionState() {
221+
private onChangeConnectionState(_e: ConfiguredIntegrationChangeEvent) {
221222
void this.notifyDidChangeIntegrations();
222223
}
223224

0 commit comments

Comments
 (0)