From 8daad78bf97f35d590fe1aeca2672cda31c97f0e Mon Sep 17 00:00:00 2001 From: OpenClaw Date: Sat, 7 Mar 2026 04:29:05 +0800 Subject: [PATCH] Improve mobile refresh loop and chat streaming UX --- .gitignore | 1 + .../kotlin/cn/xiaobai/openclawapp/App.kt | 9 ++++++++ .../openclawapp/app/OpenClawAppState.kt | 13 +++++++++++ .../data/RemoteOpenClawRepository.kt | 4 ++-- .../openclawapp/feature/chat/ChatScreen.kt | 22 ++++++++++++++++++- settings.gradle.kts | 22 +++++++++++++++++++ 6 files changed, 68 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index adfa9bf..bb1166f 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ captures !*.xcworkspace/contents.xcworkspacedata **/xcshareddata/WorkspaceSettings.xcsettings node_modules/ +/bff/ diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/App.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/App.kt index 2afee03..e0aaabe 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/App.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/App.kt @@ -29,6 +29,7 @@ import cn.xiaobai.openclawapp.feature.status.StatusScreen import cn.xiaobai.openclawapp.ui.OpenClawTheme import cn.xiaobai.openclawapp.ui.StatusPill import kotlinx.coroutines.delay +import kotlinx.coroutines.isActive import kotlinx.coroutines.launch @Composable @@ -93,6 +94,14 @@ private fun OpenClawRoot(appState: OpenClawAppState) { } } + LaunchedEffect(appState.isConfigured) { + if (!appState.isConfigured) return@LaunchedEffect + while (isActive) { + delay(30_000) + appState.refreshOverviewSilently() + } + } + Scaffold( topBar = { CenterAlignedTopAppBar( diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/app/OpenClawAppState.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/app/OpenClawAppState.kt index fa0dddf..b8dc0de 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/app/OpenClawAppState.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/app/OpenClawAppState.kt @@ -81,6 +81,19 @@ class OpenClawAppState( isSyncing = false } + suspend fun refreshOverviewSilently() { + val remote = repository as? RemoteOpenClawRepository ?: return + if (isSyncing || sendingSessionId != null) return + + runCatching { + remote.refreshStatus() + remote.refreshAgents() + remote.refreshSessions() + }.onFailure { + syncError = it.message ?: "远程同步失败" + } + } + suspend fun openSession(sessionId: String) { repository.markSessionOpened(sessionId) activeSessionId = sessionId diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt index c11cd6b..718f552 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt @@ -16,7 +16,7 @@ import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.cancel import kotlinx.coroutines.currentCoroutineContext import kotlinx.coroutines.delay -import kotlinx.coroutines.flow.collectLatest +import kotlinx.coroutines.flow.collect import kotlinx.coroutines.isActive import kotlinx.coroutines.launch @@ -155,7 +155,7 @@ class RemoteOpenClawRepository( streamJob = streamScope.launch { while (currentCoroutineContext().isActive) { try { - sseStream.connect(sessionId).collectLatest { event -> + sseStream.connect(sessionId).collect { event -> when (event) { is SessionStreamEvent.Snapshot -> { val localPending = messageStore[sessionId].orEmpty().filter { it.id.startsWith("local-") } diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/feature/chat/ChatScreen.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/feature/chat/ChatScreen.kt index 193d68b..a50b323 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/feature/chat/ChatScreen.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/feature/chat/ChatScreen.kt @@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.RowScope import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.rememberLazyListState @@ -222,6 +223,7 @@ private fun MessageBubble( MessageRole.Assistant -> "OpenClaw" MessageRole.System -> "系统" } + val isThinking = message.status == "thinking" var visibleChars by remember(message.id) { mutableIntStateOf(if (animateText) 0 else message.text.length) } LaunchedEffect(message.id, animateText) { @@ -260,7 +262,25 @@ private fun MessageBubble( .padding(14.dp), verticalArrangement = Arrangement.spacedBy(8.dp), ) { - Text(text = displayText, style = MaterialTheme.typography.bodyLarge) + if (isThinking) { + Row( + horizontalArrangement = Arrangement.spacedBy(10.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + CircularProgressIndicator( + modifier = Modifier.size(18.dp), + strokeWidth = 2.dp, + color = MaterialTheme.colorScheme.onSecondaryContainer, + ) + Text( + text = "正在思考…", + style = MaterialTheme.typography.bodyMedium, + color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + } + } else { + Text(text = displayText, style = MaterialTheme.typography.bodyLarge) + } Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp), diff --git a/settings.gradle.kts b/settings.gradle.kts index 4194f98..b31a60f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -3,6 +3,14 @@ enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") pluginManagement { repositories { + maven("https://maven.aliyun.com/repository/google") { + name = "AliyunGoogle" + mavenContent { + includeGroupAndSubgroups("androidx") + includeGroupAndSubgroups("com.android") + includeGroupAndSubgroups("com.google") + } + } google { mavenContent { includeGroupAndSubgroups("androidx") @@ -10,6 +18,9 @@ pluginManagement { includeGroupAndSubgroups("com.google") } } + maven("https://maven.aliyun.com/repository/public") { + name = "AliyunPublic" + } mavenCentral() gradlePluginPortal() } @@ -20,6 +31,14 @@ plugins { dependencyResolutionManagement { repositories { + maven("https://maven.aliyun.com/repository/google") { + name = "AliyunGoogle" + mavenContent { + includeGroupAndSubgroups("androidx") + includeGroupAndSubgroups("com.android") + includeGroupAndSubgroups("com.google") + } + } google { mavenContent { includeGroupAndSubgroups("androidx") @@ -27,6 +46,9 @@ dependencyResolutionManagement { includeGroupAndSubgroups("com.google") } } + maven("https://maven.aliyun.com/repository/public") { + name = "AliyunPublic" + } mavenCentral() } }