Improve mobile refresh loop and chat streaming UX

This commit is contained in:
OpenClaw committed 2026-03-07 04:29:05 +08:00
1 parent 6c204d8a4e
commit 8daad78bf9
6 files changed
+68 -3

No files matched your search

+1
View File
@@ -17,3 +17,4 @@ captures
!*.xcworkspace/contents.xcworkspacedata !*.xcworkspace/contents.xcworkspacedata
**/xcshareddata/WorkspaceSettings.xcsettings **/xcshareddata/WorkspaceSettings.xcsettings
node_modules/ node_modules/
/bff/
@@ -29,6 +29,7 @@ import cn.xiaobai.openclawapp.feature.status.StatusScreen
import cn.xiaobai.openclawapp.ui.OpenClawTheme import cn.xiaobai.openclawapp.ui.OpenClawTheme
import cn.xiaobai.openclawapp.ui.StatusPill import cn.xiaobai.openclawapp.ui.StatusPill
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@Composable @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( Scaffold(
topBar = { topBar = {
CenterAlignedTopAppBar( CenterAlignedTopAppBar(
@@ -81,6 +81,19 @@ class OpenClawAppState(
isSyncing = false 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) { suspend fun openSession(sessionId: String) {
repository.markSessionOpened(sessionId) repository.markSessionOpened(sessionId)
activeSessionId = sessionId activeSessionId = sessionId
@@ -16,7 +16,7 @@ import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel import kotlinx.coroutines.cancel
import kotlinx.coroutines.currentCoroutineContext import kotlinx.coroutines.currentCoroutineContext
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.isActive import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@@ -155,7 +155,7 @@ class RemoteOpenClawRepository(
streamJob = streamScope.launch { streamJob = streamScope.launch {
while (currentCoroutineContext().isActive) { while (currentCoroutineContext().isActive) {
try { try {
sseStream.connect(sessionId).collectLatest { event -> sseStream.connect(sessionId).collect { event ->
when (event) { when (event) {
is SessionStreamEvent.Snapshot -> { is SessionStreamEvent.Snapshot -> {
val localPending = messageStore[sessionId].orEmpty().filter { it.id.startsWith("local-") } val localPending = messageStore[sessionId].orEmpty().filter { it.id.startsWith("local-") }
@@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.lazy.rememberLazyListState
@@ -222,6 +223,7 @@ private fun MessageBubble(
MessageRole.Assistant -> "OpenClaw" MessageRole.Assistant -> "OpenClaw"
MessageRole.System -> "系统" MessageRole.System -> "系统"
} }
val isThinking = message.status == "thinking"
var visibleChars by remember(message.id) { mutableIntStateOf(if (animateText) 0 else message.text.length) } var visibleChars by remember(message.id) { mutableIntStateOf(if (animateText) 0 else message.text.length) }
LaunchedEffect(message.id, animateText) { LaunchedEffect(message.id, animateText) {
@@ -260,7 +262,25 @@ private fun MessageBubble(
.padding(14.dp), .padding(14.dp),
verticalArrangement = Arrangement.spacedBy(8.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( Row(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp),
+22
View File
@@ -3,6 +3,14 @@ enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
pluginManagement { pluginManagement {
repositories { repositories {
maven("https://maven.aliyun.com/repository/google") {
name = "AliyunGoogle"
mavenContent {
includeGroupAndSubgroups("androidx")
includeGroupAndSubgroups("com.android")
includeGroupAndSubgroups("com.google")
}
}
google { google {
mavenContent { mavenContent {
includeGroupAndSubgroups("androidx") includeGroupAndSubgroups("androidx")
@@ -10,6 +18,9 @@ pluginManagement {
includeGroupAndSubgroups("com.google") includeGroupAndSubgroups("com.google")
} }
} }
maven("https://maven.aliyun.com/repository/public") {
name = "AliyunPublic"
}
mavenCentral() mavenCentral()
gradlePluginPortal() gradlePluginPortal()
} }
@@ -20,6 +31,14 @@ plugins {
dependencyResolutionManagement { dependencyResolutionManagement {
repositories { repositories {
maven("https://maven.aliyun.com/repository/google") {
name = "AliyunGoogle"
mavenContent {
includeGroupAndSubgroups("androidx")
includeGroupAndSubgroups("com.android")
includeGroupAndSubgroups("com.google")
}
}
google { google {
mavenContent { mavenContent {
includeGroupAndSubgroups("androidx") includeGroupAndSubgroups("androidx")
@@ -27,6 +46,9 @@ dependencyResolutionManagement {
includeGroupAndSubgroups("com.google") includeGroupAndSubgroups("com.google")
} }
} }
maven("https://maven.aliyun.com/repository/public") {
name = "AliyunPublic"
}
mavenCentral() mavenCentral()
} }
} }