Differentiate manual sync feedback
This commit is contained in:
1 parent
1764e03263
commit
6bb2d939a6
3 files changed
+26
-25
No files matched your search
@@ -129,7 +129,7 @@ private fun OpenClawRoot(appState: OpenClawAppState) {
|
||||
|
||||
LaunchedEffect(appState.isConfigured) {
|
||||
if (appState.isConfigured) {
|
||||
appState.syncRemoteIfNeeded()
|
||||
appState.syncRemoteIfNeeded(trigger = cn.xiaobai.openclawapp.app.SyncTrigger.Initial)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,7 +315,7 @@ private fun OpenClawRoot(appState: OpenClawAppState) {
|
||||
onRetry = {
|
||||
coroutineScope.launch {
|
||||
appState.clearSyncError()
|
||||
appState.syncRemoteIfNeeded()
|
||||
appState.syncRemoteIfNeeded(trigger = cn.xiaobai.openclawapp.app.SyncTrigger.Manual)
|
||||
}
|
||||
},
|
||||
)
|
||||
@@ -336,7 +336,7 @@ private fun OpenClawRoot(appState: OpenClawAppState) {
|
||||
onRefreshOverview = {
|
||||
coroutineScope.launch {
|
||||
appState.clearSyncError()
|
||||
appState.syncRemoteIfNeeded()
|
||||
appState.syncRemoteIfNeeded(trigger = cn.xiaobai.openclawapp.app.SyncTrigger.Manual)
|
||||
}
|
||||
},
|
||||
onDisconnect = appState::disconnect,
|
||||
@@ -358,7 +358,7 @@ private fun OpenClawRoot(appState: OpenClawAppState) {
|
||||
onRefreshOverview = {
|
||||
coroutineScope.launch {
|
||||
appState.clearSyncError()
|
||||
appState.syncRemoteIfNeeded()
|
||||
appState.syncRemoteIfNeeded(trigger = cn.xiaobai.openclawapp.app.SyncTrigger.Manual)
|
||||
}
|
||||
},
|
||||
onDisconnect = appState::disconnect,
|
||||
|
||||
@@ -12,6 +12,12 @@ import cn.xiaobai.openclawapp.network.MobileGatewayApi
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
|
||||
enum class SyncTrigger {
|
||||
Initial,
|
||||
Manual,
|
||||
Background,
|
||||
}
|
||||
|
||||
class OpenClawAppState(
|
||||
private val preferences: AppPreferences = AppPreferences(),
|
||||
) {
|
||||
@@ -103,7 +109,7 @@ class OpenClawAppState(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun syncRemoteIfNeeded() {
|
||||
suspend fun syncRemoteIfNeeded(trigger: SyncTrigger = SyncTrigger.Initial) {
|
||||
val remote = repository as? RemoteOpenClawRepository ?: return
|
||||
isSyncing = true
|
||||
syncError = null
|
||||
@@ -121,13 +127,22 @@ class OpenClawAppState(
|
||||
preferences.saveOverviewSnapshot(remote.exportOverviewSnapshot())
|
||||
persistRecentMessageCache(remote)
|
||||
persistPendingSendQueue(remote)
|
||||
if (drainedText || drainedAttachments) {
|
||||
feedbackMessage = "已尝试继续处理本地待发队列"
|
||||
when {
|
||||
drainedText || drainedAttachments -> {
|
||||
feedbackMessage = "已尝试继续处理本地待发队列"
|
||||
}
|
||||
trigger == SyncTrigger.Manual -> {
|
||||
feedbackMessage = "已同步最新状态"
|
||||
}
|
||||
}
|
||||
isShowingCachedData = false
|
||||
}.onFailure {
|
||||
syncError = it.message ?: "远程同步失败"
|
||||
feedbackMessage = "Remote 同步失败"
|
||||
feedbackMessage = if (trigger == SyncTrigger.Background) {
|
||||
syncError
|
||||
} else {
|
||||
"同步失败"
|
||||
}
|
||||
}
|
||||
isSyncing = false
|
||||
}
|
||||
@@ -135,22 +150,7 @@ class OpenClawAppState(
|
||||
suspend fun refreshOverviewSilently() {
|
||||
val remote = repository as? RemoteOpenClawRepository ?: return
|
||||
if (isSyncing || sendingSessionId != null) return
|
||||
|
||||
runCatching {
|
||||
coroutineScope {
|
||||
val statusDeferred = async { remote.refreshStatus() }
|
||||
val agentsDeferred = async { remote.refreshAgents() }
|
||||
val sessionsDeferred = async { remote.refreshSessions() }
|
||||
statusDeferred.await()
|
||||
agentsDeferred.await()
|
||||
sessionsDeferred.await()
|
||||
}
|
||||
preferences.saveOverviewSnapshot(remote.exportOverviewSnapshot())
|
||||
persistPendingSendQueue(remote)
|
||||
isShowingCachedData = false
|
||||
}.onFailure {
|
||||
syncError = it.message ?: "远程同步失败"
|
||||
}
|
||||
syncRemoteIfNeeded(trigger = SyncTrigger.Background)
|
||||
}
|
||||
|
||||
suspend fun openSession(sessionId: String) {
|
||||
@@ -223,7 +223,7 @@ class OpenClawAppState(
|
||||
serverConfig = serverConfig.copy(defaultAgent = agent)
|
||||
preferences.saveServerConfig(serverConfig)
|
||||
repository.status = repository.status.copy(defaultAgent = agent)
|
||||
syncRemoteIfNeeded()
|
||||
syncRemoteIfNeeded(trigger = SyncTrigger.Manual)
|
||||
feedbackMessage = "默认 Agent 已切换到 $agent"
|
||||
}.onFailure {
|
||||
syncError = it.message ?: "默认 Agent 切换失败"
|
||||
|
||||
@@ -460,3 +460,4 @@ Android/iOS App
|
||||
- 2026-03-07:开始补主动自救能力:会话页新增常驻“刷新”入口,不再只有报错卡里才有重试;设置页新增“立即同步”入口,让用户能主动拉取状态 / agents / 会话列表,而不是只能等后台轮询或进详情页触发刷新。
|
||||
- 2026-03-07:会话页补上真正的下拉刷新:基于 Material3 `PullToRefreshBox` 接 `onRetry`,让列表页除了常驻“刷新”按钮外,也支持更符合移动端习惯的手势刷新。
|
||||
- 2026-03-07:聊天页也补上下拉刷新:沿用同一套 `PullToRefreshBox + onRetry` 机制,让会话详情除了顶栏刷新/重连外,也支持直接下拉拉取最新消息与状态。
|
||||
- 2026-03-07:同步反馈开始区分触发来源:把远端同步拆成 `Initial / Manual / Background` 三种触发语义,用户主动刷新成功时会明确提示“已同步最新状态”,后台静默刷新则尽量不打扰,避免轮询也频繁弹反馈,同时让手动操作的结果更可感知。
|
||||
Reference in new issue
Block a user