diff options
Diffstat (limited to 'packages/main/src/services')
-rw-r--r-- | packages/main/src/services/ConfigPersistenceService.ts | 6 | ||||
-rw-r--r-- | packages/main/src/services/impl/ConfigPersistenceServiceImpl.ts | 20 |
2 files changed, 14 insertions, 12 deletions
diff --git a/packages/main/src/services/ConfigPersistenceService.ts b/packages/main/src/services/ConfigPersistenceService.ts index aed0ba3..7d508c5 100644 --- a/packages/main/src/services/ConfigPersistenceService.ts +++ b/packages/main/src/services/ConfigPersistenceService.ts | |||
@@ -18,12 +18,12 @@ | |||
18 | * SPDX-License-Identifier: AGPL-3.0-only | 18 | * SPDX-License-Identifier: AGPL-3.0-only |
19 | */ | 19 | */ |
20 | 20 | ||
21 | import type { ConfigSnapshotOut } from '../stores/Config'; | 21 | import type { ConfigSnapshotOut } from '../stores/Config'; |
22 | import { Disposer } from '../utils/disposer'; | 22 | import type Disposer from '../utils/Disposer'; |
23 | 23 | ||
24 | export type ReadConfigResult = { found: true; data: unknown; } | { found: false; }; | 24 | export type ReadConfigResult = { found: true; data: unknown; } | { found: false; }; |
25 | 25 | ||
26 | export interface ConfigPersistenceService { | 26 | export default interface ConfigPersistenceService { |
27 | readConfig(): Promise<ReadConfigResult>; | 27 | readConfig(): Promise<ReadConfigResult>; |
28 | 28 | ||
29 | writeConfig(configSnapshot: ConfigSnapshotOut): Promise<void>; | 29 | writeConfig(configSnapshot: ConfigSnapshotOut): Promise<void>; |
diff --git a/packages/main/src/services/impl/ConfigPersistenceServiceImpl.ts b/packages/main/src/services/impl/ConfigPersistenceServiceImpl.ts index 2d19632..df8c807 100644 --- a/packages/main/src/services/impl/ConfigPersistenceServiceImpl.ts +++ b/packages/main/src/services/impl/ConfigPersistenceServiceImpl.ts | |||
@@ -19,18 +19,20 @@ | |||
19 | */ | 19 | */ |
20 | import { watch } from 'fs'; | 20 | import { watch } from 'fs'; |
21 | import { readFile, stat, writeFile } from 'fs/promises'; | 21 | import { readFile, stat, writeFile } from 'fs/promises'; |
22 | import JSON5 from 'json5'; | ||
23 | import { throttle } from 'lodash-es'; | ||
24 | import { join } from 'path'; | 22 | import { join } from 'path'; |
25 | 23 | ||
26 | import type { ConfigPersistenceService, ReadConfigResult } from '../ConfigPersistenceService.js'; | 24 | import JSON5 from 'json5'; |
27 | import type { ConfigSnapshotOut } from '../../stores/Config.js'; | 25 | import throttle from 'lodash-es/throttle'; |
28 | import { Disposer } from '../../utils/disposer'; | 26 | |
29 | import { getLogger } from '../../utils/logging'; | 27 | import type { ConfigSnapshotOut } from '../../stores/Config'; |
28 | import type Disposer from '../../utils/Disposer'; | ||
29 | import { getLogger } from '../../utils/log'; | ||
30 | import type ConfigPersistenceService from '../ConfigPersistenceService'; | ||
31 | import type { ReadConfigResult } from '../ConfigPersistenceService'; | ||
30 | 32 | ||
31 | const log = getLogger('configPersistence'); | 33 | const log = getLogger('configPersistence'); |
32 | 34 | ||
33 | export class ConfigPersistenceServiceImpl implements ConfigPersistenceService { | 35 | export default class ConfigPersistenceServiceImpl implements ConfigPersistenceService { |
34 | private readonly configFilePath: string; | 36 | private readonly configFilePath: string; |
35 | 37 | ||
36 | private writingConfig = false; | 38 | private writingConfig = false; |
@@ -103,7 +105,7 @@ export class ConfigPersistenceServiceImpl implements ConfigPersistenceService { | |||
103 | 'whish is newer than last written', | 105 | 'whish is newer than last written', |
104 | this.timeLastWritten, | 106 | this.timeLastWritten, |
105 | ); | 107 | ); |
106 | return callback(); | 108 | await callback(); |
107 | } | 109 | } |
108 | }, throttleMs); | 110 | }, throttleMs); |
109 | 111 | ||
@@ -115,7 +117,7 @@ export class ConfigPersistenceServiceImpl implements ConfigPersistenceService { | |||
115 | if (eventType === 'change' | 117 | if (eventType === 'change' |
116 | && (filename === this.configFileName || filename === null)) { | 118 | && (filename === this.configFileName || filename === null)) { |
117 | configChanged()?.catch((err) => { | 119 | configChanged()?.catch((err) => { |
118 | console.log('Unhandled error while listening for config changes', err); | 120 | log.error('Unhandled error while listening for config changes', err); |
119 | }); | 121 | }); |
120 | } | 122 | } |
121 | }); | 123 | }); |