mirror of
https://github.com/null2264/yokai.git
synced 2025-07-16 22:06:54 +00:00
feat: Refresh repo actually refresh trust status
This commit is contained in:
parent
fb5e581ec5
commit
fe859f07c4
3 changed files with 22 additions and 2 deletions
|
@ -12,10 +12,14 @@ class TrustExtension(
|
||||||
private val extensionRepoRepository: ExtensionRepoRepository,
|
private val extensionRepoRepository: ExtensionRepoRepository,
|
||||||
private val sourcePreferences: SourcePreferences,
|
private val sourcePreferences: SourcePreferences,
|
||||||
) {
|
) {
|
||||||
suspend fun isTrusted(pkgInfo: PackageInfo, fingerprints: List<String>): Boolean {
|
suspend fun isTrustedByRepo(fingerprints: List<String>): Boolean {
|
||||||
val trustedFingerprints = extensionRepoRepository.getAll().map { it.signingKeyFingerprint }.toHashSet()
|
val trustedFingerprints = extensionRepoRepository.getAll().map { it.signingKeyFingerprint }.toHashSet()
|
||||||
|
return trustedFingerprints.any { fingerprints.contains(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun isTrusted(pkgInfo: PackageInfo, fingerprints: List<String>): Boolean {
|
||||||
val key = "${pkgInfo.packageName}:${PackageInfoCompat.getLongVersionCode(pkgInfo)}:${fingerprints.last()}"
|
val key = "${pkgInfo.packageName}:${PackageInfoCompat.getLongVersionCode(pkgInfo)}:${fingerprints.last()}"
|
||||||
return trustedFingerprints.any { fingerprints.contains(it) } || key in sourcePreferences.trustedExtensions().get()
|
return isTrustedByRepo(fingerprints) || key in sourcePreferences.trustedExtensions().get()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun trust(pkgName: String, versionCode: Long, signatureHash: String) {
|
fun trust(pkgName: String, versionCode: Long, signatureHash: String) {
|
||||||
|
|
|
@ -13,6 +13,7 @@ import dev.yokai.domain.extension.repo.interactor.ReplaceExtensionRepo
|
||||||
import dev.yokai.domain.extension.repo.interactor.UpdateExtensionRepo
|
import dev.yokai.domain.extension.repo.interactor.UpdateExtensionRepo
|
||||||
import dev.yokai.domain.extension.repo.model.ExtensionRepo
|
import dev.yokai.domain.extension.repo.model.ExtensionRepo
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
|
import eu.kanade.tachiyomi.extension.ExtensionManager
|
||||||
import eu.kanade.tachiyomi.util.system.launchIO
|
import eu.kanade.tachiyomi.util.system.launchIO
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
@ -25,6 +26,8 @@ import uy.kohesive.injekt.injectLazy
|
||||||
class ExtensionRepoViewModel :
|
class ExtensionRepoViewModel :
|
||||||
ViewModel() {
|
ViewModel() {
|
||||||
|
|
||||||
|
private val extensionManager: ExtensionManager by injectLazy()
|
||||||
|
|
||||||
private val getExtensionRepo: GetExtensionRepo by injectLazy()
|
private val getExtensionRepo: GetExtensionRepo by injectLazy()
|
||||||
private val createExtensionRepo: CreateExtensionRepo by injectLazy()
|
private val createExtensionRepo: CreateExtensionRepo by injectLazy()
|
||||||
private val deleteExtensionRepo: DeleteExtensionRepo by injectLazy()
|
private val deleteExtensionRepo: DeleteExtensionRepo by injectLazy()
|
||||||
|
@ -41,6 +44,7 @@ class ExtensionRepoViewModel :
|
||||||
viewModelScope.launchIO {
|
viewModelScope.launchIO {
|
||||||
getExtensionRepo.subscribeAll().collectLatest { repos ->
|
getExtensionRepo.subscribeAll().collectLatest { repos ->
|
||||||
mutableRepoState.update { ExtensionRepoState.Success(repos = repos.toImmutableList()) }
|
mutableRepoState.update { ExtensionRepoState.Success(repos = repos.toImmutableList()) }
|
||||||
|
extensionManager.refreshTrust()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -308,6 +308,14 @@ class ExtensionManager(
|
||||||
installer.uninstallApk(pkgName)
|
installer.uninstallApk(pkgName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun refreshTrust() {
|
||||||
|
val nowTrustedExtensions = untrustedExtensionsFlow.value
|
||||||
|
.filter { trustExtension.isTrustedByRepo(listOf(it.signatureHash)) }
|
||||||
|
_untrustedExtensionsFlow.value -= nowTrustedExtensions
|
||||||
|
|
||||||
|
registerNewTrusted(nowTrustedExtensions)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the given extension to the list of trusted extensions. It also loads in background the
|
* Adds the given extension to the list of trusted extensions. It also loads in background the
|
||||||
* now trusted extensions.
|
* now trusted extensions.
|
||||||
|
@ -326,6 +334,10 @@ class ExtensionManager(
|
||||||
.filter { it.pkgName == pkgName && it.versionCode == versionCode }
|
.filter { it.pkgName == pkgName && it.versionCode == versionCode }
|
||||||
_untrustedExtensionsFlow.value -= nowTrustedExtensions
|
_untrustedExtensionsFlow.value -= nowTrustedExtensions
|
||||||
|
|
||||||
|
registerNewTrusted(nowTrustedExtensions)
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun registerNewTrusted(nowTrustedExtensions: List<Extension.Untrusted>) {
|
||||||
launchNow {
|
launchNow {
|
||||||
nowTrustedExtensions
|
nowTrustedExtensions
|
||||||
.map { extension ->
|
.map { extension ->
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue