Skip to content

Commit

Permalink
chore: add a way to get provider info from internal provider id (podm…
Browse files Browse the repository at this point in the history
…an-desktop#10212)

* chore: add a way to get provider name from internal provider id
Signed-off-by: Sonia Sandler <[email protected]>
  • Loading branch information
SoniaSandler authored Dec 4, 2024
1 parent decd066 commit 9cc50fa
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 17 deletions.
30 changes: 30 additions & 0 deletions packages/main/src/plugin/provider-registry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1241,3 +1241,33 @@ describe('shellInProviderConnection', () => {
expect(closeMock).toBeCalled();
});
});

test('should retrieve provider info from provider internal id', async () => {
providerRegistry.createProvider('id1', 'name1', {
id: 'internal1',
name: 'internal1name',
status: 'installed',
});

providerRegistry.createProvider('id2', 'name2', {
id: 'internal2',
name: 'internal2name',
status: 'installed',
});

const provider1 = providerRegistry.getProviderInfo('0');
const provider2 = providerRegistry.getProviderInfo('1');
const provider3 = providerRegistry.getProviderInfo('2');

expect(provider1).toBeDefined();
expect(provider2).toBeDefined();
expect(provider3).toBeUndefined();

expect(provider1?.id).toBe('internal1');
expect(provider1?.name).toBe('internal1name');
expect(provider1?.extensionId).toBe('id1');

expect(provider2?.id).toBe('internal2');
expect(provider2?.name).toBe('internal2name');
expect(provider2?.extensionId).toBe('id2');
});
42 changes: 25 additions & 17 deletions packages/main/src/plugin/provider-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class ProviderRegistry {
// If the status does not match the current one, we will send a listener event and update the status
if (status !== this.providerStatuses.get(providerKey)) {
provider.updateStatus(status);
this.listeners.forEach(listener => listener('provider:update-status', this.getProviderInfo(provider)));
this.listeners.forEach(listener => listener('provider:update-status', this.toProviderInfo(provider)));
this.providerStatuses.set(providerKey, status);
}
}
Expand Down Expand Up @@ -197,7 +197,7 @@ export class ProviderRegistry {
);
this.count++;
this.providers.set(id, providerImpl);
this.listeners.forEach(listener => listener('provider:create', this.getProviderInfo(providerImpl)));
this.listeners.forEach(listener => listener('provider:create', this.toProviderInfo(providerImpl)));
const trackOpts: { name: string; status: string; version?: string } = {
name: providerOptions.name,
status: providerOptions.status.toString(),
Expand All @@ -213,7 +213,7 @@ export class ProviderRegistry {

disposeProvider(providerImpl: ProviderImpl): void {
this.providers.delete(providerImpl.internalId);
this.listeners.forEach(listener => listener('provider:delete', this.getProviderInfo(providerImpl)));
this.listeners.forEach(listener => listener('provider:delete', this.toProviderInfo(providerImpl)));
this.apiSender.send('provider-delete', providerImpl.id);
}

Expand All @@ -223,14 +223,14 @@ export class ProviderRegistry {
this.providerLifecycleContexts.set(providerImpl.internalId, new LifecycleContextImpl());

this.lifecycleListeners.forEach(listener =>
listener('provider:register-lifecycle', this.getProviderInfo(providerImpl), lifecycle),
listener('provider:register-lifecycle', this.toProviderInfo(providerImpl), lifecycle),
);

return Disposable.create(() => {
this.providerLifecycles.delete(providerImpl.internalId);
this.providerLifecycleContexts.delete(providerImpl.internalId);
this.lifecycleListeners.forEach(listener =>
listener('provider:removal-lifecycle', this.getProviderInfo(providerImpl), lifecycle),
listener('provider:removal-lifecycle', this.toProviderInfo(providerImpl), lifecycle),
);
});
}
Expand Down Expand Up @@ -335,12 +335,12 @@ export class ProviderRegistry {
}

this.lifecycleListeners.forEach(listener =>
listener('provider:before-initialize-lifecycle', this.getProviderInfo(provider), providerLifecycle),
listener('provider:before-initialize-lifecycle', this.toProviderInfo(provider), providerLifecycle),
);

await providerLifecycle.initialize(context);
this.lifecycleListeners.forEach(listener =>
listener('provider:after-initialize-lifecycle', this.getProviderInfo(provider), providerLifecycle),
listener('provider:after-initialize-lifecycle', this.toProviderInfo(provider), providerLifecycle),
);
}

Expand All @@ -350,12 +350,12 @@ export class ProviderRegistry {
const context = this.getMatchingLifecycleContext(providerId);

this.lifecycleListeners.forEach(listener =>
listener('provider:before-start-lifecycle', this.getProviderInfo(provider), providerLifecycle),
listener('provider:before-start-lifecycle', this.toProviderInfo(provider), providerLifecycle),
);

await providerLifecycle.start(context);
this.lifecycleListeners.forEach(listener =>
listener('provider:after-start-lifecycle', this.getProviderInfo(provider), providerLifecycle),
listener('provider:after-start-lifecycle', this.toProviderInfo(provider), providerLifecycle),
);
this._onDidUpdateProvider.fire({
id: providerId,
Expand All @@ -370,11 +370,11 @@ export class ProviderRegistry {
const context = this.getMatchingLifecycleContext(providerId);

this.lifecycleListeners.forEach(listener =>
listener('provider:before-stop-lifecycle', this.getProviderInfo(provider), providerLifecycle),
listener('provider:before-stop-lifecycle', this.toProviderInfo(provider), providerLifecycle),
);
await providerLifecycle.stop(context);
this.lifecycleListeners.forEach(listener =>
listener('provider:after-stop-lifecycle', this.getProviderInfo(provider), providerLifecycle),
listener('provider:after-stop-lifecycle', this.toProviderInfo(provider), providerLifecycle),
);
this._onDidUpdateProvider.fire({
id: providerId,
Expand Down Expand Up @@ -684,7 +684,7 @@ export class ProviderRegistry {
return providerConnection;
}

protected getProviderInfo(provider: ProviderImpl): ProviderInfo {
protected toProviderInfo(provider: ProviderImpl): ProviderInfo {
const containerConnections: ProviderContainerConnectionInfo[] = provider.containerConnections.map(connection => {
return this.getProviderContainerConnectionInfo(connection);
});
Expand Down Expand Up @@ -780,7 +780,7 @@ export class ProviderRegistry {
getProviderInfos(): ProviderInfo[] {
return Array.from(this.providers.values())
.map(provider => {
return this.getProviderInfo(provider);
return this.toProviderInfo(provider);
})
.sort((provider1, provider2) => provider2.name.localeCompare(provider1.name));
}
Expand Down Expand Up @@ -1157,7 +1157,7 @@ export class ProviderRegistry {
this.containerConnectionLifecycleListeners.forEach(listener => {
listener(
'provider-container-connection:register',
this.getProviderInfo(provider),
this.toProviderInfo(provider),
this.getProviderContainerConnectionInfo(containerProviderConnection),
);
});
Expand All @@ -1181,7 +1181,7 @@ export class ProviderRegistry {
this.containerConnectionLifecycleListeners.forEach(listener => {
listener(
'provider-container-connection:update-status',
this.getProviderInfo(provider),
this.toProviderInfo(provider),
this.getProviderContainerConnectionInfo(containerConnection),
);
});
Expand All @@ -1195,7 +1195,7 @@ export class ProviderRegistry {
this.containerConnectionLifecycleListeners.forEach(listener => {
listener(
'provider-container-connection:unregister',
this.getProviderInfo(provider),
this.toProviderInfo(provider),
this.getProviderContainerConnectionInfo(containerConnection),
);
});
Expand All @@ -1215,7 +1215,7 @@ export class ProviderRegistry {
const provider = this.getMatchingProvider(providerId);

provider.onDidUpdateStatus(() => {
callback(this.getProviderInfo(provider));
callback(this.toProviderInfo(provider));
});

this._onDidUpdateProvider.fire({
Expand Down Expand Up @@ -1325,4 +1325,12 @@ export class ProviderRegistry {
throw error;
}
}

getProviderInfo(internalProviderId: string): ProviderInfo | undefined {
const provider = this.providers.get(internalProviderId);
if (provider) {
return this.toProviderInfo(provider);
}
return undefined;
}
}

0 comments on commit 9cc50fa

Please sign in to comment.