diff options
Diffstat (limited to 'packages/main/src/infrastructure/config/impl/ConfigFile.ts')
-rw-r--r-- | packages/main/src/infrastructure/config/impl/ConfigFile.ts | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/packages/main/src/infrastructure/config/impl/ConfigFile.ts b/packages/main/src/infrastructure/config/impl/ConfigFile.ts index c4e6d22..8b110a2 100644 --- a/packages/main/src/infrastructure/config/impl/ConfigFile.ts +++ b/packages/main/src/infrastructure/config/impl/ConfigFile.ts | |||
@@ -24,7 +24,6 @@ import path from 'node:path'; | |||
24 | 24 | ||
25 | import { throttle } from 'lodash-es'; | 25 | import { throttle } from 'lodash-es'; |
26 | 26 | ||
27 | import type Config from '../../../stores/config/Config'; | ||
28 | import type Disposer from '../../../utils/Disposer'; | 27 | import type Disposer from '../../../utils/Disposer'; |
29 | import isErrno from '../../../utils/isErrno'; | 28 | import isErrno from '../../../utils/isErrno'; |
30 | import { getLogger } from '../../../utils/log'; | 29 | import { getLogger } from '../../../utils/log'; |
@@ -48,9 +47,9 @@ export default class ConfigFile implements ConfigRepository { | |||
48 | } | 47 | } |
49 | 48 | ||
50 | async readConfig(): Promise<ReadConfigResult> { | 49 | async readConfig(): Promise<ReadConfigResult> { |
51 | let configStr: string; | 50 | let contents: string; |
52 | try { | 51 | try { |
53 | configStr = await readFile(this.configFilePath, 'utf8'); | 52 | contents = await readFile(this.configFilePath, 'utf8'); |
54 | } catch (error) { | 53 | } catch (error) { |
55 | if (isErrno(error, 'ENOENT')) { | 54 | if (isErrno(error, 'ENOENT')) { |
56 | log.debug('Config file', this.configFilePath, 'was not found'); | 55 | log.debug('Config file', this.configFilePath, 'was not found'); |
@@ -61,15 +60,14 @@ export default class ConfigFile implements ConfigRepository { | |||
61 | log.info('Read config file', this.configFilePath); | 60 | log.info('Read config file', this.configFilePath); |
62 | return { | 61 | return { |
63 | found: true, | 62 | found: true, |
64 | data: JSON.parse(configStr), | 63 | contents, |
65 | }; | 64 | }; |
66 | } | 65 | } |
67 | 66 | ||
68 | async writeConfig(configSnapshot: Config): Promise<void> { | 67 | async writeConfig(contents: string): Promise<void> { |
69 | const configJson = JSON.stringify(configSnapshot, undefined, 2); | ||
70 | this.writingConfig = true; | 68 | this.writingConfig = true; |
71 | try { | 69 | try { |
72 | await writeFile(this.configFilePath, configJson, 'utf8'); | 70 | await writeFile(this.configFilePath, contents, 'utf8'); |
73 | const { mtime } = await stat(this.configFilePath); | 71 | const { mtime } = await stat(this.configFilePath); |
74 | log.trace('Config file', this.configFilePath, 'last written at', mtime); | 72 | log.trace('Config file', this.configFilePath, 'last written at', mtime); |
75 | this.timeLastWritten = mtime; | 73 | this.timeLastWritten = mtime; |