block application launch setup until beta upgrades have completed

This commit is contained in:
Adam Brown 2022-10-30 19:34:34 +00:00
parent 223b5d27ef
commit 5b7fe5aa4e
5 changed files with 44 additions and 19 deletions

View File

@ -60,13 +60,12 @@ class SmallTalkApplication : Application(), ModuleProvider {
private fun onApplicationLaunch(notificationsModule: NotificationsModule, storeModule: StoreModule) {
applicationScope.launch {
featureModules.homeModule.betaVersionUpgradeUseCase.waitUnitReady()
storeModule.credentialsStore().credentials()?.let {
featureModules.pushModule.pushTokenRegistrar().registerCurrentToken()
}
runCatching { storeModule.localEchoStore.preload() }
}
applicationScope.launch {
val notificationsUseCase = notificationsModule.notificationsUseCase()
notificationsUseCase.listenForNotificationChanges(this)
}

View File

@ -20,6 +20,7 @@ import app.dapk.st.directory.DirectoryModule
import app.dapk.st.domain.StoreModule
import app.dapk.st.engine.MatrixEngine
import app.dapk.st.firebase.messaging.MessagingModule
import app.dapk.st.home.BetaVersionUpgradeUseCase
import app.dapk.st.home.HomeModule
import app.dapk.st.home.MainActivity
import app.dapk.st.imageloader.ImageLoaderModule
@ -164,7 +165,16 @@ internal class FeatureModules internal constructor(
deviceMeta,
)
}
val homeModule by unsafeLazy { HomeModule(chatEngineModule.engine, storeModule.value, buildMeta) }
val homeModule by unsafeLazy {
HomeModule(
chatEngineModule.engine,
storeModule.value,
BetaVersionUpgradeUseCase(
storeModule.value.applicationStore(),
buildMeta,
),
)
}
val settingsModule by unsafeLazy {
SettingsModule(
chatEngineModule.engine,

View File

@ -3,24 +3,44 @@ package app.dapk.st.home
import app.dapk.st.core.BuildMeta
import app.dapk.st.domain.ApplicationPreferences
import app.dapk.st.domain.ApplicationVersion
import kotlinx.coroutines.CancellableContinuation
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlin.coroutines.resume
class BetaVersionUpgradeUseCase(
private val applicationPreferences: ApplicationPreferences,
private val buildMeta: BuildMeta,
) {
private var _continuation: CancellableContinuation<Unit>? = null
fun hasVersionChanged(): Boolean {
return runBlocking {
return runBlocking { hasChangedVersion() }
}
private suspend fun hasChangedVersion(): Boolean {
val previousVersion = applicationPreferences.readVersion()?.value
val currentVersion = buildMeta.versionCode
when (previousVersion) {
return when (previousVersion) {
null -> false
else -> currentVersion > previousVersion
}.also {
applicationPreferences.setVersion(ApplicationVersion(currentVersion))
}
}
suspend fun waitUnitReady() {
if (hasChangedVersion()) {
suspendCancellableCoroutine { continuation ->
_continuation = continuation
}
}
}
fun notifyUpgraded() {
_continuation?.resume(Unit)
_continuation = null
}
}

View File

@ -1,6 +1,5 @@
package app.dapk.st.home
import app.dapk.st.core.BuildMeta
import app.dapk.st.core.ProvidableModule
import app.dapk.st.directory.DirectoryViewModel
import app.dapk.st.domain.StoreModule
@ -11,7 +10,7 @@ import app.dapk.st.profile.ProfileViewModel
class HomeModule(
private val chatEngine: ChatEngine,
private val storeModule: StoreModule,
private val buildMeta: BuildMeta,
val betaVersionUpgradeUseCase: BetaVersionUpgradeUseCase,
) : ProvidableModule {
fun homeViewModel(directory: DirectoryViewModel, login: LoginViewModel, profileViewModel: ProfileViewModel): HomeViewModel {
@ -22,10 +21,7 @@ class HomeModule(
login,
profileViewModel,
storeModule.cacheCleaner(),
BetaVersionUpgradeUseCase(
storeModule.applicationStore(),
buildMeta,
),
betaVersionUpgradeUseCase,
)
}

View File

@ -12,7 +12,6 @@ import app.dapk.st.profile.ProfileViewModel
import app.dapk.st.viewmodel.DapkViewModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
@ -87,6 +86,7 @@ class HomeViewModel(
fun clearCache() {
viewModelScope.launch {
cacheCleaner.cleanCache(removeCredentials = false)
betaVersionUpgradeUseCase.notifyUpgraded()
_events.emit(HomeEvent.Relaunch)
}
}