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
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import type { Event } from 'vscode';
import { EventEmitter } from 'vscode';
import type { IntegrationId } from '../../../constants.integrations';
import { HostingIntegrationId } from '../../../constants.integrations';
import type { StoredConfiguredIntegrationDescriptor } from '../../../constants.storage';
import type { Container } from '../../../container';
import { debounce } from '../../../system/function';
import { flatten } from '../../../system/iterable';
import { getBuiltInIntegrationSession } from '../../gk/utils/-webview/integrationAuthentication.utils';
import { isSelfHostedIntegrationId, providersMetadata } from '../providers/models';
Expand All @@ -24,7 +27,16 @@ interface StoredSession {

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

export interface ConfiguredIntegrationsChangeEvent {
ids: IntegrationId[];
}

export class ConfiguredIntegrationService {
private readonly _onDidChange = new EventEmitter<ConfiguredIntegrationsChangeEvent>();
get onDidChange(): Event<ConfiguredIntegrationsChangeEvent> {
return this._onDidChange.event;
}

private _configured?: Map<IntegrationId, ConfiguredIntegrationDescriptor[]>;

constructor(private readonly container: Container) {}
Expand Down Expand Up @@ -165,6 +177,7 @@ export class ConfiguredIntegrationService {

descriptors.push(descriptor);
this.configured.set(descriptor.integrationId, descriptors);
this.queueDidChange(descriptor.integrationId);
await this.storeConfigured();
}

Expand All @@ -187,6 +200,7 @@ export class ConfiguredIntegrationService {
}

this.configured.set(id, descriptors ?? []);
this.queueDidChange(id);
await this.storeConfigured();
}

Expand Down Expand Up @@ -346,6 +360,18 @@ export class ConfiguredIntegrationService {
getSessionId(descriptor: IntegrationAuthenticationSessionDescriptor): string {
return descriptor.domain;
}

private changedIds = new Set<IntegrationId>();
private debouncedFireDidChange?: () => void;
private queueDidChange(id: IntegrationId) {
this.debouncedFireDidChange ??= debounce(() => {
this._onDidChange.fire({ ids: [...this.changedIds] });
this.changedIds.clear();
}, 300);

this.changedIds.add(id);
this.debouncedFireDidChange();
}
}

function convertStoredSessionToSession(
Expand Down
9 changes: 8 additions & 1 deletion src/plus/integrations/integrationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import { filterMap, flatten, join } from '../../system/iterable';
import { Logger } from '../../system/logger';
import { getLogScope } from '../../system/logger.scope';
import type { SubscriptionChangeEvent } from '../gk/subscriptionService';
import type { ConfiguredIntegrationService } from './authentication/configuredIntegrationService';
import type {
ConfiguredIntegrationsChangeEvent,
ConfiguredIntegrationService,
} from './authentication/configuredIntegrationService';
import type { IntegrationAuthenticationService } from './authentication/integrationAuthenticationService';
import type { ConfiguredIntegrationDescriptor } from './authentication/models';
import {
Expand Down Expand Up @@ -69,6 +72,10 @@ export class IntegrationService implements Disposable {
return this._onDidSyncCloudIntegrations.event;
}

get onDidChangeConfiguredIntegrations(): Event<ConfiguredIntegrationsChangeEvent> {
return this.configuredIntegrationService.onDidChange;
}

private readonly _connectedCache = new Set<string>();
private readonly _disposable: Disposable;
private _integrations = new Map<IntegrationKey, Integration>();
Expand Down
5 changes: 3 additions & 2 deletions src/webviews/home/homeWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { showPatchesView } from '../../plus/drafts/actions';
import type { Subscription } from '../../plus/gk/models/subscription';
import type { SubscriptionChangeEvent } from '../../plus/gk/subscriptionService';
import { isSubscriptionStatePaidOrTrial } from '../../plus/gk/utils/subscription.utils';
import type { ConfiguredIntegrationsChangeEvent } from '../../plus/integrations/authentication/configuredIntegrationService';
import { providersMetadata } from '../../plus/integrations/providers/models';
import type { LaunchpadCategorizedResult } from '../../plus/launchpad/launchpadProvider';
import { getLaunchpadItemGroups } from '../../plus/launchpad/launchpadProvider';
Expand Down Expand Up @@ -157,7 +158,7 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
: emptyDisposable,
this.container.subscription.onDidChange(this.onSubscriptionChanged, this),
onDidChangeContext(this.onContextChanged, this),
this.container.integrations.onDidChangeConnectionState(this.onChangeConnectionState, this),
this.container.integrations.onDidChangeConfiguredIntegrations(this.onChangeConnectionState, this),
this.container.walkthrough.onProgressChanged(this.onWalkthroughChanged, this),
configuration.onDidChange(this.onDidChangeConfig, this),
this.container.launchpad.onDidChange(this.onDidLaunchpadChange, this),
Expand Down Expand Up @@ -217,7 +218,7 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
this.notifyDidCompleteDiscoveringRepositories();
}

private onChangeConnectionState() {
private onChangeConnectionState(_e: ConfiguredIntegrationsChangeEvent) {
void this.notifyDidChangeIntegrations();
}

Expand Down