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

104 lines
2.5 KiB
JavaScript
Raw Normal View History

2020-05-07 11:55:42 -03:00
import {
CommandsManager,
ExtensionManager,
ServicesManager,
HotkeysManager,
2020-05-07 11:55:42 -03:00
UINotificationService,
UIModalService,
UIDialogService,
UIViewportDialogService,
2020-05-12 21:41:11 +02:00
MeasurementService,
2020-05-18 17:21:57 +02:00
DisplaySetService,
2020-08-19 16:24:07 -03:00
ToolBarService,
ViewportGridService,
2020-08-19 16:24:07 -03:00
HangingProtocolService,
2020-09-14 21:18:46 -04:00
CineService,
2021-06-23 20:41:27 +02:00
UserAuthenticationService,
2021-06-24 12:30:38 -04:00
errorHandler
2020-05-07 11:55:42 -03:00
// utils,
} from '@ohif/core';
/**
* @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 11:55:42 -03:00
: appConfigOrFunc),
};
const commandsManagerConfig = {
2020-09-14 21:18:46 -04:00
getAppState: () => {},
2020-05-07 11:55:42 -03:00
/** Used by commands to determine active context */
2020-09-14 21:18:46 -04:00
getActiveContexts: () => [
'VIEWER',
'DEFAULT',
'ACTIVE_VIEWPORT::CORNERSTONE',
],
2020-05-07 11:55:42 -03:00
};
const commandsManager = new CommandsManager(commandsManagerConfig);
2020-09-14 21:18:46 -04:00
const servicesManager = new ServicesManager(commandsManager);
const hotkeysManager = new HotkeysManager(commandsManager, servicesManager);
2020-05-07 11:55:42 -03:00
const extensionManager = new ExtensionManager({
commandsManager,
servicesManager,
hotkeysManager,
2020-05-07 11:55:42 -03:00
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-08-19 16:24:07 -03:00
ToolBarService,
ViewportGridService,
2020-08-19 16:24:07 -03:00
HangingProtocolService,
2020-09-14 21:18:46 -04:00
CineService,
2021-06-23 20:41:27 +02:00
UserAuthenticationService,
2020-05-07 11:55:42 -03:00
]);
2021-06-24 12:30:38 -04:00
errorHandler.getHTTPErrorHandler = () => {
if (typeof appConfig.httpErrorHandler === 'function') {
return appConfig.httpErrorHandler;
}
};
2020-05-07 11:55:42 -03: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 11:55:42 -03: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
2021-06-23 20:41:27 +02:00
if (!appConfig.modes) {
throw new Error('No modes are defined! Check your app-config.js');
}
// TODO: Remove this
if (!appConfig.modes.length) {
2020-05-26 09:03:58 -04:00
appConfig.modes.push(window.longitudinalMode);
2020-07-06 08:42:06 -04:00
// appConfig.modes.push(window.segmentationMode);
}
2020-05-07 11:55:42 -03:00
return {
appConfig,
commandsManager,
extensionManager,
servicesManager,
2020-06-30 15:48:42 -04:00
hotkeysManager,
2020-05-07 11:55:42 -03:00
};
}
export default appInit;