pluto icon indicating copy to clipboard operation
pluto copied to clipboard

Please add support to Proto DataStore

Open JosephSanjaya opened this issue 2 years ago • 2 comments

Is your feature request related to a problem? Please describe. Currently im using proto datastore to support encryption, but i can't seems attach watcher because it need to use Preferences generic class.

Describe the solution you'd like Please add support Proto DataStore with custom serializer,

JosephSanjaya avatar Dec 15 '22 04:12 JosephSanjaya

hey @JosephSanjaya, can you elaborate your issue in detail?

srtvprateek avatar Dec 15 '22 11:12 srtvprateek

I'm using Proto DataStore with custom serializer, for example

DataStore<UserPrefData>

but currently PlutoDatastoreWatcher, is just supported DataStore with Preferences (DataStore Pref)

DataStore<Preferences>

you can see in com.pluto.plugins.datastore.pref.PlutoDatastoreWatcher it only support DataStore Pref.

object PlutoDatastoreWatcher {

    internal val sources = MutableStateFlow<Set<PreferenceHolder>>(emptySet())

    fun watch(name: String, store: DataStore<Preferences>) {
        sources.update { oldSet ->
            mutableSetOf<PreferenceHolder>().apply {
                addAll(oldSet)
                add(PreferenceHolder(name, store))
            }
        }
    }

    fun remove(name: String) {
        sources.update { oldSet ->
            mutableSetOf<PreferenceHolder>().apply {
                oldSet.forEach {
                    if (it.name != name) add(it)
                }
            }
        }
    }
}

internal data class PreferenceHolder(val name: String, val preferences: DataStore<Preferences>)

JosephSanjaya avatar Dec 16 '22 04:12 JosephSanjaya