Best way to save a list of presets?

Hello.

What is the best way to save multiple presets (basically the states of all the elements of a plugin - checkboxes, radio.buttons, sliders, textfields, … ) between sessions and even between plugin updates?

In the end I want to have a dropdown menu where I can pick different entries and all the UI elements are set accordingly.

Cheers.

1 Like

first store your presets in an object
stringify the object and store the JSON file to local disk (plugin folder) if security is not a concern.
another option is to store the JSON string in local storage .

you will need two functions:

the saver function
to loop through element and store their settings inside an object then stringify it and store it.

the loader function
to parse the JSON and loop through properties and set settings of element accordingly

1 Like

Thanks for the reply.

Will the localstorage option stay intact after updating the plugin or after uninstalling and installing it again?

Provides a local key-value store useful for setting preferences and other kinds of data. This data is technically persistent, but can be cleared in a variety of ways, so you should not store data using localStorage that you cannot otherwise reconstruct.

Source

you may also wanna take a look at secureStorage for sensitive data

it maybe better to use a dedicated folder on local disk for presets, might be easier to share and backup too. and from what I can read local storage

can be cleared in a variety of ways

1 Like