block application launch setup until beta upgrades have completed
This commit is contained in:
parent
223b5d27ef
commit
5b7fe5aa4e
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
}
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue