Android: add canvas hasContent state tracking

Tracks whether the canvas has navigated content to support
conditional UI rendering based on canvas state.

AI-assisted (Claude) - lightly tested
This commit is contained in:
yishai 2026-01-29 04:18:52 +02:00
parent 275b908d0e
commit 55631f83a1
3 changed files with 8 additions and 0 deletions

View File

@ -53,6 +53,7 @@ class MainViewModel(app: Application) : AndroidViewModel(app) {
val manualTls: StateFlow<Boolean> = runtime.manualTls
val manualToken: StateFlow<String> = runtime.manualToken
val canvasDebugStatusEnabled: StateFlow<Boolean> = runtime.canvasDebugStatusEnabled
val canvasHasContent: StateFlow<Boolean> = runtime.canvasHasContent
val chatSessionKey: StateFlow<String> = runtime.chatSessionKey
val chatSessionId: StateFlow<String?> = runtime.chatSessionId

View File

@ -330,6 +330,7 @@ class NodeRuntime(context: Context) {
val manualToken: StateFlow<String> = prefs.manualToken
val lastDiscoveredStableId: StateFlow<String> = prefs.lastDiscoveredStableId
val canvasDebugStatusEnabled: StateFlow<Boolean> = prefs.canvasDebugStatusEnabled
val canvasHasContent: StateFlow<Boolean> = canvas.hasContent
private var didAutoConnect = false
private var suppressWakeWordsSync = false

View File

@ -8,6 +8,9 @@ import android.webkit.WebView
import androidx.core.graphics.createBitmap
import androidx.core.graphics.scale
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext
import java.io.ByteArrayOutputStream
@ -21,6 +24,8 @@ import com.clawdbot.android.BuildConfig
import kotlin.coroutines.resume
class CanvasController {
private val _hasContent = MutableStateFlow(false)
val hasContent: StateFlow<Boolean> = _hasContent.asStateFlow()
enum class SnapshotFormat(val rawValue: String) {
Png("png"),
Jpeg("jpeg"),
@ -48,6 +53,7 @@ class CanvasController {
fun navigate(url: String) {
val trimmed = url.trim()
this.url = if (trimmed.isBlank() || trimmed == "/") null else trimmed
_hasContent.value = this.url != null
reload()
}