mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-05-18 16:01:44 +00:00
Fix potential memory leak in PluginViewModel flow collectors
- Replaced three separate flow collectors with a single combined flow - Prevents potential race conditions and reduces coroutine overhead - Uses combine() to merge pluginsEnabled, repositories, and scrapers flows - Single collector updates UI state atomically for all three values This ensures that flow collection is more efficient and reduces the risk of memory leaks from multiple concurrent collectors.
This commit is contained in:
parent
f5ead7c729
commit
a5c6dbaa7c
1 changed files with 15 additions and 14 deletions
|
|
@ -7,6 +7,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
@ -25,20 +26,20 @@ class PluginViewModel @Inject constructor(
|
||||||
|
|
||||||
private fun observePluginData() {
|
private fun observePluginData() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
pluginManager.pluginsEnabled.collect { enabled ->
|
combine(
|
||||||
_uiState.update { it.copy(pluginsEnabled = enabled) }
|
pluginManager.pluginsEnabled,
|
||||||
}
|
pluginManager.repositories,
|
||||||
}
|
pluginManager.scrapers
|
||||||
|
) { enabled, repos, scrapers ->
|
||||||
viewModelScope.launch {
|
Triple(enabled, repos, scrapers)
|
||||||
pluginManager.repositories.collect { repos ->
|
}.collect { (enabled, repos, scrapers) ->
|
||||||
_uiState.update { it.copy(repositories = repos) }
|
_uiState.update {
|
||||||
}
|
it.copy(
|
||||||
}
|
pluginsEnabled = enabled,
|
||||||
|
repositories = repos,
|
||||||
viewModelScope.launch {
|
scrapers = scrapers
|
||||||
pluginManager.scrapers.collect { scraperList ->
|
)
|
||||||
_uiState.update { it.copy(scrapers = scraperList) }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue