diff options
author | Ricardo Cino <ricardo@cino.io> | 2022-06-26 01:21:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-25 23:21:07 +0000 |
commit | af814d7cfff7e1ca3c27f8a25d498d3439debabb (patch) | |
tree | e56ec1ef4efdb2c07ac37884b0a629ab7756632b /src/electron/Settings.ts | |
parent | Update 'CHANGELOG.md' for '6.0.0-beta.2' release [skip ci] (diff) | |
download | ferdium-app-af814d7cfff7e1ca3c27f8a25d498d3439debabb.tar.gz ferdium-app-af814d7cfff7e1ca3c27f8a25d498d3439debabb.tar.zst ferdium-app-af814d7cfff7e1ca3c27f8a25d498d3439debabb.zip |
chore: add more strict types in electron directory (#367)
Diffstat (limited to 'src/electron/Settings.ts')
-rw-r--r-- | src/electron/Settings.ts | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/electron/Settings.ts b/src/electron/Settings.ts index de010b9a3..d09ac7fb6 100644 --- a/src/electron/Settings.ts +++ b/src/electron/Settings.ts | |||
@@ -5,11 +5,11 @@ import { userDataPath } from '../environment-remote'; | |||
5 | const debug = require('../preload-safe-debug')('Ferdium:Settings'); | 5 | const debug = require('../preload-safe-debug')('Ferdium:Settings'); |
6 | 6 | ||
7 | export default class Settings { | 7 | export default class Settings { |
8 | type = ''; | 8 | type: string = ''; |
9 | 9 | ||
10 | defaultState: {}; | 10 | defaultState: object; |
11 | 11 | ||
12 | @observable store = {}; | 12 | @observable store: object = {}; |
13 | 13 | ||
14 | constructor(type: string, defaultState = {}) { | 14 | constructor(type: string, defaultState = {}) { |
15 | this.type = type; | 15 | this.type = type; |
@@ -23,41 +23,41 @@ export default class Settings { | |||
23 | } | 23 | } |
24 | } | 24 | } |
25 | 25 | ||
26 | set(settings) { | 26 | set(settings: object): void { |
27 | this.store = this._merge(settings); | 27 | this.store = this._merge(settings); |
28 | 28 | ||
29 | this._writeFile(); | 29 | this._writeFile(); |
30 | } | 30 | } |
31 | 31 | ||
32 | get all() { | 32 | get all(): object { |
33 | return this.store; | 33 | return this.store; |
34 | } | 34 | } |
35 | 35 | ||
36 | get allSerialized() { | 36 | get allSerialized(): object { |
37 | return toJS(this.store); | 37 | return toJS(this.store); |
38 | } | 38 | } |
39 | 39 | ||
40 | get(key: string | number) { | 40 | get(key: string | number): any { |
41 | return this.store[key]; | 41 | return this.store[key]; |
42 | } | 42 | } |
43 | 43 | ||
44 | _merge(settings) { | 44 | _merge(settings: object): object { |
45 | return Object.assign(this.defaultState, this.store, settings); | 45 | return Object.assign(this.defaultState, this.store, settings); |
46 | } | 46 | } |
47 | 47 | ||
48 | _hydrate() { | 48 | _hydrate(): void { |
49 | this.store = this._merge(readJsonSync(this.settingsFile)); | 49 | this.store = this._merge(readJsonSync(this.settingsFile)); |
50 | debug('Hydrate store', this.type, this.allSerialized); | 50 | debug('Hydrate store', this.type, this.allSerialized); |
51 | } | 51 | } |
52 | 52 | ||
53 | _writeFile() { | 53 | _writeFile(): void { |
54 | outputJsonSync(this.settingsFile, this.store, { | 54 | outputJsonSync(this.settingsFile, this.store, { |
55 | spaces: 2, | 55 | spaces: 2, |
56 | }); | 56 | }); |
57 | debug('Write settings file', this.type, this.allSerialized); | 57 | debug('Write settings file', this.type, this.allSerialized); |
58 | } | 58 | } |
59 | 59 | ||
60 | get settingsFile() { | 60 | get settingsFile(): string { |
61 | return userDataPath( | 61 | return userDataPath( |
62 | 'config', | 62 | 'config', |
63 | `${this.type === 'app' ? 'settings' : this.type}.json`, | 63 | `${this.type === 'app' ? 'settings' : this.type}.json`, |