diff options
Diffstat (limited to 'packages/main/src/services/impl/ConfigPersistenceServiceImpl.ts')
-rw-r--r-- | packages/main/src/services/impl/ConfigPersistenceServiceImpl.ts | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/packages/main/src/services/impl/ConfigPersistenceServiceImpl.ts b/packages/main/src/services/impl/ConfigPersistenceServiceImpl.ts index df8c807..e92f706 100644 --- a/packages/main/src/services/impl/ConfigPersistenceServiceImpl.ts +++ b/packages/main/src/services/impl/ConfigPersistenceServiceImpl.ts | |||
@@ -32,7 +32,9 @@ import type { ReadConfigResult } from '../ConfigPersistenceService'; | |||
32 | 32 | ||
33 | const log = getLogger('configPersistence'); | 33 | const log = getLogger('configPersistence'); |
34 | 34 | ||
35 | export default class ConfigPersistenceServiceImpl implements ConfigPersistenceService { | 35 | export default class ConfigPersistenceServiceImpl |
36 | implements ConfigPersistenceService | ||
37 | { | ||
36 | private readonly configFilePath: string; | 38 | private readonly configFilePath: string; |
37 | 39 | ||
38 | private writingConfig = false; | 40 | private writingConfig = false; |
@@ -92,13 +94,19 @@ export default class ConfigPersistenceServiceImpl implements ConfigPersistenceSe | |||
92 | log.trace('Config file last modified at', mtime); | 94 | log.trace('Config file last modified at', mtime); |
93 | } catch (err) { | 95 | } catch (err) { |
94 | if ((err as NodeJS.ErrnoException).code === 'ENOENT') { | 96 | if ((err as NodeJS.ErrnoException).code === 'ENOENT') { |
95 | log.debug('Config file', this.configFilePath, 'was deleted after being changed'); | 97 | log.debug( |
98 | 'Config file', | ||
99 | this.configFilePath, | ||
100 | 'was deleted after being changed', | ||
101 | ); | ||
96 | return; | 102 | return; |
97 | } | 103 | } |
98 | throw err; | 104 | throw err; |
99 | } | 105 | } |
100 | if (!this.writingConfig | 106 | if ( |
101 | && (this.timeLastWritten === null || mtime > this.timeLastWritten)) { | 107 | !this.writingConfig && |
108 | (this.timeLastWritten === null || mtime > this.timeLastWritten) | ||
109 | ) { | ||
102 | log.debug( | 110 | log.debug( |
103 | 'Found a config file modified at', | 111 | 'Found a config file modified at', |
104 | mtime, | 112 | mtime, |
@@ -114,8 +122,10 @@ export default class ConfigPersistenceServiceImpl implements ConfigPersistenceSe | |||
114 | }); | 122 | }); |
115 | 123 | ||
116 | watcher.on('change', (eventType, filename) => { | 124 | watcher.on('change', (eventType, filename) => { |
117 | if (eventType === 'change' | 125 | if ( |
118 | && (filename === this.configFileName || filename === null)) { | 126 | eventType === 'change' && |
127 | (filename === this.configFileName || filename === null) | ||
128 | ) { | ||
119 | configChanged()?.catch((err) => { | 129 | configChanged()?.catch((err) => { |
120 | log.error('Unhandled error while listening for config changes', err); | 130 | log.error('Unhandled error while listening for config changes', err); |
121 | }); | 131 | }); |