From b967b46986406be4ba2b5f6dcdfaa2cf49373363 Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Mon, 29 Dec 2025 14:04:18 +0800 Subject: [PATCH] Remove usage of `window.Fleetbase` --- addon/library/subject-custom-fields.js | 2 +- addon/services/legacy-universe.js | 1 - addon/services/universe.js | 2 +- addon/services/universe/extension-manager.js | 15 ++++++----- addon/services/universe/hook-service.js | 16 +++++++----- addon/services/universe/registry-service.js | 27 ++++++++------------ addon/utils/inject-engine-service.js | 2 +- package.json | 2 +- 8 files changed, 32 insertions(+), 35 deletions(-) diff --git a/addon/library/subject-custom-fields.js b/addon/library/subject-custom-fields.js index 4c71540b..6df2ec08 100644 --- a/addon/library/subject-custom-fields.js +++ b/addon/library/subject-custom-fields.js @@ -242,7 +242,7 @@ export default class SubjectCustomFields { let existingMany = subject.hasMany?.('custom_field_values')?.value?.() ?? null; // If asked or not loaded, fetch from API (scoped to subject) - if (reloadExisting || !existingMany) { + if ((reloadExisting || !existingMany) && subjectId) { try { existingMany = await this.store.query('custom-field-value', { subject_uuid: subjectId, diff --git a/addon/services/legacy-universe.js b/addon/services/legacy-universe.js index 8e2d508b..4d48c0f3 100644 --- a/addon/services/legacy-universe.js +++ b/addon/services/legacy-universe.js @@ -155,7 +155,6 @@ export default class LegacyUniverseService extends Service.extend(Evented) { * @return {void} */ setApplicationInstance(instance) { - window.Fleetbase = instance; this.applicationInstance = instance; } diff --git a/addon/services/universe.js b/addon/services/universe.js index e34973ef..f09701ec 100644 --- a/addon/services/universe.js +++ b/addon/services/universe.js @@ -212,7 +212,7 @@ export default class UniverseService extends Service.extend(Evented) { * @returns {ApplicationInstance} The application instance */ getApplicationInstance() { - return this.applicationInstance ?? window.Fleetbase; + return this.applicationInstance; } /** diff --git a/addon/services/universe/extension-manager.js b/addon/services/universe/extension-manager.js index 49f934a6..9b0156f8 100644 --- a/addon/services/universe/extension-manager.js +++ b/addon/services/universe/extension-manager.js @@ -1,4 +1,4 @@ -import Service from '@ember/service'; +import Service, { inject as service } from '@ember/service'; import Evented from '@ember/object/evented'; import { tracked } from '@glimmer/tracking'; import { getOwner } from '@ember/application'; @@ -22,6 +22,7 @@ import ExtensionBootState from '../../contracts/extension-boot-state'; * @extends Service */ export default class ExtensionManagerService extends Service.extend(Evented) { + @service universe; /** * Reference to the root Ember Application Instance. * Used for registering components/services to the application container @@ -84,14 +85,14 @@ export default class ExtensionManagerService extends Service.extend(Evented) { * @returns {Application} */ #getApplication() { - // First priority: use applicationInstance if set - if (this.applicationInstance) { - return this.applicationInstance; + // First priority use the universe application instance + if (this.universe.applicationInstance) { + return this.universe.applicationInstance; } - // Second priority: window.Fleetbase - if (typeof window !== 'undefined' && window.Fleetbase) { - return window.Fleetbase; + // Second priority: use applicationInstance if set + if (this.applicationInstance) { + return this.applicationInstance; } // Third priority: try to get application from owner diff --git a/addon/services/universe/hook-service.js b/addon/services/universe/hook-service.js index 6719c233..51b04a28 100644 --- a/addon/services/universe/hook-service.js +++ b/addon/services/universe/hook-service.js @@ -1,4 +1,4 @@ -import Service from '@ember/service'; +import Service, { inject as service } from '@ember/service'; import { tracked } from '@glimmer/tracking'; import { getOwner } from '@ember/application'; import Hook from '../../contracts/hook'; @@ -14,6 +14,8 @@ import HookRegistry from '../../contracts/hook-registry'; * @extends Service */ export default class HookService extends Service { + @service universe; + /** * Reference to the root Ember Application Instance. * Used for registering components/services to the application container @@ -69,14 +71,14 @@ export default class HookService extends Service { * @returns {Application} */ #getApplication() { - // First priority: use applicationInstance if set - if (this.applicationInstance) { - return this.applicationInstance; + // First priority use the universe application instance + if (this.universe.applicationInstance) { + return this.universe.applicationInstance; } - // Second priority: window.Fleetbase - if (typeof window !== 'undefined' && window.Fleetbase) { - return window.Fleetbase; + // Second priority: use applicationInstance if set + if (this.applicationInstance) { + return this.applicationInstance; } // Third priority: try to get application from owner diff --git a/addon/services/universe/registry-service.js b/addon/services/universe/registry-service.js index 15c38282..6136d8e3 100644 --- a/addon/services/universe/registry-service.js +++ b/addon/services/universe/registry-service.js @@ -82,21 +82,16 @@ export default class RegistryService extends Service { let application = this.applicationInstance; if (!application) { - // Second priority: window.Fleetbase - if (typeof window !== 'undefined' && window.Fleetbase) { - application = window.Fleetbase; + // Second priority: try to get from owner + const owner = getOwner(this); + if (owner && owner.application) { + application = owner.application; } else { - // Third priority: try to get from owner - const owner = getOwner(this); - if (owner && owner.application) { - application = owner.application; - } else { - warn('[RegistryService] Could not find application instance for registry initialization', { - id: 'registry-service.no-application', - }); - // Return a new instance as fallback (won't be shared) - return new UniverseRegistry(); - } + warn('[RegistryService] Could not find application instance for registry initialization', { + id: 'registry-service.no-application', + }); + // Return a new instance as fallback (won't be shared) + return new UniverseRegistry(); } } @@ -489,7 +484,7 @@ export default class RegistryService extends Service { * ); */ async registerHelper(helperName, helperClassOrTemplateHelper, options = {}) { - const owner = this.applicationInstance || (typeof window !== 'undefined' && window.Fleetbase) || getOwner(this); + const owner = this.applicationInstance || getOwner(this); if (!owner) { warn('No owner available for helper registration. Cannot register helper.', { @@ -539,7 +534,7 @@ export default class RegistryService extends Service { * @returns {Promise} The loaded helper or null if failed */ async #loadHelperFromEngine(templateHelper) { - const owner = this.applicationInstance || (typeof window !== 'undefined' && window.Fleetbase) || getOwner(this); + const owner = this.applicationInstance || getOwner(this); if (!owner) { return null; diff --git a/addon/utils/inject-engine-service.js b/addon/utils/inject-engine-service.js index 721e0d5e..e4c1bc7d 100644 --- a/addon/utils/inject-engine-service.js +++ b/addon/utils/inject-engine-service.js @@ -35,7 +35,7 @@ function automaticServiceResolution(service, target, owner) { } function _getOwner(target) { - return window.Fleetbase ?? getOwner(target); + return getOwner(target); } export default function injectEngineService(target, engineName, serviceName, options = {}) { diff --git a/package.json b/package.json index 35a7f22a..fc7e85e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fleetbase/ember-core", - "version": "0.3.9", + "version": "0.3.10", "description": "Provides all the core services, decorators and utilities for building a Fleetbase extension for the Console.", "keywords": [ "fleetbase-core",