Improve mobile refresh loop and chat streaming UX
This commit is contained in:
1 parent
6c204d8a4e
commit
8daad78bf9
6 files changed
+68
-3
No files matched your search
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
+2
-2
@@ -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-") }
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in new issue
Block a user