All files / platform/core/src/extensions ExtensionManager.ts

74.16% Statements 155/209
57.37% Branches 35/61
75.6% Functions 31/41
74.14% Lines 152/205

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661                                                                                                                                      34x             34x 34x 34x 34x 34x 34x 34x 34x 34x 34x       34x 34x                   34x 34x 34x 34x   34x 34x 34x 34x 34x   34x 34x 408x   34x 34x 34x 34x 34x 34x       136x 102x     34x   34x             68x           34x                               34x 34x         34x 782x     34x 306x   306x 102x                                                                         34x                           34x 68x 68x 68x 68x                   68x               34x                     306x       306x   306x           306x               306x 102x                     306x 102x     306x 68x       306x 3672x             3672x 2312x     1360x   170x 170x     34x 34x     102x 102x     102x 102x     102x 102x                 850x 850x         1360x             306x     34x             4022x     34x             34x 34x     341x   1x       341x 34x       34x     1580x     34x                               34x             34x                                                       34x             3672x 3672x   3672x 2312x     1360x 1360x                 1360x           1360x             34x     102x 102x 510x   510x     34x     102x 34x         102x 102x 748x 408x                       952x 1428x     1428x 1428x 1428x                     340x 340x         340x   340x                                                                       340x   340x       340x   340x           340x               34x 170x     34x 170x   170x 1700x 340x           34x           170x 170x         170x   170x 170x     170x 4216x 4216x 1190x     4216x   4216x       4216x                                   3672x    
import MODULE_TYPES from './MODULE_TYPES';
import log from '../log';
import { PubSubService, ServiceProvidersManager } from '../services';
import { HotkeysManager, CommandsManager } from '../classes';
import type { DataSourceDefinition } from '../types';
import type AppTypes from '../types/AppTypes';
 
/**
 * This is the arguments given to create the extension.
 */
export interface ExtensionConstructor {
  servicesManager: AppTypes.ServicesManager;
  serviceProvidersManager: ServiceProvidersManager;
  commandsManager: CommandsManager;
  hotkeysManager: HotkeysManager;
  appConfig: AppTypes.Config;
}
 
/**
 * The configuration of an extension.
 * This uses type as the extension manager only knows that the configuration
 * is an object of some sort, and doesn't know anything else about it.
 */
export type ExtensionConfiguration = Record<string, unknown>;
 
/**
 * The parameters passed to the extension.
 */
export interface ExtensionParams extends ExtensionConstructor {
  extensionManager: ExtensionManager;
  servicesManager: AppTypes.ServicesManager;
  serviceProvidersManager: ServiceProvidersManager;
  configuration?: ExtensionConfiguration;
  peerImport: (moduleId: string) => Promise<any>;
}
 
/**
 * The type of an actual extension instance.
 * This is an interface as it declares possible calls, but extensions can
 * have more values than this.
 */
export interface Extension {
  id: string;
  preRegistration?: (p: ExtensionParams) => Promise<void> | void;
  getHangingProtocolModule?: (p: ExtensionParams) => unknown;
  getCommandsModule?: (p: ExtensionParams) => CommandsModule;
  getViewportModule?: (p: ExtensionParams) => unknown;
  getUtilityModule?: (p: ExtensionParams) => unknown;
  getCustomizationModule?: (p: ExtensionParams) => unknown;
  getSopClassHandlerModule?: (p: ExtensionParams) => unknown;
  getToolbarModule?: (p: ExtensionParams) => unknown;
  getPanelModule?: (p: ExtensionParams) => unknown;
  onModeEnter?: (p: AppTypes) => void;
  onModeExit?: (p: AppTypes) => void;
}
 
export type ExtensionRegister = {
  id: string;
  create: (p: ExtensionParams) => Extension;
};
 
export type CommandsModule = {
  actions: Record<string, unknown>;
  definitions: Record<string, unknown>;
  defaultContext?: string;
};
 
export default class ExtensionManager extends PubSubService {
  public static readonly EVENTS = {
    ACTIVE_DATA_SOURCE_CHANGED: 'event::activedatasourcechanged',
  };
 
  public static readonly MODULE_TYPES = MODULE_TYPES;
 
  private _commandsManager: CommandsManager;
  private _servicesManager: AppTypes.ServicesManager;
  private _hotkeysManager: HotkeysManager;
  private _serviceProvidersManager: ServiceProvidersManager;
  private modulesMap: Record<string, unknown>;
  private modules: Record<string, any[]>;
  private registeredExtensionIds: string[];
  private moduleTypeNames: string[];
  private _appConfig: any;
  private _extensionLifeCycleHooks: {
    onModeEnter: Record<string, any>;
    onModeExit: Record<string, any>;
  };
  private dataSourceMap: Record<string, any>;
  private dataSourceDefs: Record<string, any>;
  private activeDataSourceName: string;
 
