Use a single settings file and refactor settings #2640
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR completely changes how we do settings. Instead of the weird local storage thing we did, all settings are now stored in a single
settings.json
. The main process is responsible for reading and writingsettings.json
. The renderer can read and write settings via ICP channels.The main advantages of this architecture are:
settings.json
is easier for users to edit and for us to change (settings migration).Turned out, backend package settings were actually parsed incorrectly in CLI mode. Not anymore.
Since the new settings use a single
settings.json
, there is a migration from the old format (see tests for an example). This migration is the old reason whynode-locastorage
is still a dependency. We can remove it in the future, but it's still necessary right now for the backwards compatibility.I also added something called "storage." Storage is accessed using the
useStored(key: string, default: T): T
hook. This is basically a drop-in replacement for the olduseLocalStorage
hook. The main difference is thatuseStored
will store its values insettings.json
.The difference between storage and settings is that settings are used across UI components while stored values are basically
useState
of a single component that is remembered across restarts (e.g. when the node selector is open or closed). Storage is less structured.Tbh, I'm not too sure about storage. This could just be
localStorage
, but I'm not sure how that would work with migrating settings. Maybe we'll change that in the future. Idk.One thing that I haven't tested enough yet is performance. Since settings are completely reactive now, there can be more re-renders than before. This can cause perf problems. The node selector optimization PRs I recently did were because of this. Perf seems to be the same as without this change, but this still needs more testing.
It goes without saying, but this is a deep change. We should probably release this at the same time as #2597.