ohif-viewer/platform/viewer/src/appInit.js

88 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-05-07 16:55:42 +02:00
import {
CommandsManager,
ExtensionManager,
ServicesManager,
HotkeysManager,
2020-05-07 16:55:42 +02:00
UINotificationService,
UIModalService,
UIDialogService,
UIViewportDialogService,
2020-05-12 21:41:11 +02:00
MeasurementService,
2020-05-18 17:21:57 +02:00
DisplaySetService,
2020-05-19 11:01:44 +02:00
ToolBarSerivce,
ViewportGridService,
2020-05-07 16:55:42 +02:00
// utils,
// redux as reduxOHIF,
} from '@ohif/core';
2020-06-05 17:36:11 +02:00
// TODO -> this feels bad.
2020-05-07 16:55:42 +02:00
/**
* @param {object|func} appConfigOrFunc - application configuration, or a function that returns application configuration
* @param {object[]} defaultExtensions - array of extension objects
*/
function appInit(appConfigOrFunc, defaultExtensions) {
const appConfig = {
...(typeof appConfigOrFunc === 'function'
? appConfigOrFunc({ servicesManager })
2020-05-07 16:55:42 +02:00
: appConfigOrFunc),
};
// TODO: Wire this up to Rodrigo's basic Context "ContextService"
2020-05-07 16:55:42 +02:00
const commandsManagerConfig = {
/** Used by commands to inject `viewports` from "redux" */
getAppState: () => { },
2020-05-07 16:55:42 +02:00
/** Used by commands to determine active context */
getActiveContexts: () => ['VIEWER', 'DEFAULT', 'ACTIVE_VIEWPORT::CORNERSTONE'],
2020-05-07 16:55:42 +02:00
};
2020-05-07 16:55:42 +02:00
const servicesManager = new ServicesManager();
const commandsManager = new CommandsManager(commandsManagerConfig);
const hotkeysManager = new HotkeysManager(commandsManager, servicesManager);
2020-05-07 16:55:42 +02:00
const extensionManager = new ExtensionManager({
commandsManager,
servicesManager,
appConfig,
});
servicesManager.registerServices([
UINotificationService,
UIModalService,
UIDialogService,
UIViewportDialogService,
2020-05-12 21:41:11 +02:00
MeasurementService,
2020-05-18 17:21:57 +02:00
DisplaySetService,
2020-05-19 11:01:44 +02:00
ToolBarSerivce,
ViewportGridService,
2020-05-07 16:55:42 +02:00
]);
/**
* Example: [ext1, ext2, ext3]
* Example2: [[ext1, config], ext2, [ext3, config]]
*/
2020-05-11 18:56:46 +02:00
extensionManager.registerExtensions(
[...defaultExtensions, ...appConfig.extensions],
appConfig.dataSources
);
2020-05-07 16:55:42 +02:00
// TODO: We no longer use `utils.addServer`
// TODO: We no longer init webWorkers at app level
// TODO: We no longer init the user Manager
// TODO: Remove this
if (!appConfig.modes.length) {
2020-05-26 15:03:58 +02:00
appConfig.modes.push(window.longitudinalMode);
2020-07-06 14:42:06 +02:00
// appConfig.modes.push(window.segmentationMode);
}
2020-05-07 16:55:42 +02:00
return {
appConfig,
commandsManager,
extensionManager,
servicesManager,
2020-06-30 21:48:42 +02:00
hotkeysManager,
2020-05-07 16:55:42 +02:00
};
}
export default appInit;