  constructor({
    commandsManager,
    servicesManager,
    serviceProvidersManager,
    hotkeysManager,
    appConfig = {},
  }: ExtensionConstructor) {
    super(ExtensionManager.EVENTS);
    this.modules = {};
    this.registeredExtensionIds = [];
    this.moduleTypeNames = Object.values(MODULE_TYPES);
    //
    this._commandsManager = commandsManager;
    this._servicesManager = servicesManager;
    this._serviceProvidersManager = serviceProvidersManager;
    this._hotkeysManager = hotkeysManager;
    this._appConfig = appConfig;
 
    this.modulesMap = {};
    this.moduleTypeNames.forEach(moduleType => {
      this.modules[moduleType] = [];
    });
    this._extensionLifeCycleHooks = { onModeEnter: {}, onModeExit: {} };
    this.dataSourceMap = {};
    this.dataSourceDefs = {};
    this.defaultDataSourceName = appConfig.defaultDataSourceName;
    this.activeDataSourceName = appConfig.defaultDataSourceName;
    this.peerImport = appConfig.peerImport;
  }
 
  public setActiveDataSource(dataSource: string): void {
    if (this.activeDataSourceName === dataSource) {
      return;
    }
 
    this.activeDataSourceName = dataSource;
 
    this._broadcastEvent(
      ExtensionManager.EVENTS.ACTIVE_DATA_SOURCE_CHANGED,
      this.dataSourceDefs[this.activeDataSourceName]
    );
  }
 
  public getRegisteredExtensionIds() {
    return [...this.registeredExtensionIds];
  }
 
  private getUniqueServicesList(servicesManager: AppTypes.ServicesManager) {
    // Make sure only one service instance is returned because almost all services are
    // registered with different keys (eg: StudyPrefetcherService and studyPrefetcherService)
    return Array.from(new Set(Object.values(servicesManager.services)));
  }
 
  /**
   * Calls all the services and extension on mode enters.
   * The service onModeEnter is called first
   * Then registered extensions onModeEnter is called
   * This is supposed to setup the extension for a standard entry.
   */
  public onModeEnter(): void {
    const {
      registeredExtensionIds,
      _servicesManager,
      _commandsManager,
      _hotkeysManager,
      _extensionLifeCycleHooks,
    } = this;
    const services = this.getUniqueServicesList(_servicesManager);
 
    // The onModeEnter of the service must occur BEFORE the extension
    // onModeEnter in order to reset the state to a standard state
    // before the extension restores and cached data.
    for (const service of services) {
      service?.onModeEnter?.();
    }
 
    registeredExtensionIds.forEach(extensionId => {
      const onModeEnter = _extensionLifeCycleHooks.onModeEnter[extensionId];
 
      if (typeof onModeEnter === 'function') {
        onModeEnter({
          servicesManager: _servicesManager,
          commandsManager: _commandsManager,
          hotkeysManager: _hotkeysManager,
          extensionManager: this,
        });
      }
    });
  }
 
  public onModeExit(): void {
    const { registeredExtensionIds, _servicesManager, _commandsManager, _extensionLifeCycleHooks } =
      this;
    const services = this.getUniqueServicesList(_servicesManager);
 
    registeredExtensionIds.forEach(extensionId => {
      const onModeExit = _extensionLifeCycleHooks.onModeExit[extensionId];
 
      Iif (typeof onModeExit === 'function') {
        onModeExit({
          servicesManager: _servicesManager,
          commandsManager: _commandsManager,
        });
      }
    });
 
    // The service onModeExit calls must occur after the extension ones
    // so that extension ones can store/restore data.
    for (const service of services) {
      try {
        service?.onModeExit?.();
      } catch (e) {
        console.warn('onModeExit caught', e);
      }
    }
  }
 
