ohif-viewer/platform/viewer/src/appInit.js
Bill Wallace 803f638401
feat: state sync service and hanging protocol updates to preserve state (#3131)
* feat: Add state sync and use it to remember viewport grid info

fix: Version updates

Fixes for toggling MPR mode

Fix the display when the interleaved load module fails

Fix the memory of the state to restore correctly

PR fixes for the state sync service

PR fixes

PR fixes

PR fixes

Added a hack warning to remove volumeDeactivate

Fixes for TMTV colormap setting

Fix the casing

Missed renames

fix: tests not running due to variance in ordering

Reverting some fixes to change case

PR changes - mostly comments and minor improvements

fix: All display sets were being updated on drag and drop

PR fixes - mostly renames

PR fixes

Test support for OHIF, for HP branch

test: Add at least a minimal set of automated tests for hanging protocols

Docs

PR fixes

Merge fixes

DOCS updates

Add an example of the mn hanging protocol

PR fixes

PR fixes

PR fixes

* Fix the drag and drop

PR fixes

* PR changes - update default keys for next/previous stage

* fix: Was storing the custom viewport grid too aggressively

Caused by a PR change misspelling a variable
2023-03-15 12:41:41 -04:00

119 lines
3.1 KiB
JavaScript

import {
CommandsManager,
ExtensionManager,
ServicesManager,
HotkeysManager,
UINotificationService,
UIModalService,
UIDialogService,
UIViewportDialogService,
MeasurementService,
StateSyncService,
DisplaySetService,
ToolbarService,
ViewportGridService,
HangingProtocolService,
CineService,
UserAuthenticationService,
errorHandler,
CustomizationService,
PanelService,
// utils,
} from '@ohif/core';
/**
* @param {object|func} appConfigOrFunc - application configuration, or a function that returns application configuration
* @param {object[]} defaultExtensions - array of extension objects
*/
async function appInit(appConfigOrFunc, defaultExtensions, defaultModes) {
const commandsManagerConfig = {
getAppState: () => {},
};
const commandsManager = new CommandsManager(commandsManagerConfig);
const servicesManager = new ServicesManager(commandsManager);
const hotkeysManager = new HotkeysManager(commandsManager, servicesManager);
const appConfig = {
...(typeof appConfigOrFunc === 'function'
? appConfigOrFunc({ servicesManager })
: appConfigOrFunc),
};
const extensionManager = new ExtensionManager({
commandsManager,
servicesManager,
hotkeysManager,
appConfig,
});
servicesManager.registerServices([
UINotificationService.REGISTRATION,
UIModalService.REGISTRATION,
UIDialogService.REGISTRATION,
UIViewportDialogService.REGISTRATION,
MeasurementService.REGISTRATION,
DisplaySetService.REGISTRATION,
[CustomizationService.REGISTRATION, appConfig.customizationService],
ToolbarService.REGISTRATION,
ViewportGridService.REGISTRATION,
HangingProtocolService.REGISTRATION,
CineService.REGISTRATION,
UserAuthenticationService.REGISTRATION,
PanelService.REGISTRATION,
StateSyncService.REGISTRATION,
]);
errorHandler.getHTTPErrorHandler = () => {
if (typeof appConfig.httpErrorHandler === 'function') {
return appConfig.httpErrorHandler;
}
};
/**
* Example: [ext1, ext2, ext3]
* Example2: [[ext1, config], ext2, [ext3, config]]
*/
await extensionManager.registerExtensions(
[...defaultExtensions, ...appConfig.extensions],
appConfig.dataSources
);
// TODO: We no longer use `utils.addServer`
// TODO: We no longer init webWorkers at app level
// TODO: We no longer init the user Manager
if (!appConfig.modes) {
throw new Error('No modes are defined! Check your app-config.js');
}
for (let i = 0; i < defaultModes.length; i++) {
const { modeFactory, id } = defaultModes[i];
// If the appConfig contains configuration for this mode, use it.
const modeConfig =
appConfig.modeConfig && appConfig.modeConfig[i]
? appConfig.modeConfig[id]
: {};
const mode = modeFactory(modeConfig);
appConfig.modes.push(mode);
}
// remove modes that are not objects, or have no id
appConfig.modes = appConfig.modes.filter(
mode => typeof mode === 'object' && mode.id
);
return {
appConfig,
commandsManager,
extensionManager,
servicesManager,
hotkeysManager,
};
}
export default appInit;