@fleetbase/ember-core 0.2.20 → 0.2.22

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.
@@ -1,12 +1,14 @@
1
1
  import Service from '@ember/service';
2
+ import Evented from '@ember/object/evented';
2
3
  import { tracked } from '@glimmer/tracking';
3
4
  import { inject as service } from '@ember/service';
4
5
  import { computed } from '@ember/object';
5
6
  import { dasherize } from '@ember/string';
6
7
  import { isArray } from '@ember/array';
7
8
  import { getOwner } from '@ember/application';
9
+ import { debug } from '@ember/debug';
8
10
 
9
- export default class ThemeService extends Service {
11
+ export default class ThemeService extends Service.extend(Evented) {
10
12
  /**
11
13
  * Lookup the correct router for the engine and or console.
12
14
  *
@@ -201,10 +203,12 @@ export default class ThemeService extends Service {
201
203
  * @void
202
204
  */
203
205
  setTheme(theme = 'light') {
206
+ debug(`Theme was changed to: ${theme}`);
204
207
  document.body.classList.remove(`${this.currentTheme}-theme`);
205
208
  document.body.classList.add(`${theme}-theme`);
206
209
  this.currentUser.setOption('theme', theme);
207
210
  this.activeTheme = theme;
211
+ this.trigger('theme.changed', theme);
208
212
  }
209
213
 
210
214
  /**
@@ -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
  *
@@ -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,6 +1873,9 @@ 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];
@@ -1874,90 +1889,20 @@ export default class UniverseService extends Service.extend(Evented) {
1874
1889
  }
1875
1890
 
1876
1891
  /**
1877
- * Boots all installed engines, ensuring dependencies are resolved.
1878
- *
1879
- * This method loads all installed extensions and then attempts to boot each engine.
1880
- * For each extension, it loads the engine and, if the engine has a `setupExtension`
1881
- * method in its base, it calls this method to complete the setup. This function ensures
1882
- * that dependencies are resolved before booting the engines. If some dependencies are
1883
- * never booted, an error is logged.
1892
+ * Run engine preboots from all indexed engines.
1884
1893
  *
1885
- * @method legacyBootEngines
1886
- * @param {ApplicationInstance|null} owner - The Ember ApplicationInstance that owns the engines.
1887
- * @return {void}
1894
+ * @param {ApplicationInstance} owner
1895
+ * @memberof UniverseService
1888
1896
  */
1889
- legacyBootEngines(owner = null) {
1890
- const booted = [];
1891
- const pending = [];
1892
-
1893
- // If no owner provided use the owner of this service
1894
- if (owner === null) {
1895
- owner = getOwner(this);
1896
- }
1897
-
1898
- // Set application instance
1899
- this.setApplicationInstance(owner);
1900
-
1901
- const tryBootEngine = (extension) => {
1902
- return this.loadEngine(extension.name).then((engineInstance) => {
1903
- if (engineInstance.base && engineInstance.base.setupExtension) {
1904
- const engineDependencies = getWithDefault(engineInstance.base, 'engineDependencies', []);
1905
-
1906
- // Check if all dependency engines are booted
1907
- const allDependenciesBooted = engineDependencies.every((dep) => booted.includes(dep));
1908
-
1909
- if (!allDependenciesBooted) {
1910
- pending.push({ extension, engineInstance });
1911
- return;
1912
- }
1913
-
1914
- engineInstance.base.setupExtension(owner, engineInstance, this);
1915
- booted.push(extension.name);
1916
- this.bootedExtensions.pushObject(extension.name);
1917
- this.trigger('extension.booted', extension);
1918
- debug(`Booted : ${extension.name}`);
1919
-
1920
- // Try booting pending engines again
1921
- tryBootPendingEngines();
1922
- }
1923
- });
1924
- };
1925
-
1926
- const tryBootPendingEngines = () => {
1927
- const stillPending = [];
1928
-
1929
- pending.forEach(({ extension, engineInstance }) => {
1930
- const engineDependencies = getWithDefault(engineInstance.base, 'engineDependencies', []);
1931
- const allDependenciesBooted = engineDependencies.every((dep) => booted.includes(dep));
1932
-
1933
- if (allDependenciesBooted) {
1934
- engineInstance.base.setupExtension(owner, engineInstance, this);
1935
- booted.push(extension.name);
1936
- this.bootedExtensions.pushObject(extension.name);
1937
- this.trigger('extension.booted', extension);
1938
- debug(`Booted : ${extension.name}`);
1939
- } else {
1940
- stillPending.push({ extension, engineInstance });
1941
- }
1942
- });
1943
-
1944
- // If no progress was made, log an error in debug/development mode
1945
- assert('Some engines have unmet dependencies and cannot be booted:', pending.length === stillPending.length);
1946
-
1947
- pending.length = 0;
1948
- pending.push(...stillPending);
1949
- };
1950
-
1951
- return loadExtensions().then(async (extensions) => {
1952
- for (let i = 0; i < extensions.length; i++) {
1953
- const extension = extensions[i];
1954
- 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);
1955
1904
  }
1956
-
1957
- this.runBootCallbacks(owner, () => {
1958
- this.enginesBooted = true;
1959
- });
1960
- });
1905
+ }
1961
1906
  }
1962
1907
 
1963
1908
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fleetbase/ember-core",
3
- "version": "0.2.20",
3
+ "version": "0.2.22",
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",