Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileSettings implementation #225

Open
vanniktech opened this issue Dec 20, 2024 · 1 comment
Open

FileSettings implementation #225

vanniktech opened this issue Dec 20, 2024 · 1 comment

Comments

@vanniktech
Copy link
Contributor

I'm currently on JVM and I am using PreferencesSettings.Factory with Preferences.userRoot(). The key/value pairs are written into $HOME/Library/Preferences/com.apple.java.util.prefs.plist. Other apps are also writing into this file though so you could potentially overwrite values. This can be solved by something like Preferences.userRoot().node("com.my.app.id). This brings me to my second point though that clearing them is tricky. My app also has a database and local files all of which are saved in a folder of mine. I'd like my settings to be also stored in that exact same directory, that way all the data belongs together. Clearing all the data manually, is easy since I just need to delete the directory.

Therefore I'd like to see a FileSettings implementation that writes the key/value pairs to a File. The implementation could be just 100% what Android does with SharedPreferences. So an XML file, a FileSettings.Factory method where if you pass a name you get a different xml file.

@russhwolf
Copy link
Owner

I'm potentially open to this, but somewhat wary because this would require that the library own more of the storage implementation details than most existing Settings implementations. I'm not convinced that simply copying what SharedPreferences does would be the best way forward, though it would certainly make implementation easier. But you're welcome to give it a try in your own code and report back here on how it goes.

Alternatively, you could explore migrating to DataStore or DataStoreSettings. DataStore does something similar to what you want, but in a Flow-based API. It's backed by an explicit file which you can delete as needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants