Reload extensions when relevant settings are updated (#3954)
This commit is contained in:
@@ -4,6 +4,11 @@ import android.content.pm.PackageInfo
|
||||
import androidx.core.content.pm.PackageInfoCompat
|
||||
import dev.zacsweers.metro.Inject
|
||||
import eu.kanade.domain.source.service.SourcePreferences
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.merge
|
||||
import mihon.domain.extension.repository.ExtensionStoreRepository
|
||||
import tachiyomi.core.common.preference.getAndSet
|
||||
|
||||
@@ -31,4 +36,23 @@ class TrustExtension(
|
||||
fun revokeAll() {
|
||||
preferences.trustedExtensions.delete()
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits whenever what counts as trusted changes, either because a store was added or removed or
|
||||
* because an extension was trusted or had its trust revoked. Both sources replay their current
|
||||
* value, which is dropped.
|
||||
*/
|
||||
fun changes(): Flow<Unit> {
|
||||
return merge(
|
||||
// Stores are rewritten whenever their index is refreshed, so only their keys matter here
|
||||
repository.getAllAsFlow()
|
||||
.map { stores -> stores.mapTo(HashSet()) { it.signingKey } }
|
||||
.distinctUntilChanged()
|
||||
.drop(1),
|
||||
preferences.trustedExtensions.changes()
|
||||
.distinctUntilChanged()
|
||||
.drop(1),
|
||||
)
|
||||
.map {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user