From 83c3ba3a9746694839bbb6134e131a9163281755 Mon Sep 17 00:00:00 2001 From: tiddlygit-test Date: Thu, 2 Dec 2021 01:33:11 +0800 Subject: [PATCH] fix: debounce setting file write fixes https://github.com/tiddly-gittly/TiddlyGit-Desktop/issues/149 --- src/services/workspaces/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/services/workspaces/index.ts b/src/services/workspaces/index.ts index d2487a4a2..7533e1994 100644 --- a/src/services/workspaces/index.ts +++ b/src/services/workspaces/index.ts @@ -3,7 +3,7 @@ import { injectable } from 'inversify'; import { app } from 'electron'; import settings from 'electron-settings'; -import { pickBy, mapValues } from 'lodash'; +import { pickBy, mapValues, debounce } from 'lodash'; import { v4 as uuid } from 'uuid'; import path from 'path'; import fsExtra from 'fs-extra'; @@ -25,6 +25,8 @@ import type { IWorkspaceService, IWorkspace, IWorkspaceMetaData, INewWorkspaceCo import i18n from '@services/libs/i18n'; import { defaultServerIP } from '@/constants/urls'; +const debouncedSetSettingFile = debounce(async (id: string, workspace: IWorkspace) => await settings.set(`workspaces.${id}`, { ...workspace }), 500); + @injectable() export class Workspace implements IWorkspaceService { /** @@ -194,7 +196,7 @@ export class Workspace implements IWorkspaceService { public async set(id: string, workspace: IWorkspace): Promise { this.workspaces[id] = this.sanitizeWorkspace(workspace); await this.reactBeforeWorkspaceChanged(workspace); - await settings.set(`workspaces.${id}`, { ...workspace }); + await debouncedSetSettingFile(id, workspace); await this.updateWorkspaceSubject(); await this.updateWorkspaceMenuItems(); }