Fix error in legacyRegisterApi on main (#5426)

This commit is contained in:
Sebastian Malton authored and GitHub committed 2022-05-20 08:27:47 -04:00
1 parent d23f4018c8
commit acb119af94
1 file changed
+14 -3
+14 -3
View File
@@ -312,12 +312,23 @@ export interface DeleteResourceDescriptor extends ResourceDescriptor {
* @deprecated In the new extension API, don't expose `KubeApi`'s constructor
*/
function legacyRegisterApi(api: KubeApi<any, any>): void {
const di = getEnvironmentSpecificLegacyGlobalDiForExtensionApi(Environments.renderer);
if (di) {
try {
/**
* This function throws if called in `main`, so the `try..catch` is to make sure that doesn't
* leak.
*
* However, we need this code to be run in `renderer` so that the auto registering of `KubeApi`
* instances still works. That auto registering never worked or was applicable in `main` because
* there is no "single cluster" on `main`.
*
* TODO: rearchitect this design pattern in the new extension API
*/
const di = getEnvironmentSpecificLegacyGlobalDiForExtensionApi(Environments.renderer);
const autoRegistrationEmitter = di.inject(autoRegistrationEmitterInjectable);
autoRegistrationEmitter.emit("kubeApi", api);
} catch {
// ignore error
}
}