config.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  6. */
  7. import { Structure, Model } from '../mol-model/structure';
  8. import { PluginContext } from './context';
  9. import { PdbDownloadProvider } from '../mol-plugin-state/actions/structure';
  10. import { EmdbDownloadProvider } from '../mol-plugin-state/actions/volume';
  11. export class PluginConfigItem<T = any> {
  12. toString() { return this.key; }
  13. valueOf() { return this.key; }
  14. constructor(public key: string, public defaultValue?: T) { }
  15. }
  16. function item<T>(key: string, defaultValue?: T) { return new PluginConfigItem(key, defaultValue); }
  17. export const PluginConfig = {
  18. item,
  19. General: {
  20. IsBusyTimeoutMs: item('plugin-config.is-busy-timeout', 750)
  21. },
  22. State: {
  23. DefaultServer: item('plugin-state.server', 'https://webchem.ncbr.muni.cz/molstar-state'),
  24. CurrentServer: item('plugin-state.server', 'https://webchem.ncbr.muni.cz/molstar-state')
  25. },
  26. VolumeStreaming: {
  27. DefaultServer: item('volume-streaming.server', 'https://ds.litemol.org'),
  28. CanStream: item('volume-streaming.can-stream', (s: Structure, plugin: PluginContext) => {
  29. return s.models.length === 1 && Model.probablyHasDensityMap(s.models[0]);
  30. }),
  31. EmdbHeaderServer: item('volume-streaming.emdb-header-server', 'https://ftp.wwpdb.org/pub/emdb/structures'),
  32. },
  33. Viewport: {
  34. ShowExpand: item('viewer.show-expand-button', true),
  35. ShowSelectionMode: item('viewer.show-selection-model-button', true),
  36. ShowAnimation: item('viewer.show-animation-button', true),
  37. },
  38. Download: {
  39. DefaultPdbProvider: item<PdbDownloadProvider>('download.default-pdb-provider', 'pdbe'),
  40. DefaultEmdbProvider: item<EmdbDownloadProvider>('download.default-emdb-provider', 'pdbe'),
  41. },
  42. Structure: {
  43. SizeThresholds: item('structure.size-thresholds', Structure.DefaultSizeThresholds),
  44. }
  45. };
  46. export class PluginConfigManager {
  47. private _config = new Map<PluginConfigItem<any>, unknown>();
  48. get<T>(key: PluginConfigItem<T>) {
  49. if (!this._config.has(key)) return key.defaultValue;
  50. return this._config.get(key) as T;
  51. }
  52. set<T>(key: PluginConfigItem<T>, value: T) {
  53. this._config.set(key, value);
  54. }
  55. delete<T>(key: PluginConfigItem<T>) {
  56. this._config.delete(key);
  57. }
  58. constructor(initial?: [PluginConfigItem, unknown][]) {
  59. if (!initial) return;
  60. initial.forEach(([k, v]) => this._config.set(k, v));
  61. }
  62. }