feat: add provider login flow #4
@@ -32,9 +32,11 @@ class LoginViewModel @Inject constructor(
|
|||||||
private var usernameEdited = false
|
private var usernameEdited = false
|
||||||
private var rememberUsernameEdited = false
|
private var rememberUsernameEdited = false
|
||||||
private var autoLoginEdited = false
|
private var autoLoginEdited = false
|
||||||
|
private var loadedProfileId: com.flagship.abox.manager.domain.ProviderProfileId? = null
|
||||||
|
|
||||||
fun loadProfile(value: ProviderProfile) {
|
fun loadProfile(value: ProviderProfile) {
|
||||||
|
|
|||||||
if (profile?.id == value.id &&
|
if (loadedProfileId == value.id ||
|
||||||
|
profile?.id == value.id &&
|
||||||
(loadingJob?.isActive == true || submitJob?.isActive == true)
|
(loadingJob?.isActive == true || submitJob?.isActive == true)
|
||||||
) return
|
) return
|
||||||
loadingJob?.cancel()
|
loadingJob?.cancel()
|
||||||
@@ -65,6 +67,7 @@ class LoginViewModel @Inject constructor(
|
|||||||
},
|
},
|
||||||
isLoadingPreferences = false,
|
isLoadingPreferences = false,
|
||||||
)
|
)
|
||||||
|
loadedProfileId = value.id
|
||||||
} catch (error: CancellationException) {
|
} catch (error: CancellationException) {
|
||||||
throw error
|
throw error
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
@@ -92,6 +95,7 @@ class LoginViewModel @Inject constructor(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
profile = null
|
profile = null
|
||||||
|
loadedProfileId = null
|
||||||
usernameEdited = false
|
usernameEdited = false
|
||||||
rememberUsernameEdited = false
|
rememberUsernameEdited = false
|
||||||
autoLoginEdited = false
|
autoLoginEdited = false
|
||||||
|
|||||||
+4
-8
@@ -28,12 +28,9 @@ class ProviderProfileStoreImpl(
|
|||||||
private val safeData: Flow<Preferences>
|
private val safeData: Flow<Preferences>
|
||||||
|
pr-agent-bot
commented
无限重试
**无限重试**
`safeData` 遇到任何 `IOException` 都会无限重试,没有最大次数或最终错误路径。如果 DataStore 因磁盘或文件系统故障而持续不可读,`activeProfile()` 和 `loginPreferences()` 将永远挂起,导致应用一直停留在加载页或登录表单持续禁用,上层异常处理也无法展示错误。应限制重试次数,并在耗尽后抛出错误或执行明确的降级处理。
<!-- pr-agent-dedup: 4389fff2f610 -->
<!-- pr-agent-key-issue-location: b2da98684d7a -->
pr-agent-bot
commented
启动失败
**启动失败**
`safeData` 在两次重试后仍会向调用方传播 `IOException`,而启动流程中的 `activeProfile()` 和 `observeActiveProfile()` 均未处理该异常。持续性存储读取故障会触发未处理异常;即使异常被全局处理,`bootstrapResult` 也可能一直为空,使应用永久停留在加载页。应在重试耗尽后将错误转换为可恢复状态或显式领域错误。
<!-- pr-agent-dedup: 7302d3a589b8 -->
<!-- pr-agent-key-issue-location: db2a740c074a -->
pr-agent-bot
commented
启动卡死 当 DataStore 连续读取失败并耗尽重试后, **启动卡死**
当 DataStore 连续读取失败并耗尽重试后,`safeData` 会继续抛出 `IOException`。`observeActiveProfile()` 是 `combine(...).stateIn(...)` 的上游之一,该异常会终止共享协程,导致启动界面永久停留在加载状态或后续一直保留陈旧状态。应在共享前捕获并映射为可恢复错误,或采用不会终止状态流的重试策略。
<!-- pr-agent-dedup: 31fd4d3bef7b -->
<!-- pr-agent-key-issue-location: 2275a87bf139 -->
|
|||||||
get() = dataStore.data
|
get() = dataStore.data
|
||||||
.retryWhen { cause, attempt ->
|
.retryWhen { cause, attempt ->
|
||||||
if (cause !is IOException) return@retryWhen false
|
val retry = cause is IOException && attempt < MAX_READ_RETRIES
|
||||||
val delayMillis = (READ_RETRY_DELAY_MILLIS shl
|
if (retry) delay(READ_RETRY_DELAY_MILLIS)
|
||||||
attempt.coerceAtMost(MAX_BACKOFF_SHIFT).toInt())
|
retry
|
||||||
.coerceAtMost(MAX_READ_RETRY_DELAY_MILLIS)
|
|
||||||
delay(delayMillis)
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
|
|
||||||
@@ -118,9 +115,8 @@ class ProviderProfileStoreImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
private const val MAX_READ_RETRIES = 2L
|
||||||
private const val READ_RETRY_DELAY_MILLIS = 100L
|
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 PROFILE_IDS = stringSetPreferencesKey("profile_ids")
|
||||||
private val ACTIVE_PROFILE_ID = stringPreferencesKey("active_profile_id")
|
private val ACTIVE_PROFILE_ID = stringPreferencesKey("active_profile_id")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user
状态丢失
LoginRoute重新进入组合时会再次调用loadProfile。当同一提供方已加载完成且当前没有任务时,此实现仍会重置编辑标记并用新的LoginUiState覆盖现有状态。因此 Activity 因旋转等配置变更重建时,虽然 ViewModel 得以保留,用户已输入的用户名和密码仍会被清空。应对已加载的相同配置直接返回,或在刷新时保留当前编辑值。