fix: UTC+0/UTC+8 切换偏好持久化——OCGO 路径首次加载不读取持久化值导致偏好丢失
将 UTC 偏好同步读取逻辑从 setWorkspace() 下沉到 load() 开头, 确保 OCGO(load())和 CCGO(setWorkspace()→load())两条路径 首次加载时都从 DataStore 读取持久化的 useUtc8 偏好。 useUtc8Initialized 标志位保证只读取一次,后续 toggleUtc8() 不被覆盖。
This commit is contained in:
parent
b4c3402d22
commit
0b140fe73e
@ -44,18 +44,7 @@ class UsageChartViewModel @Inject constructor(
|
||||
loadGeneration++
|
||||
allowFallback = true
|
||||
_state.value = ChartUiState(useUtc8 = _state.value.useUtc8)
|
||||
viewModelScope.launch {
|
||||
// 首次加载时同步读取 UTC 偏好,避免用默认值 false 加载后再切换
|
||||
if (!_state.value.useUtc8Initialized) {
|
||||
val saved = chartSettingsStore.useUtc8Flow.first()
|
||||
if (saved != _state.value.useUtc8) {
|
||||
_state.update { it.copy(useUtc8 = saved, useUtc8Initialized = true) }
|
||||
} else {
|
||||
_state.update { it.copy(useUtc8Initialized = true) }
|
||||
}
|
||||
}
|
||||
load()
|
||||
}
|
||||
load()
|
||||
}
|
||||
|
||||
private suspend fun workspaceId(): String? {
|
||||
@ -101,6 +90,11 @@ class UsageChartViewModel @Inject constructor(
|
||||
|
||||
fun load() {
|
||||
viewModelScope.launch {
|
||||
// 首次加载时同步读取 UTC 偏好,避免用默认值 false 加载后再切换
|
||||
if (!_state.value.useUtc8Initialized) {
|
||||
val saved = chartSettingsStore.useUtc8Flow.first()
|
||||
_state.update { it.copy(useUtc8 = saved, useUtc8Initialized = true) }
|
||||
}
|
||||
val wid = workspaceId() ?: return@launch
|
||||
val genAtStart = loadGeneration
|
||||
val cache = cacheProvider.get()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user