diff --git a/packages/main/src/plugin/index.ts b/packages/main/src/plugin/index.ts index a3907453be0..bd123b0ece4 100644 --- a/packages/main/src/plugin/index.ts +++ b/packages/main/src/plugin/index.ts @@ -160,6 +160,7 @@ import { DialogRegistry } from './dialog-registry.js'; import type { Deferred } from './util/deferred.js'; import type { ContextGeneralState, ResourceName } from './kubernetes-context-state.js'; import { Updater } from '/@/plugin/updater.js'; +import { RecommendationsRegistry } from './recommendations/recommendations-registry.js'; type LogType = 'log' | 'warn' | 'trace' | 'debug' | 'error'; @@ -453,6 +454,9 @@ export class PluginSystem { const closeBehaviorConfiguration = new CloseBehavior(configurationRegistry); await closeBehaviorConfiguration.init(); + const recommendationsRegistry = new RecommendationsRegistry(configurationRegistry); + recommendationsRegistry.init(); + const messageBox = new MessageBox(apiSender); // Don't show the tray icon options on Mac diff --git a/packages/main/src/plugin/recommendations/recommendations-registry.spec.ts b/packages/main/src/plugin/recommendations/recommendations-registry.spec.ts new file mode 100644 index 00000000000..ce0df22c4a0 --- /dev/null +++ b/packages/main/src/plugin/recommendations/recommendations-registry.spec.ts @@ -0,0 +1,53 @@ +/********************************************************************** + * Copyright (C) 2024 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 { beforeEach, expect, test, vi } from 'vitest'; +import type { ConfigurationRegistry } from '/@/plugin/configuration-registry.js'; +import { RecommendationsRegistry } from './recommendations-registry.js'; + +let recommendationsRegistry: RecommendationsRegistry; + +const registerConfigurationsMock = vi.fn(); + +const configurationRegistryMock = { + registerConfigurations: registerConfigurationsMock, +} as unknown as ConfigurationRegistry; + +beforeEach(() => { + recommendationsRegistry = new RecommendationsRegistry(configurationRegistryMock); +}); +test('should register a configuration', async () => { + // register configuration + recommendationsRegistry.init(); + + // should be the directory provided as env var + expect(configurationRegistryMock.registerConfigurations).toBeCalled(); + + // take first argument of first call + const configurationNode = vi.mocked(configurationRegistryMock).registerConfigurations.mock.calls[0][0][0]; + expect(configurationNode.id).toBe('preferences.extensions'); + expect(configurationNode.title).toBe('Extensions'); + expect(configurationNode.type).toBe('object'); + expect(configurationNode.properties).toBeDefined(); + expect(configurationNode.properties?.['extensions.ignoreRecommendations']).toBeDefined(); + expect(configurationNode.properties?.['extensions.ignoreRecommendations'].description).toBe( + 'When enabled, the notifications for extension recommendations will not be shown.', + ); + expect(configurationNode.properties?.['extensions.ignoreRecommendations'].type).toBe('boolean'); + expect(configurationNode.properties?.['extensions.ignoreRecommendations'].default).toBeFalsy(); +}); diff --git a/packages/main/src/plugin/recommendations/recommendations-registry.ts b/packages/main/src/plugin/recommendations/recommendations-registry.ts new file mode 100644 index 00000000000..3e760727d7c --- /dev/null +++ b/packages/main/src/plugin/recommendations/recommendations-registry.ts @@ -0,0 +1,42 @@ +/********************************************************************** + * Copyright (C) 2024 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 type { IConfigurationNode, IConfigurationRegistry } from '/@/plugin/configuration-registry.js'; +import { RecommendationsSettings } from './recommendations-settings.js'; + +export class RecommendationsRegistry { + constructor(private configurationRegistry: IConfigurationRegistry) {} + + init(): void { + const recommendationConfiguration: IConfigurationNode = { + id: 'preferences.extensions', + title: 'Extensions', + type: 'object', + properties: { + [RecommendationsSettings.SectionName + '.' + RecommendationsSettings.IgnoreRecommendations]: { + description: 'When enabled, the notifications for extension recommendations will not be shown.', + type: 'boolean', + default: false, + hidden: true, + }, + }, + }; + + this.configurationRegistry.registerConfigurations([recommendationConfiguration]); + } +} diff --git a/packages/main/src/plugin/recommendations/recommendations-settings.ts b/packages/main/src/plugin/recommendations/recommendations-settings.ts new file mode 100644 index 00000000000..4c6b66c01c6 --- /dev/null +++ b/packages/main/src/plugin/recommendations/recommendations-settings.ts @@ -0,0 +1,22 @@ +/********************************************************************** + * Copyright (C) 2024 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 enum RecommendationsSettings { + SectionName = 'extensions', + IgnoreRecommendations = 'ignoreRecommendations', +}