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,19 +44,8 @@ class UsageChartViewModel @Inject constructor(
|
|||||||
loadGeneration++
|
loadGeneration++
|
||||||
allowFallback = true
|
allowFallback = true
|
||||||
_state.value = ChartUiState(useUtc8 = _state.value.useUtc8)
|
_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? {
|
private suspend fun workspaceId(): String? {
|
||||||
workspaceIdOverride?.let { return it }
|
workspaceIdOverride?.let { return it }
|
||||||
@ -101,6 +90,11 @@ class UsageChartViewModel @Inject constructor(
|
|||||||
|
|
||||||
fun load() {
|
fun load() {
|
||||||
viewModelScope.launch {
|
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 wid = workspaceId() ?: return@launch
|
||||||
val genAtStart = loadGeneration
|
val genAtStart = loadGeneration
|
||||||
val cache = cacheProvider.get()
|
val cache = cacheProvider.get()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user