UNPKG

@robotical/roboticaljs

Version:

Javascript/TS library for Robotical products

56 lines 1.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class SettingsManager { constructor() { var _a; this.storageKey = "RaftJS_Settings"; this.maxChartDataPoints_default = 50; this.maxDatapointsToStore_default = 1000; // Load settings from localStorage or use default values const savedSettings = (_a = window.localStorage) === null || _a === void 0 ? void 0 : _a.getItem(this.storageKey); this.settings = savedSettings ? JSON.parse(savedSettings) : { latencyTest: false, showCharts: true, maxChartDataPoints: this.maxChartDataPoints_default, maxDatapointsToStore: this.maxDatapointsToStore_default, }; } static getInstance() { if (!SettingsManager.instance) { SettingsManager.instance = new SettingsManager(); } return SettingsManager.instance; } getSetting(key) { return this.settings[key]; } setSetting(key, value) { this.settings[key] = value; this.saveSettings(); } getAllSettings() { return this.settings; } // Save settings to localStorage saveSettings() { var _a; // if accessed from phone localStorage is not available (_a = window.localStorage) === null || _a === void 0 ? void 0 : _a.setItem(this.storageKey, JSON.stringify(this.settings)); } // Reset to default settings resetSettings() { this.settings = { latencyTest: false, showCharts: true, maxChartDataPoints: this.maxChartDataPoints_default, maxDatapointsToStore: this.maxDatapointsToStore_default, latencyAttributeName: "", latencyChangeThreshold: 0, }; this.saveSettings(); } } exports.default = SettingsManager; //# sourceMappingURL=SettingsManager.js.map