fixed config file getting spontaneously erased - fixes #4293

This commit is contained in:
Eugene Pankov
2021-07-31 15:28:10 +02:00
parent 94819019ec
commit 8b8bacdf69

View File

@@ -24,6 +24,7 @@ try {
export class ElectronPlatformService extends PlatformService {
supportsWindowControls = true
private configPath: string
private _configSaveInProgress = Promise.resolve()
constructor (
private hostApp: HostAppService,
@@ -107,7 +108,17 @@ export class ElectronPlatformService extends PlatformService {
}
async saveConfig (content: string): Promise<void> {
await fs.writeFile(this.configPath, content, 'utf8')
try {
await this._configSaveInProgress
} catch { }
this._configSaveInProgress = this._saveConfigInternal(content)
await this._configSaveInProgress
}
async _saveConfigInternal (content: string): Promise<void> {
const tempPath = this.configPath + '.new'
await fs.writeFile(tempPath, content, 'utf8')
await fs.rename(tempPath, this.configPath)
}
getConfigPath (): string|null {