diff --git a/data/provider/src/main/kotlin/com/flixclusive/data/provider/ProviderManager.kt b/data/provider/src/main/kotlin/com/flixclusive/data/provider/ProviderManager.kt index 43c73eaac..58b3ce012 100644 --- a/data/provider/src/main/kotlin/com/flixclusive/data/provider/ProviderManager.kt +++ b/data/provider/src/main/kotlin/com/flixclusive/data/provider/ProviderManager.kt @@ -31,6 +31,7 @@ import com.flixclusive.provider.Provider import com.flixclusive.provider.settings.ProviderSettings import dagger.hilt.android.qualifiers.ApplicationContext import dalvik.system.PathClassLoader +import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch import okhttp3.OkHttpClient @@ -58,6 +59,7 @@ class ProviderManager @Inject constructor( private val classLoaders: MutableMap = Collections.synchronizedMap(HashMap()) private var notificationChannelHasBeenInitialized = false + val initialization = CompletableDeferred() /** * An observable map of provider data @@ -117,6 +119,8 @@ class ProviderManager @Inject constructor( notificationChannelHasBeenInitialized = true } + + initialization.complete(Unit) } } diff --git a/domain/updater/src/main/kotlin/com/flixclusive/domain/updater/ProviderUpdaterUseCase.kt b/domain/updater/src/main/kotlin/com/flixclusive/domain/updater/ProviderUpdaterUseCase.kt index 0b43f557f..b3de3a2af 100644 --- a/domain/updater/src/main/kotlin/com/flixclusive/domain/updater/ProviderUpdaterUseCase.kt +++ b/domain/updater/src/main/kotlin/com/flixclusive/domain/updater/ProviderUpdaterUseCase.kt @@ -43,6 +43,10 @@ class ProviderUpdaterUseCase @Inject constructor( private var notificationChannelHasBeenInitialized = false suspend fun checkForUpdates(notify: Boolean) { + // Wait for providers to be initialized + // To avoid ConcurrentModificationException + providerManager.initialization.await() + val appSettingsProvider = appSettingsManager.providerSettings.data.first() outdatedProviders.clear()