Skip to content

Commit

Permalink
chore: use publisher.extension-name as extension id
Browse files Browse the repository at this point in the history
avoid potential collision if it is just the name

Change-Id: Ib872bb654e2961513f7367eff6dcb7e258b6d2e0

Signed-off-by: Florent Benoit <fbenoit@redhat.com>
Change-Id: Ie018e0a0e210b8599c7b425dc877c9d308cf870d
  • Loading branch information
benoitf committed May 25, 2023
1 parent 29ae0e7 commit 1b52d5c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/main/src/plugin/extension-loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ test('Verify extension error leads to failed state', async () => {
await extensionLoader.activateExtension(
{
id: id,
name: 'id',
path: 'dummy',
api: {} as typeof containerDesktopAPI,
mainPath: '',
Expand Down
14 changes: 12 additions & 2 deletions packages/main/src/plugin/extension-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import { securityRestrictionCurrentHandler } from '../security-restrictions-hand

export interface AnalyzedExtension {
id: string;
name: string;
// root folder (where is package.json)
path: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -360,7 +361,8 @@ export class ExtensionLoader {
const api = this.createApi(extensionPath, manifest);

const extension: AnalyzedExtension = {
id: manifest.name,
id: `${manifest.publisher}.${manifest.name}`,
name: manifest.name,
manifest,
path: extensionPath,
mainPath: path.resolve(extensionPath, manifest.main),
Expand Down Expand Up @@ -808,9 +810,17 @@ export class ExtensionLoader {

const subscriptions: containerDesktopAPI.Disposable[] = [];

const storagePath = path.resolve(this.extensionsStorageDirectory, extension.id);
const oldStoragePath = path.resolve(this.extensionsStorageDirectory, extension.name);

// Migrate old storage path to new storage path
if (fs.existsSync(oldStoragePath)) {
await fs.promises.rename(oldStoragePath, storagePath);
}

const extensionContext: containerDesktopAPI.ExtensionContext = {
subscriptions,
storagePath: path.resolve(this.extensionsStorageDirectory, extension.id),
storagePath,
};
let deactivateFunction = undefined;
if (typeof extensionMain['deactivate'] === 'function') {
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/plugin/featured/featured.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ test('getFeaturedExtensions should check installable extensions', async () => {
listExtensionsMock.mockReturnValue([
{
publisher: 'podman-desktop',
id: 'podman',
id: 'podman-desktop.podman',
// make it a built-in extension (cannot be removed, just disabled)
removable: false,
},
Expand Down
4 changes: 1 addition & 3 deletions packages/main/src/plugin/featured/featured.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ export class Featured {
};

// check if the extension is installed
const extensionInfo = extensionInfos.find(
extensionInfo => `${extensionInfo.publisher}.${extensionInfo.id}` === extensionToCheck.extensionId,
);
const extensionInfo = extensionInfos.find(extensionInfo => extensionInfo.id === extensionToCheck.extensionId);
if (extensionInfo) {
// found it so we can flag them as installed/fetched
featuredExtension.installed = true;
Expand Down
4 changes: 2 additions & 2 deletions packages/renderer/src/PreferencesNavigation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ $: addSectionHiddenClass = (section: string): string => (sectionExpanded[section
<section class="pf-c-nav__subnav {addSectionHiddenClass('extensionsCatalog')}">
<ul class="pf-c-nav__list">
{#each $extensionInfos as extension}
<li class="pf-c-nav__item {addCurrentClass(`/preferences/extension/${extension.name}`)}">
<li class="pf-c-nav__item {addCurrentClass(`/preferences/extension/${extension.id}`)}">
<a
href="/preferences/extension/{extension.name}"
href="/preferences/extension/{extension.id}"
id="configuration-section-extensions-catalog-{extension.name.toLowerCase()}"
class="pf-c-nav__link"
style="font-weight: 200">{extension.displayName}</a>
Expand Down

0 comments on commit 1b52d5c

Please sign in to comment.