diff --git a/src/common/catalog/catalog-run-event.ts b/src/common/catalog/catalog-run-event.ts
index 68a1a4bd08..00c475771d 100644
--- a/src/common/catalog/catalog-run-event.ts
+++ b/src/common/catalog/catalog-run-event.ts
@@ -22,23 +22,23 @@
import type { CatalogEntity } from "../catalog";
export class CatalogRunEvent {
- private _defaultPrevented: boolean;
- private _target: CatalogEntity;
+ #defaultPrevented: boolean;
+ #target: CatalogEntity;
get defaultPrevented() {
- return this._defaultPrevented;
+ return this.#defaultPrevented;
}
get target() {
- return this._target;
+ return this.#target;
}
constructor({ target }: { target: CatalogEntity }) {
- this._defaultPrevented = false;
- this._target = target;
+ this.#defaultPrevented = false;
+ this.#target = target;
}
preventDefault() {
- this._defaultPrevented = true;
+ this.#defaultPrevented = true;
}
}
diff --git a/src/renderer/api/catalog-entity-registry.ts b/src/renderer/api/catalog-entity-registry.ts
index 58a14018de..1b7e79e67c 100644
--- a/src/renderer/api/catalog-entity-registry.ts
+++ b/src/renderer/api/catalog-entity-registry.ts
@@ -206,11 +206,13 @@ export class CatalogEntityRegistry {
} catch (error) {
logger.warn(`[CATALOG-ENTITY-REGISTRY]: entity ${entity.getId()} onBeforeRun threw an error`, error);
}
+
+ if (runEvent.defaultPrevented) {
+ return false;
+ }
}
- const shouldContinue = !runEvent.defaultPrevented;
-
- return shouldContinue;
+ return true;
}
/**
diff --git a/src/renderer/components/+catalog/catalog.test.tsx b/src/renderer/components/+catalog/catalog.test.tsx
index f71b04f50f..bb1ce35a5b 100644
--- a/src/renderer/components/+catalog/catalog.test.tsx
+++ b/src/renderer/components/+catalog/catalog.test.tsx
@@ -158,8 +158,6 @@ describe("", () => {
expect(onRun).toHaveBeenCalled();
done();
}, 500);
-
- return true;
}
);
@@ -213,7 +211,7 @@ describe("", () => {
userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon"));
});
- it("addOnBeforeRun throw an exception => onRun wont be triggered", (done) => {
+ it("addOnBeforeRun throw an exception => onRun will be triggered", (done) => {
const catalogCategoryRegistry = new CatalogCategoryRegistry();
const catalogEntityRegistry = new CatalogEntityRegistry(catalogCategoryRegistry);
const catalogEntityStore = new CatalogEntityStore(catalogEntityRegistry);
@@ -232,7 +230,7 @@ describe("", () => {
catalogEntityRegistry.addOnBeforeRun(
() => {
setTimeout(() => {
- expect(onRun).not.toHaveBeenCalled();
+ expect(onRun).toHaveBeenCalled();
done();
}, 500);
@@ -327,7 +325,7 @@ describe("", () => {
userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon"));
});
- it("addOnRunHook return a promise and reject => onRun wont be triggered", (done) => {
+ it("addOnRunHook return a promise and reject => onRun will be triggered", (done) => {
const catalogCategoryRegistry = new CatalogCategoryRegistry();
const catalogEntityRegistry = new CatalogEntityRegistry(catalogCategoryRegistry);
const catalogEntityStore = new CatalogEntityStore(catalogEntityRegistry);
@@ -346,7 +344,7 @@ describe("", () => {
catalogEntityRegistry.addOnBeforeRun(
async () => {
setTimeout(() => {
- expect(onRun).not.toHaveBeenCalled();
+ expect(onRun).toHaveBeenCalled();
done();
}, 500);