nathanbuchar / electron-settings

📝 A simple persistent user settings framework for Electron.
https://electron-settings.js.org
MIT License
817 stars 60 forks source link

Setting file with unexped ended json #160

Open linonetwo opened 3 years ago

linonetwo commented 3 years ago

{"workspaces":{"bd2761d6-507f-4099-9289-8c15fdca3673":{"storageService":"local","userName":"","gitUrl":null,"isSubWiki":false,"mainWikiToLink":null,"mainWikiID":null,"name":"wiki","tagName":null,"port":5212,"wikiFolderLocation":"E:\twtest\001\wiki","active":true,"disableAudio":false,"disableNotifications":false,"hibernated":false,"hibernateWhenUnused":false,"homeUrl":"http://0.0.0.0:5212","id":"bd2761d6-507f-4099-9289-8c15fdca3673","lastUrl":"http://192.168.80.129:5212/#GettingStarted:GettingStarted","order":1,"picturePath":null,"subWikiFolderName":"subwiki","syncOnInterval":false,"syncOnIntervalDebounced":false,"syncOnStartup":true,"transparentBackground":false},"4339c1e8-1b86-43f4-a7f4-515eb584b46a":{"storageService":"local","userName":"","gitUrl":null,"isSubWiki":false,"mainWikiToLink":null,"mainWikiID":null,"name":"002","tagName":null,"port":5213,"wikiFolderLocation":"E:\\twtest\\002","active":false,"disableAudio":false,"disableNotifications":false,"hibernated":false,"hibernateWhenUnused":false,"homeUrl":"http://0.0.0.0:5213","id":"4339c1e8-1b86-43f4-a7f4-515eb584b46a","lastUrl":"http://192.168.80.129:5213/#","order":2,"picturePath":null,"subWikiFolderName":"subwiki","syncOnInterval":false,"syncOnIntervalDebounced":false,"syncOnStartup":true,"transparentBackground":false}}}ransparentBackground":false}}}

Look at the }}}ransparentBackground":false}}} in the end, probably this is the result of disabling atomicSave in https://github.com/nathanbuchar/electron-settings/issues/159?

linonetwo commented 3 years ago

This is caused by quickly call await settings.set(workspaces.${id}, { ...workspace }); in

  public async set(id: string, workspace: IWorkspace): Promise<void> {
    this.workspaces[id] = this.sanitizeWorkspace(workspace);
    await this.reactBeforeWorkspaceChanged(workspace);
    await settings.set(`workspaces.${id}`, { ...workspace });
    await this.updateWorkspaceSubject();
    await this.updateWorkspaceMenuItems();
  }
PeterBenko commented 1 year ago

Looks like the default name for the settings file has changed between versions 3.2.0 and 4.0.0: before vs after

linonetwo commented 1 year ago

I fixed broken json using best-effort-json-parser package.

PeterBenko commented 1 year ago

Ah, fair. I guess I misunderstood your initial ticket :)