Keep an installed extension's store current as stores change

Extensions only reload when the set of signing keys changes, so one could keep a store that was removed while another with the same key stayed, or a store's old name. The manager now reassigns each installed extension's store whenever the stores change.
This commit is contained in:
AntsyLich
2026-09-28 00:52:24 +06:00
parent 4f33486aa4
commit 09edf7dc8d
@@ -30,9 +30,11 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import logcat.LogPriority
import mihon.domain.extension.interactor.UpdateExtensionStores
import mihon.domain.extension.model.ExtensionStore
import mihon.domain.extension.repository.ExtensionStoreRepository
import tachiyomi.core.common.util.lang.withIOContext
import tachiyomi.core.common.util.lang.withUIContext
@@ -91,6 +93,13 @@ class ExtensionManager(
)
.collectLatest { loadExtensions() }
}
// Extensions are only reloaded when the set of signing keys changes, which misses a store being
// removed while another with the same key stays, or a store being renamed
scope.launch(Dispatchers.IO) {
initialized.await()
extensionStoreRepository.getAllAsFlow().collect(::assignStores)
}
}
private var subLanguagesEnabledOnFirstRun = preferences.enabledLanguages.isSet()
@@ -378,6 +387,17 @@ class ExtensionManager(
updatePendingUpdatesCount()
}
private fun assignStores(stores: List<ExtensionStore>) {
fun Extension.Installed.signingStore() = stores.firstOrNull { it.signingKey in signatures }
loadedExtensionMapFlow.update { extensions ->
extensions.mapValues { (_, extension) -> extension.copy(store = extension.signingStore()) }
}
notLoadedExtensionMapFlow.update { extensions ->
extensions.mapValues { (_, extension) -> extension.copy(store = extension.signingStore()) }
}
}
private fun updatePendingUpdatesCount() {
val pendingUpdateCount = (loadedExtensionMapFlow.value.values + notLoadedExtensionMapFlow.value.values)
.count { it.hasUpdate }