As I was researching how to persist data in an Electron application, I came across two options: use the localStorage object which is only accessible in render process or use an Electron JSON storage module which is accessible by both main and render process and stores each data key in a JSON file in the app.getPath("userData") folder. I decided to go with the latter as I needed that data in the main process before the window is opened. For example, Electron-Storage and (the one I am using) Electron-json-storage
It appears that the data saved by these modules is being persisted through the build as well, which is causing users to have non-default behavior when they first open the app.
Is there any way to clear (or add an option to clear) this data on build in Electron-builder? Currently I have to add some code to clear all data, run the app, remove the code, and build, which is a pain.
Thanks
It appears that the data saved by these modules is being persisted through the build as well, which is causing users to have non-default behavior when they first open the app.
Users of your app are not affected. build in the build time, not in runtime. I don't understand you, sorry.
NSIS installer doesn't delete local app data on reinstall, but remove on uninstall.
@develar
Sorry for the confusion. I will give my use case to maybe clear this up.
I have some settings a user should be able to set when they first open the newly-installed app. These settings are persisted using Electron-json-storage so I can access them in my main process. My main process checks if these settings have been set and determines whether to load the initial settings page or the homepage.
The issue I am having is that these settings files seem to exist in the build.
So first I set the settings on my development mac machine while I am testing my application. When I am done, I build my installers using Electron-builder, transfer the Setup.exe installer to my windows machine, and install/open the app. However instead of opening the settings page, I get redirected to the homepage with the settings configured as they were on my development machine (as if the persisted data is being put into the installer).
build in the build time, not in runtime.
I am not building in runtime. This data is persisted as files so they still exist even when out of runtime.
NSIS installer doesn't delete local app data on reinstall, but remove on uninstall.
I am still using Squirrel for both Windows and Mac currently, not NSIS.
Silly me, I see the issue now. I was not realizing that these files were being persisted in a separate directory than the application itself (in Windows at least, they are saved in .../AppData/Roaming/myApp). I cannot believe I didn't realize that even when you said "delete local app data" 馃槄 Sorry about that.
My assumption was that uninstalling the app would delete this storage as well, which does not seem to be the case for the squirrel uninstaller. I see now that it does work initially and properly loads the page I want when I delete the AppData after uninstalling and reinstalling.
Is there a way to have the squirrel uninstaller remove the local app data, or should I just wait until NSIS is complete with auto-update and use that?
Is there a way to have the squirrel uninstaller remove the local app data
@Mercieral Perform the removal in your --squirrel-uninstall handler.
Most helpful comment
@Mercieral Perform the removal in your
--squirrel-uninstallhandler.