  /**
   * An array of extensions, or an array of arrays that contains extension
   * configuration pairs.
   *
   * @param {Object[]} extensions - Array of extensions
   */
  public registerExtensions = async (
    extensions: (ExtensionRegister | [ExtensionRegister, ExtensionConfiguration])[],
    dataSources: unknown[] = []
  ): Promise<void> => {
    // Todo: we ideally should be able to run registrations in parallel
    // but currently since some extensions need to be registered before
    // others, we need to run them sequentially. We need a postInit hook
    // to avoid this sequential async registration
    for (let i = 0; i < extensions.length; i++) {
      const extension = extensions[i];
      const hasConfiguration = Array.isArray(extension);
      try {
        Iif (hasConfiguration) {
          // Important: for some reason in the line below the type
          // of extension is not recognized as [ExtensionRegister,
          // ExtensionConfiguration] by babel DON"T CHANGE IT
          // Same for the for loop above don't use
          // for (const extension of extensions)
          const ohifExtension = extension[0];
          const configuration = extension[1];
          await this.registerExtension(ohifExtension, configuration, dataSources);
        } else {
          await this.registerExtension(extension, {}, dataSources);
        }
      } catch (error) {
        console.error(error);
      }
    }
  };
 
  /**
   *
   * TODO: Id Management: SopClassHandlers currently refer to viewport module by id; setting the extension id as viewport module id is a workaround for now
   * @param {Object} extension
   * @param {Object} configuration
   */
  public registerExtension = async (
    extension: ExtensionRegister,
    configuration = {},
    dataSources = []
  ): Promise<void> => {
    Iif (!extension) {
      throw new Error('Attempting to register a null/undefined extension.');
    }
 
    const extensionId = extension.id;
 
    Iif (!extensionId) {
      // Note: Mode framework cannot function without IDs.
      log.warn(extension);
      throw new Error(`Extension ID not set`);
    }
 
    Iif (this.registeredExtensionIds.includes(extensionId)) {
      log.warn(
        `Extension ID ${extensionId} has already been registered. Exiting before duplicating modules.`
      );
      return;
    }
 
    // preRegistrationHook
    if (extension.preRegistration) {
      await extension.preRegistration({
        servicesManager: this._servicesManager,
        serviceProvidersManager: this._serviceProvidersManager,
        commandsManager: this._commandsManager,
        hotkeysManager: this._hotkeysManager,
        extensionManager: this,
        appConfig: this._appConfig,
        configuration,
      });
    }
 
    if (extension.onModeEnter) {
      this._extensionLifeCycleHooks.onModeEnter[extensionId] = extension.onModeEnter;
    }
 
    if (extension.onModeExit) {
      this._extensionLifeCycleHooks.onModeExit[extensionId] = extension.onModeExit;
    }
 
    // Register Modules
    this.moduleTypeNames.forEach(moduleType => {
      const extensionModule = this._getExtensionModule(
        moduleType,
        extension,
        extensionId,
        configuration
      );
 
      if (!extensionModule) {
        return;
      }
 
      switch (moduleType) {
        case MODULE_TYPES.COMMANDS:
          this._initCommandsModule(extensionModule);
          break;
 
        case MODULE_TYPES.DATA_SOURCE:
          this._initDataSourcesModule(extensionModule, extensionId, dataSources);
          break;
 
        case MODULE_TYPES.HANGING_PROTOCOL:
          this._initHangingProtocolsModule(extensionModule, extensionId);
          break;
 
        case MODULE_TYPES.PANEL:
          this._initPanelModule(extensionModule, extensionId);
          break;
 
        case MODULE_TYPES.TOOLBAR:
          this._initToolbarModule(extensionModule, extensionId);
          break;
 
        case MODULE_TYPES.VIEWPORT:
        case MODULE_TYPES.SOP_CLASS_HANDLER:
        case MODULE_TYPES.CONTEXT:
        case MODULE_TYPES.LAYOUT_TEMPLATE:
        case MODULE_TYPES.CUSTOMIZATION:
        case MODULE_TYPES.STATE_SYNC:
        case MODULE_TYPES.UTILITY:
          this.processExtensionModule(extensionModule, extensionId, moduleType);
          break;
        default:
          throw new Error(`Module type invalid: ${moduleType}`);
      }
 
      this.modules[moduleType].push({
        extensionId,
        module: extensionModule,
      });
    });
 
    // Track extension registration
    this.registeredExtensionIds.push(extensionId);
  };
 
  /**
   * Retrieves the module entry associated with the given string entry
   * @param stringEntry - The string entry to retrieve the module entry for which is
   * in the format of `${extensionId}.${moduleType}.${moduleName}`
   * @returns The module entry associated with the given string entry.
   */
  getModuleEntry = stringEntry => {
    return this.modulesMap[stringEntry];
  };
 
  /**
   * Retrieves all modules of a given type for all registered extensions.
   *
   * @param moduleType - The type of modules to retrieve.
   * @returns An array of modules of the specified type.
   */
  getModulesByType = (moduleType: string) => {
    return this.modules[moduleType];
  };
 
