From 087113d8a1214ba4c7df03bfe66747d8d944280c Mon Sep 17 00:00:00 2001 From: Markus Hatvan Date: Tue, 14 Sep 2021 11:03:28 +0200 Subject: chore: convert JS to TS (#1934) --- src/electron/Settings.js | 61 ------------------------------------------------ 1 file changed, 61 deletions(-) delete mode 100644 src/electron/Settings.js (limited to 'src/electron/Settings.js') diff --git a/src/electron/Settings.js b/src/electron/Settings.js deleted file mode 100644 index 3e11bb175..000000000 --- a/src/electron/Settings.js +++ /dev/null @@ -1,61 +0,0 @@ -import { observable, toJS } from 'mobx'; -import { pathExistsSync, outputJsonSync, readJsonSync } from 'fs-extra'; -import { userDataPath } from '../environment'; - -const debug = require('debug')('Ferdi:Settings'); - -export default class Settings { - type = ''; - - @observable store = {}; - - constructor(type, defaultState = {}) { - this.type = type; - this.store = defaultState; - this.defaultState = defaultState; - - if (!pathExistsSync(this.settingsFile)) { - this._writeFile(); - } else { - this._hydrate(); - } - } - - set(settings) { - this.store = this._merge(settings); - - this._writeFile(); - } - - get all() { - return this.store; - } - - get allSerialized() { - return toJS(this.store); - } - - get(key) { - return this.store[key]; - } - - _merge(settings) { - return Object.assign(this.defaultState, this.store, settings); - } - - _hydrate() { - this.store = this._merge(readJsonSync(this.settingsFile)); - debug('Hydrate store', this.type, this.allSerialized); - } - - _writeFile() { - outputJsonSync(this.settingsFile, this.store, { - spaces: 2, - }); - debug('Write settings file', this.type, this.allSerialized); - } - - get settingsFile() { - return userDataPath('config', `${this.type === 'app' ? 'settings' : this.type}.json`); - } -} -- cgit v1.2.3-70-g09d2