From 8b8bacdf6953545d5c6b01b5d4455c2ca624a720 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Sat, 31 Jul 2021 15:28:10 +0200 Subject: [PATCH] fixed config file getting spontaneously erased - fixes #4293 --- tabby-electron/src/services/platform.service.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tabby-electron/src/services/platform.service.ts b/tabby-electron/src/services/platform.service.ts index 1a74731a..5de96b4c 100644 --- a/tabby-electron/src/services/platform.service.ts +++ b/tabby-electron/src/services/platform.service.ts @@ -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 { - 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 { + const tempPath = this.configPath + '.new' + await fs.writeFile(tempPath, content, 'utf8') + await fs.rename(tempPath, this.configPath) } getConfigPath (): string|null {