From d0ad601efc9f75cbd43a36cca5a9f04424b73794 Mon Sep 17 00:00:00 2001 From: KremeCN <3265494849@qq.com> Date: Mon, 24 Aug 2026 02:31:59 +0800 Subject: [PATCH] fix: bound provider storage retries --- .../flagship/abox/manager/ui/login/LoginViewModel.kt | 6 +++++- .../session/profile/ProviderProfileStoreImpl.kt | 12 ++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/android/app/src/main/kotlin/com/flagship/abox/manager/ui/login/LoginViewModel.kt b/android/app/src/main/kotlin/com/flagship/abox/manager/ui/login/LoginViewModel.kt index 5d96021..e51b7bc 100644 --- a/android/app/src/main/kotlin/com/flagship/abox/manager/ui/login/LoginViewModel.kt +++ b/android/app/src/main/kotlin/com/flagship/abox/manager/ui/login/LoginViewModel.kt @@ -32,9 +32,11 @@ class LoginViewModel @Inject constructor( private var usernameEdited = false private var rememberUsernameEdited = false private var autoLoginEdited = false + private var loadedProfileId: com.flagship.abox.manager.domain.ProviderProfileId? = null fun loadProfile(value: ProviderProfile) { - if (profile?.id == value.id && + if (loadedProfileId == value.id || + profile?.id == value.id && (loadingJob?.isActive == true || submitJob?.isActive == true) ) return loadingJob?.cancel() @@ -65,6 +67,7 @@ class LoginViewModel @Inject constructor( }, isLoadingPreferences = false, ) + loadedProfileId = value.id } catch (error: CancellationException) { throw error } catch (_: Exception) { @@ -92,6 +95,7 @@ class LoginViewModel @Inject constructor( return } profile = null + loadedProfileId = null usernameEdited = false rememberUsernameEdited = false autoLoginEdited = false diff --git a/android/core/session/src/main/kotlin/com/flagship/abox/manager/session/profile/ProviderProfileStoreImpl.kt b/android/core/session/src/main/kotlin/com/flagship/abox/manager/session/profile/ProviderProfileStoreImpl.kt index f3333b9..248861a 100644 --- a/android/core/session/src/main/kotlin/com/flagship/abox/manager/session/profile/ProviderProfileStoreImpl.kt +++ b/android/core/session/src/main/kotlin/com/flagship/abox/manager/session/profile/ProviderProfileStoreImpl.kt @@ -28,12 +28,9 @@ class ProviderProfileStoreImpl( private val safeData: Flow get() = dataStore.data .retryWhen { cause, attempt -> - if (cause !is IOException) return@retryWhen false - val delayMillis = (READ_RETRY_DELAY_MILLIS shl - attempt.coerceAtMost(MAX_BACKOFF_SHIFT).toInt()) - .coerceAtMost(MAX_READ_RETRY_DELAY_MILLIS) - delay(delayMillis) - true + val retry = cause is IOException && attempt < MAX_READ_RETRIES + if (retry) delay(READ_RETRY_DELAY_MILLIS) + retry } .distinctUntilChanged() @@ -118,9 +115,8 @@ class ProviderProfileStoreImpl( } companion object { + private const val MAX_READ_RETRIES = 2L private const val READ_RETRY_DELAY_MILLIS = 100L - private const val MAX_READ_RETRY_DELAY_MILLIS = 5_000L - private const val MAX_BACKOFF_SHIFT = 6L private val PROFILE_IDS = stringSetPreferencesKey("profile_ids") private val ACTIVE_PROFILE_ID = stringPreferencesKey("active_profile_id")