  getDataSources = dataSourceName => {
    if (dataSourceName === undefined) {
      // Default to the activeDataSource
      dataSourceName = this.activeDataSourceName;
    }
 
    // Note: this currently uses the data source name, which feels weird...
    return this.dataSourceMap[dataSourceName];
  };
 
  getDataSourceInstance = dataSourceName => {
    return this.dataSourceMap[dataSourceName][0];
  };
 
  getActiveDataSource = () => {
    return this.dataSourceMap[this.activeDataSourceName];
  };
 
  /**
   * Gets the data source definition for the given data source name.
   * If no data source name is provided, the active data source definition is
   * returned.
   * @param dataSourceName the data source name
   * @returns the data source definition
   */
  getDataSourceDefinition = dataSourceName => {
    Iif (dataSourceName === undefined) {
      // Default to the activeDataSource
      dataSourceName = this.activeDataSourceName;
    }
 
    return this.dataSourceDefs[dataSourceName];
  };
 
  /**
   * Gets the data source definition for the active data source.
   */
  getActiveDataSourceDefinition = () => {
    return this.getDataSourceDefinition(this.activeDataSourceName);
  };
 
  /**
   * Gets a formatted list of data sources suitable for UI display/selection.
   * Only returns data sources that support STOW or have a WADO root.
   * @returns Array of data source options with value, label, and placeholder
   */
  getDataSourcesForUI = () => {
    // If multi-select export is not allowed, return empty list
    Iif (this._appConfig?.allowMultiSelectExport === false) {
      return [];
    }
 
    const inactiveDataSourceNames = Object.keys(this.dataSourceMap).filter(ds => {
      const configuration = this.dataSourceDefs[ds]?.configuration;
      const isNotActiveDataSource =
        this.dataSourceDefs[ds].sourceName !== this.activeDataSourceName;
      const supportsStowOrWado = configuration?.supportsStow ?? configuration?.wadoRoot;
      return supportsStowOrWado && isNotActiveDataSource;
    });
 
    const allDatasourcesForUI = [this.activeDataSourceName, ...inactiveDataSourceNames].map(ds => ({
      value: ds,
      label: ds,
      placeHolder: ds,
    }));
 
    return allDatasourcesForUI;
  };
 
  /**
   * @private
   * @param {string} moduleType
   * @param {Object} extension
   * @param {string} extensionId - Used for logging warnings
   */
  _getExtensionModule = (moduleType, extension, extensionId, configuration) => {
    const getModuleFnName = 'get' + _capitalizeFirstCharacter(moduleType);
    const getModuleFn = extension[getModuleFnName];
 
    if (!getModuleFn) {
      return;
    }
 
    try {
      const extensionModule = extension[getModuleFnName]({
        appConfig: this._appConfig,
        commandsManager: this._commandsManager,
        servicesManager: this._servicesManager,
        hotkeysManager: this._hotkeysManager,
        extensionManager: this,
        configuration,
      });
 
      Iif (!extensionModule) {
        log.warn(
          `Null or undefined returned when registering the ${getModuleFnName} module for the ${extensionId} extension`
        );
      }
 
      return extensionModule;
    } catch (ex) {
      console.error(ex);
      throw new Error(
        `Exception thrown while trying to call ${getModuleFnName} for the ${extensionId} extension`
      );
    }
  };
 
  _initHangingProtocolsModule = (extensionModule, extensionId) => {
    const { hangingProtocolService } = this._servicesManager.services;
    extensionModule.forEach(({ name, protocol }) => {
      if (protocol) {
        // Only auto-register if protocol specified, otherwise let mode register
        hangingProtocolService.addProtocol(name, protocol);
      }
    });
  };
 
  _initPanelModule = (extensionModule, extensionId) => {
    this.processExtensionModule(extensionModule, extensionId, MODULE_TYPES.PANEL);
  };
 
  _initToolbarModule = (extensionModule, extensionId) => {
    // check if the toolbar module has a handler function for evaluation of
    // the toolbar button state
    const { toolbarService } = this._servicesManager.services;
    extensionModule.forEach(toolbarButton => {
      if (toolbarButton.evaluate) {
        toolbarService.registerEvaluateFunction(toolbarButton.name, toolbarButton.evaluate);
      }
    });
  };
 
  /**
   * Processes an extension module.
   * @param extensionModule - The extension module to process.
   * @param extensionId - The ID of the extension.
   * @param moduleType - The type of the module.
   */
  private processExtensionModule(extensionModule, extensionId: string, moduleType: string) {
    extensionModule.forEach(element => {
      Iif (!element.name) {
        throw new Error(`Extension ID ${extensionId} module ${moduleType} element has no name`);
      }
      const id = `${extensionId}.${moduleType}.${element.name}`;
      element.id = id;
      this.modulesMap[id] = element;
    });
  }
 
  /**
   * Adds the given data source and optionally sets it as the active data source.
   * The method does this by first creating the data source.
   * @param dataSourceDef the data source definition to be added
   * @param activate flag to indicate if the added data source should be set to the active data source
   */
  addDataSource(dataSourceDef: DataSourceDefinition, options = { activate: false }) {
    const existingDataSource = this.getDataSources(dataSourceDef.sourceName);
    Iif (existingDataSource?.[0]) {
      // The data source already exists and cannot be added.
      return;
    }
 
    this._createDataSourceInstance(dataSourceDef);
 
    Iif (options.activate) {
      this.setActiveDataSource(dataSourceDef.sourceName);
    }
  }
 
  /**
   * Updates the configuration of the given data source name. It first creates a new data source with
   * the existing definition and the new configuration passed in.
   * @param dataSourceName the name of the data source to update
   * @param dataSourceConfiguration the new configuration to update the data source with
   */
  updateDataSourceConfiguration(dataSourceName: string, dataSourceConfiguration: any) {
    const existingDataSource = this.getDataSources(dataSourceName);
    Iif (!existingDataSource?.[0]) {
      // Cannot update a non existent data source.
      return;
    }
 
    const dataSourceDef = this.dataSourceDefs[dataSourceName];
    // Update the configuration.
    dataSourceDef.configuration = dataSourceConfiguration;
    this._createDataSourceInstance(dataSourceDef);
 
    Iif (this.activeDataSourceName === dataSourceName) {
      // When the active data source is changed/set, fire an event to indicate that its configuration has changed.
      this._broadcastEvent(ExtensionManager.EVENTS.ACTIVE_DATA_SOURCE_CHANGED, dataSourceDef);
    }
  }
 
  /**
   * Creates a data source instance from the given definition. The definition is
   * added to dataSourceDefs and the created instance is added to dataSourceMap.
   * @param dataSourceDef
   * @returns
   */
  _createDataSourceInstance(dataSourceDef: DataSourceDefinition) {
    const module = this.getModuleEntry(dataSourceDef.namespace);
 
    Iif (!module) {
      return;
    }
 
    this.dataSourceDefs[dataSourceDef.sourceName] = dataSourceDef;
 
    const dataSourceInstance = module.createDataSource(
      dataSourceDef.configuration,
      this._servicesManager,
      this
    );
 
    this.dataSourceMap[dataSourceDef.sourceName] = [dataSourceInstance];
  }
 
  _initDataSourcesModule(
    extensionModule,
    extensionId,
    dataSources: Array<DataSourceDefinition> = []
  ): void {
    extensionModule.forEach(element => {
      this.modulesMap[`${extensionId}.${MODULE_TYPES.DATA_SOURCE}.${element.name}`] = element;
    });
 
    extensionModule.forEach(element => {
      const namespace = `${extensionId}.${MODULE_TYPES.DATA_SOURCE}.${element.name}`;
 
      dataSources.forEach(dataSource => {
        if (dataSource.namespace === namespace) {
          this.addDataSource(dataSource);
        }
      });
    });
  }
 
  /**
   *
   * @private
   * @param {Object[]} commandDefinitions
   */
  _initCommandsModule = extensionModule => {
    let { definitions, defaultContext } = extensionModule;
    Iif (!definitions || Object.keys(definitions).length === 0) {
      log.warn('Commands Module contains no command definitions');
      return;
    }
 
    defaultContext = defaultContext || 'VIEWER';
 
    if (!this._commandsManager.getContext(defaultContext)) {
      this._commandsManager.createContext(defaultContext);
    }
 
    Object.keys(definitions).forEach(commandName => {
      let commandDefinition = definitions[commandName];
      if (typeof commandDefinition === 'function') {
        commandDefinition = { commandFn: commandDefinition };
      }
      const commandHasContextThatDoesNotExist =
        commandDefinition.context && !this._commandsManager.getContext(commandDefinition.context);
 
      Iif (commandHasContextThatDoesNotExist) {
        this._commandsManager.createContext(commandDefinition.context);
      }
 
      this._commandsManager.registerCommand(
        commandDefinition.context || defaultContext,
        commandName,
        commandDefinition
      );
    });
  };
 
  public get appConfig() {
    return this._appConfig;
  }
}
 
/**
 * @private
 * @param {string} lower
 */
function _capitalizeFirstCharacter(lower) {
  return lower.charAt(0).toUpperCase() + lower.substring(1);
}