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
18 changes: 14 additions & 4 deletions packages/extension/src/dashboard-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
***********************************************************************/

import type { WebviewPanel, ExtensionContext, KubeconfigUpdateEvent } from '@podman-desktop/api';
import { kubernetes, Uri, window } from '@podman-desktop/api';
import { env, kubernetes, Uri, window } from '@podman-desktop/api';

import { RpcExtension } from '/@common/rpc/rpc';

Expand All @@ -26,9 +26,15 @@ import { ContextsManager } from './manager/contexts-manager';
import { existsSync } from 'node:fs';
import { KubeConfig } from '@kubernetes/client-node';
import { ContextsStatesDispatcher } from './manager/contexts-states-dispatcher';
import { InversifyBinding } from './inject/inversify-binding';
import type { Container } from 'inversify';

export class DashboardExtension {
#container: Container | undefined;
#inversifyBinding: InversifyBinding | undefined;

#extensionContext: ExtensionContext;

#contextsManager: ContextsManager;
#contextsStatesDispatcher: ContextsStatesDispatcher;

Expand All @@ -37,17 +43,21 @@ export class DashboardExtension {
}

async activate(): Promise<void> {
const telemetryLogger = env.createTelemetryLogger();

const panel = await this.createWebview();

// Register webview communication for this webview
const rpcExtension = new RpcExtension(panel.webview);
rpcExtension.init();
this.#extensionContext.subscriptions.push(rpcExtension);

this.#contextsManager = new ContextsManager();
this.#contextsStatesDispatcher = new ContextsStatesDispatcher(this.#contextsManager, rpcExtension);

const now = performance.now();
this.#inversifyBinding = new InversifyBinding(rpcExtension, this.extensionContext, telemetryLogger);
this.#container = await this.#inversifyBinding.initBindings();

this.#contextsManager = await this.#container.getAsync(ContextsManager);
this.#contextsStatesDispatcher = await this.#container.getAsync(ContextsStatesDispatcher);

const afterFirst = performance.now();

Expand Down
64 changes: 64 additions & 0 deletions packages/extension/src/inject/inversify-binding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**********************************************************************
* Copyright (C) 2025 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

import 'reflect-metadata';

import type { ExtensionContext as PodmanDesktopExtensionContext, TelemetryLogger } from '@podman-desktop/api';
import { Container } from 'inversify';

import { ExtensionContextSymbol, TelemetryLoggerSymbol } from '/@/inject/symbol';
import { RpcExtension } from '/@common/rpc/rpc';
import { managersModule } from '/@/manager/_manager-module';

export class InversifyBinding {
#container: Container | undefined;

readonly #rpcExtension: RpcExtension;

readonly #extensionContext: PodmanDesktopExtensionContext;

readonly #telemetryLogger: TelemetryLogger;

constructor(
rpcExtension: RpcExtension,
extensionContext: PodmanDesktopExtensionContext,
telemetryLogger: TelemetryLogger,
) {
this.#rpcExtension = rpcExtension;
this.#extensionContext = extensionContext;
this.#telemetryLogger = telemetryLogger;
}

public async initBindings(): Promise<Container> {
this.#container = new Container();

this.#container.bind(RpcExtension).toConstantValue(this.#rpcExtension);
this.#container.bind(ExtensionContextSymbol).toConstantValue(this.#extensionContext);
this.#container.bind(TelemetryLoggerSymbol).toConstantValue(this.#telemetryLogger);

await this.#container.load(managersModule);

return this.#container;
}

async dispose(): Promise<void> {
if (this.#container) {
await this.#container.unbindAll();
}
}
}
21 changes: 21 additions & 0 deletions packages/extension/src/inject/symbol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**********************************************************************
* Copyright (C) 2025 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

export const ExtensionContextSymbol = Symbol.for('ExtensionContext');

export const TelemetryLoggerSymbol = Symbol.for('TelemetryLogger');
29 changes: 29 additions & 0 deletions packages/extension/src/manager/_manager-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**********************************************************************
* Copyright (C) 2025 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

import { ContainerModule } from 'inversify';

import { ContextsManager } from './contexts-manager';
import { ContextsStatesDispatcher } from './contexts-states-dispatcher';

const managersModule = new ContainerModule(options => {
options.bind<ContextsManager>(ContextsManager).toSelf().inSingletonScope();
options.bind<ContextsStatesDispatcher>(ContextsStatesDispatcher).toSelf().inSingletonScope();
});

export { managersModule };
2 changes: 2 additions & 0 deletions packages/extension/src/manager/contexts-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import type { CacheUpdatedEvent, OfflineEvent, ResourceInformer } from '/@/types
import { RoutesResourceFactory } from '/@/resources/routes-resource-factory.js';
import { SecretsResourceFactory } from '/@/resources/secrets-resource-factory.js';
import { ServicesResourceFactory } from '/@/resources/services-resource-factory.js';
import { injectable } from 'inversify';

const HEALTH_CHECK_TIMEOUT_MS = 5_000;

Expand All @@ -59,6 +60,7 @@ const HEALTH_CHECK_TIMEOUT_MS = 5_000;
*
* ContextsManager exposes the current state of the health checkers, permission checkers and informers.
*/
@injectable()
export class ContextsManager {
#resourceFactoryHandler: ResourceFactoryHandler;
#dispatcher: ContextsDispatcher;
Expand Down
Loading