@fleetbase/ember-core 0.2.19 → 0.2.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,6 +44,7 @@ export default class UniverseService extends Service.extend(Evented) {
44
44
  };
45
45
  @tracked hooks = {};
46
46
  @tracked bootCallbacks = A([]);
47
+ @tracked initialLocation = { ...window.location };
47
48
 
48
49
  /**
49
50
  * Computed property that returns all administrative menu items.
@@ -137,6 +138,16 @@ export default class UniverseService extends Service.extend(Evented) {
137
138
  return this.router.transitionTo(route, ...args);
138
139
  }
139
140
 
141
+ /**
142
+ * Initialize the universe service.
143
+ *
144
+ * @memberof UniverseService
145
+ */
146
+ initialize() {
147
+ this.initialLocation = { ...window.location };
148
+ this.trigger('init', this);
149
+ }
150
+
140
151
  /**
141
152
  * Sets the application instance.
142
153
  *
@@ -1775,7 +1786,7 @@ export default class UniverseService extends Service.extend(Evented) {
1775
1786
  clearInterval(intervalId);
1776
1787
  reject(new Error('Timeout: Universe was unable to boot engines'));
1777
1788
  },
1778
- 5000
1789
+ 1000 * 40
1779
1790
  );
1780
1791
  });
1781
1792
  }
@@ -1803,6 +1814,7 @@ export default class UniverseService extends Service.extend(Evented) {
1803
1814
  }
1804
1815
 
1805
1816
  // Set application instance
1817
+ this.initialize();
1806
1818
  this.setApplicationInstance(owner);
1807
1819
 
1808
1820
  const tryBootEngine = (extension) => {
@@ -1861,101 +1873,36 @@ export default class UniverseService extends Service.extend(Evented) {
1861
1873
  pending.push(...stillPending);
1862
1874
  };
1863
1875
 
1876
+ // Run pre-boots if any
1877
+ await this.preboot();
1878
+
1864
1879
  return loadInstalledExtensions(additionalCoreExtensions).then(async (extensions) => {
1865
1880
  for (let i = 0; i < extensions.length; i++) {
1866
1881
  const extension = extensions[i];
1867
1882
  await tryBootEngine(extension);
1868
1883
  }
1869
1884
 
1870
- this.runBootCallbacks(owner);
1871
- this.enginesBooted = true;
1885
+ this.runBootCallbacks(owner, () => {
1886
+ this.enginesBooted = true;
1887
+ });
1872
1888
  });
1873
1889
  }
1874
1890
 
1875
1891
  /**
1876
- * Boots all installed engines, ensuring dependencies are resolved.
1892
+ * Run engine preboots from all indexed engines.
1877
1893
  *
1878
- * This method loads all installed extensions and then attempts to boot each engine.
1879
- * For each extension, it loads the engine and, if the engine has a `setupExtension`
1880
- * method in its base, it calls this method to complete the setup. This function ensures
1881
- * that dependencies are resolved before booting the engines. If some dependencies are
1882
- * never booted, an error is logged.
1883
- *
1884
- * @method legacyBootEngines
1885
- * @param {ApplicationInstance|null} owner - The Ember ApplicationInstance that owns the engines.
1886
- * @return {void}
1894
+ * @param {ApplicationInstance} owner
1895
+ * @memberof UniverseService
1887
1896
  */
1888
- legacyBootEngines(owner = null) {
1889
- const booted = [];
1890
- const pending = [];
1891
-
1892
- // If no owner provided use the owner of this service
1893
- if (owner === null) {
1894
- owner = getOwner(this);
1895
- }
1896
-
1897
- // Set application instance
1898
- this.setApplicationInstance(owner);
1899
-
1900
- const tryBootEngine = (extension) => {
1901
- return this.loadEngine(extension.name).then((engineInstance) => {
1902
- if (engineInstance.base && engineInstance.base.setupExtension) {
1903
- const engineDependencies = getWithDefault(engineInstance.base, 'engineDependencies', []);
1904
-
1905
- // Check if all dependency engines are booted
1906
- const allDependenciesBooted = engineDependencies.every((dep) => booted.includes(dep));
1907
-
1908
- if (!allDependenciesBooted) {
1909
- pending.push({ extension, engineInstance });
1910
- return;
1911
- }
1912
-
1913
- engineInstance.base.setupExtension(owner, engineInstance, this);
1914
- booted.push(extension.name);
1915
- this.bootedExtensions.pushObject(extension.name);
1916
- this.trigger('extension.booted', extension);
1917
- debug(`Booted : ${extension.name}`);
1918
-
1919
- // Try booting pending engines again
1920
- tryBootPendingEngines();
1921
- }
1922
- });
1923
- };
1924
-
1925
- const tryBootPendingEngines = () => {
1926
- const stillPending = [];
1927
-
1928
- pending.forEach(({ extension, engineInstance }) => {
1929
- const engineDependencies = getWithDefault(engineInstance.base, 'engineDependencies', []);
1930
- const allDependenciesBooted = engineDependencies.every((dep) => booted.includes(dep));
1931
-
1932
- if (allDependenciesBooted) {
1933
- engineInstance.base.setupExtension(owner, engineInstance, this);
1934
- booted.push(extension.name);
1935
- this.bootedExtensions.pushObject(extension.name);
1936
- this.trigger('extension.booted', extension);
1937
- debug(`Booted : ${extension.name}`);
1938
- } else {
1939
- stillPending.push({ extension, engineInstance });
1940
- }
1941
- });
1942
-
1943
- // If no progress was made, log an error in debug/development mode
1944
- assert('Some engines have unmet dependencies and cannot be booted:', pending.length === stillPending.length);
1945
-
1946
- pending.length = 0;
1947
- pending.push(...stillPending);
1948
- };
1949
-
1950
- return loadExtensions().then(async (extensions) => {
1951
- for (let i = 0; i < extensions.length; i++) {
1952
- const extension = extensions[i];
1953
- await tryBootEngine(extension);
1897
+ async preboot(owner) {
1898
+ const extensions = await loadExtensions();
1899
+ for (let i = 0; i < extensions.length; i++) {
1900
+ const extension = extensions[i];
1901
+ const instance = await this.loadEngine(extension.name);
1902
+ if (instance.base && typeof instance.base.preboot === 'function') {
1903
+ instance.base.preboot(owner, instance, this);
1954
1904
  }
1955
-
1956
- this.runBootCallbacks(owner);
1957
- this.enginesBooted = true;
1958
- });
1905
+ }
1959
1906
  }
1960
1907
 
1961
1908
  /**
@@ -2004,7 +1951,11 @@ export default class UniverseService extends Service.extend(Evented) {
2004
1951
  for (let i = 0; i < this.bootCallbacks.length; i++) {
2005
1952
  const callback = this.bootCallbacks[i];
2006
1953
  if (typeof callback === 'function') {
2007
- callback(this, appInstance);
1954
+ try {
1955
+ callback(this, appInstance);
1956
+ } catch (error) {
1957
+ debug(`Engine Boot Callback Error: ${error.message}`);
1958
+ }
2008
1959
  }
2009
1960
  }
2010
1961
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fleetbase/ember-core",
3
- "version": "0.2.19",
3
+ "version": "0.2.21",
4
4
  "description": "Provides all the core services, decorators and utilities for building a Fleetbase extension for the Console.",
5
5
  "keywords": [
6
6
  "fleetbase-core",