/** * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal * @author Alexander Rose */ import { Structure, Model } from '../mol-model/structure'; import { PluginContext } from './context'; export class PluginConfigItem { toString() { return this.key; } valueOf() { return this.key; } constructor(public key: string, public defaultValue?: T) { } } function item(key: string, defaultValue?: T) { return new PluginConfigItem(key, defaultValue); } export const PluginConfig = { item, General: { IsBusyTimeoutMs: item('plugin-config.is-busy-timeout', 750) }, State: { DefaultServer: item('plugin-state.server', 'https://webchem.ncbr.muni.cz/molstar-state'), CurrentServer: item('plugin-state.server', 'https://webchem.ncbr.muni.cz/molstar-state') }, VolumeStreaming: { DefaultServer: item('volume-streaming.server', 'https://ds.litemol.org'), CanStream: item('volume-streaming.can-stream', (s: Structure, plugin: PluginContext) => { return s.models.length === 1 && Model.probablyHasDensityMap(s.models[0]); }), EmdbHeaderServer: item('volume-streaming.emdb-header-server', 'https://ftp.wwpdb.org/pub/emdb/structures'), }, Viewport: { ShowExpand: item('viewer.show-expand-button', true), ShowSelectionMode: item('viewer.show-selection-model-button', true), ShowAnimation: item('viewer.show-animation-button', true), } }; export class PluginConfigManager { private _config = new Map, unknown>(); get(key: PluginConfigItem) { if (!this._config.has(key)) return key.defaultValue; return this._config.get(key) as T; } set(key: PluginConfigItem, value: T) { this._config.set(key, value); } delete(key: PluginConfigItem) { this._config.delete(key); } constructor(initial?: Map) { if (!initial) return; initial.forEach((v, k) => this._config.set(k, v)); } }