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 切换失败"
|
||||
|
||||
Reference in new issue
Block a user