Skip to content

Commit 2a8b322

Browse files
authored
feat: view your machine's screen from the iOS and Android apps (#123097)
* feat(ui): add mobile desktop document mode Add a shell-free mobile desktop route that reuses the dock panel controller and lazy noVNC client, with source preselection, touch controls, keyboard input, and retryable inventory failures. * feat(ios): add desktop viewer entry points * feat(android): add desktop viewer * fix(android): keep System Back inside the desktop viewer The per-session viewer replaces SessionDashboardScreen in place instead of pushing a shell tab, so System Back fell through to the shell-level handler and popped the whole Dashboard tab, stranding the operator on Chat. Claim Back while the viewer is showing. Also carry over TerminalSettingsScreen's imePadding: the viewer's own touch toolbar hosts the keyboard affordance, so the soft keyboard would cover it. Proof (emulator, Medium_Phone_API_36.0, stub control UI on 18789): pre-fix Back from the viewer lands on Chat; post-fix it returns to Dashboard. No Robolectric regression test — no existing screen test constructs MainViewModel, and BackHandler under Robolectric would need new scaffolding for weaker evidence than the live repro. * test(ui): stop the pairing views leaking dialogs into the shared document `ui/vitest.config.ts` runs the unit project with `isolate: false`, so test files share one jsdom document inside a worker. `view.pairing.test.ts` appends a container to `document.body` for every case and never tears down, unlike its sibling `channels-page.test.ts`, so whichever suite the worker scheduled next inherited a mounted pairing dialog. That surfaced on this PR's first CI run as ten failures in the untouched `input-dialog.test.ts`, which found "Approve DM access" where it expected "Rename session". A rerun went green, so the ordering is scheduler-dependent rather than deterministic; this removes the contamination source rather than leaving the next suite to lose the race. Not a proven fix for that specific run — the leak reproduces only under CI's file scheduling, and the full suite passes locally either way — but the missing teardown is a real violation of the shared-environment contract. * test(ui): stop the background-tasks rail asserting on a ticking clock The rail e2e captured the main transcript's text before opening a task detail and required it to be byte-identical afterwards. A running task renders a live elapsed label, so the assertion failed whenever a second ticked over between the two reads — twice while landing this PR, both times "12s" against "13s" with no other difference. Normalize elapsed labels on both sides instead of weakening the assertion. The invariant it protects, that opening a detail leaves the main transcript alone, still holds: a real content change is still caught, and only complete duration tokens collapse, so diffstat figures like +14/-3 and phrases like "5 messages" are untouched.
1 parent d5d069a commit 2a8b322

35 files changed

Lines changed: 2404 additions & 872 deletions

‎apps/.i18n/native-source.json‎

Lines changed: 734 additions & 622 deletions
Large diffs are not rendered by default.

‎apps/android/app/src/main/java/ai/openclaw/app/AndroidScreenshotFixture.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ internal object AndroidScreenshotFixture {
1818
}
1919

2020
const val gatewayId = "android-screenshot-gateway"
21+
const val controlUiBaseUrl = "http://127.0.0.1:18789"
2122
const val mainSessionKey = "agent:main:node-screenshot"
2223
const val primarySessionTitle = "Android release planning"
2324
const val cronJobId = "android-release-digest"

‎apps/android/app/src/main/java/ai/openclaw/app/AndroidScreenshotMode.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ enum class AndroidScreenshotScene(
1717
Settings("settings", HomeDestination.Settings),
1818
Gateway("gateway", HomeDestination.Settings, SettingsRoute.Gateway),
1919
OpenClaw("openclaw", HomeDestination.Settings, SettingsRoute.SystemAgent),
20+
Desktop("desktop", HomeDestination.Settings, SettingsRoute.Desktop),
2021
VoiceWake("voice-wake", HomeDestination.Settings, SettingsRoute.Voice),
2122
;
2223

‎apps/android/app/src/main/java/ai/openclaw/app/MainViewModel.kt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,8 @@ class MainViewModel private constructor(
517517
val isConnected: StateFlow<Boolean> = runtimeState(initial = false) { it.isConnected }
518518
val gatewayControlPage: StateFlow<NodeRuntime.GatewayControlPage?> =
519519
runtimeState(initial = null) { it.gatewayControlPage }
520+
val desktopObserveAvailable: StateFlow<Boolean> =
521+
runtimeState(initial = false) { it.desktopObserveAvailable }
520522
val isNodeConnected: StateFlow<Boolean> = runtimeState(initial = false) { it.nodeConnected }
521523
val nodeCapabilityApproval: StateFlow<GatewayNodeCapabilityApproval> =
522524
runtimeState(initial = GatewayNodeCapabilityApproval.Loading) { it.nodeCapabilityApproval }

‎apps/android/app/src/main/java/ai/openclaw/app/NodeRuntime.kt‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,8 @@ class NodeRuntime private constructor(
11191119
val isConnected: StateFlow<Boolean> = _isConnected.asStateFlow()
11201120
private val _gatewayControlPage = MutableStateFlow<GatewayControlPage?>(null)
11211121
val gatewayControlPage: StateFlow<GatewayControlPage?> = _gatewayControlPage.asStateFlow()
1122+
private val _desktopObserveAvailable = MutableStateFlow(false)
1123+
val desktopObserveAvailable: StateFlow<Boolean> = _desktopObserveAvailable.asStateFlow()
11221124
private val _nodeConnected = MutableStateFlow(false)
11231125
val nodeConnected: StateFlow<Boolean> = _nodeConnected.asStateFlow()
11241126
private val _nodeCapabilityApproval = MutableStateFlow<GatewayNodeCapabilityApproval>(GatewayNodeCapabilityApproval.Loading)
@@ -2914,6 +2916,14 @@ class NodeRuntime private constructor(
29142916
_serverName.value = "OpenClaw Gateway"
29152917
_remoteAddress.value = "Mac Studio on local network"
29162918
_gatewayVersion.value = BuildConfig.VERSION_NAME
2919+
replaceGatewayMethods(setOf(GatewayMethod.DesktopObserve.rawValue))
2920+
_gatewayControlPage.value =
2921+
GatewayControlPage(
2922+
baseUrl = AndroidScreenshotFixture.controlUiBaseUrl,
2923+
token = null,
2924+
password = null,
2925+
tlsFingerprintSha256 = null,
2926+
)
29172927
updateGatewayDefaultAgentId("main")
29182928
_gatewayAgents.value = AndroidScreenshotFixture.agents
29192929
_modelCatalog.value = AndroidScreenshotFixture.models
@@ -7523,6 +7533,7 @@ class NodeRuntime private constructor(
75237533
synchronized(gatewayMethodsLock) {
75247534
gatewayApprovalRpcFamily = selectGatewayApprovalRpcFamily(methods)
75257535
_clawHubSkillMethodsAvailable.value = supportsClawHubSkillManagement(methods)
7536+
_desktopObserveAvailable.value = GatewayMethod.DesktopObserve.rawValue in methods
75267537
systemAgentChatSupported.value = GatewayMethod.OpenclawChat.rawValue in methods
75277538
gatewayMethodsEpoch += 1
75287539
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package ai.openclaw.app.ui
2+
3+
import ai.openclaw.app.MainViewModel
4+
import ai.openclaw.app.i18n.nativeString
5+
import ai.openclaw.app.ui.design.ClawPlainIconButton
6+
import ai.openclaw.app.ui.design.ClawScaffold
7+
import ai.openclaw.app.ui.design.ClawTheme
8+
import androidx.compose.foundation.layout.Arrangement
9+
import androidx.compose.foundation.layout.Box
10+
import androidx.compose.foundation.layout.Column
11+
import androidx.compose.foundation.layout.PaddingValues
12+
import androidx.compose.foundation.layout.Row
13+
import androidx.compose.foundation.layout.fillMaxSize
14+
import androidx.compose.foundation.layout.fillMaxWidth
15+
import androidx.compose.foundation.layout.imePadding
16+
import androidx.compose.foundation.layout.padding
17+
import androidx.compose.material.icons.Icons
18+
import androidx.compose.material.icons.automirrored.filled.ArrowBack
19+
import androidx.compose.material.icons.outlined.DesktopWindows
20+
import androidx.compose.material3.Icon
21+
import androidx.compose.material3.Text
22+
import androidx.compose.runtime.Composable
23+
import androidx.compose.runtime.collectAsState
24+
import androidx.compose.runtime.getValue
25+
import androidx.compose.runtime.key
26+
import androidx.compose.ui.Alignment
27+
import androidx.compose.ui.Modifier
28+
import androidx.compose.ui.text.style.TextOverflow
29+
import androidx.compose.ui.unit.dp
30+
import androidx.core.net.toUri
31+
32+
/** Full-height viewer for a gateway-observable desktop source. */
33+
@Composable
34+
internal fun DesktopScreen(
35+
viewModel: MainViewModel,
36+
source: String? = null,
37+
onBack: () -> Unit,
38+
) {
39+
val isConnected by viewModel.isConnected.collectAsState()
40+
val controlPage by viewModel.gatewayControlPage.collectAsState()
41+
ClawScaffold(
42+
contentPadding = PaddingValues(start = ClawTheme.spacing.lg, top = 14.dp, end = ClawTheme.spacing.lg, bottom = 6.dp),
43+
) {
44+
// The viewer's keyboard affordance opens the soft keyboard over the canvas; without
45+
// imePadding it would also cover the viewer's own touch toolbar.
46+
Column(modifier = Modifier.fillMaxSize().imePadding(), verticalArrangement = Arrangement.spacedBy(10.dp)) {
47+
Row(
48+
modifier = Modifier.fillMaxWidth(),
49+
verticalAlignment = Alignment.CenterVertically,
50+
horizontalArrangement = Arrangement.spacedBy(9.dp),
51+
) {
52+
ClawPlainIconButton(
53+
icon = Icons.AutoMirrored.Filled.ArrowBack,
54+
contentDescription = nativeString("Back"),
55+
onClick = onBack,
56+
)
57+
Text(
58+
text = nativeString("Desktop"),
59+
style = ClawTheme.type.title,
60+
color = ClawTheme.colors.text,
61+
modifier = Modifier.weight(1f),
62+
maxLines = 1,
63+
overflow = TextOverflow.Ellipsis,
64+
)
65+
Icon(
66+
imageVector = Icons.Outlined.DesktopWindows,
67+
contentDescription = null,
68+
tint = ClawTheme.colors.textMuted,
69+
)
70+
}
71+
Box(modifier = Modifier.fillMaxWidth().weight(1f)) {
72+
val page = controlPage
73+
if (isConnected && page != null) {
74+
// GatewayControlPage equality includes credentials and the accepted TLS pin.
75+
key(page, source) {
76+
ControlUiWebView(
77+
page = page,
78+
url = desktopUrl(baseUrl = page.baseUrl, source = source),
79+
modifier = Modifier.fillMaxSize(),
80+
)
81+
}
82+
} else {
83+
Column(
84+
modifier = Modifier.fillMaxWidth().padding(top = 48.dp),
85+
horizontalAlignment = Alignment.CenterHorizontally,
86+
verticalArrangement = Arrangement.spacedBy(6.dp),
87+
) {
88+
Text(
89+
text = nativeString("Desktop needs a connected gateway"),
90+
style = ClawTheme.type.section,
91+
color = ClawTheme.colors.text,
92+
)
93+
Text(
94+
text = nativeString("Connect to your gateway to view a machine screen."),
95+
style = ClawTheme.type.body,
96+
color = ClawTheme.colors.textMuted,
97+
)
98+
}
99+
}
100+
}
101+
}
102+
}
103+
}
104+
105+
/** Builds the desktop document route; credentials stay in ControlUiWebView's startup script. */
106+
internal fun desktopUrl(
107+
baseUrl: String,
108+
source: String? = null,
109+
): String {
110+
val baseUri = baseUrl.trimEnd('/').toUri()
111+
val routePath = "${baseUri.encodedPath.orEmpty().trimEnd('/')}/"
112+
val builder =
113+
baseUri
114+
.buildUpon()
115+
.encodedPath(routePath)
116+
.clearQuery()
117+
.fragment(null)
118+
.appendQueryParameter("view", "desktop")
119+
source?.let { builder.appendQueryParameter("source", it) }
120+
return builder.build().toString()
121+
}

‎apps/android/app/src/main/java/ai/openclaw/app/ui/SessionDashboardScreen.kt‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import ai.openclaw.app.i18n.nativeString
55
import ai.openclaw.app.ui.design.ClawPlainIconButton
66
import ai.openclaw.app.ui.design.ClawScaffold
77
import ai.openclaw.app.ui.design.ClawTheme
8+
import androidx.activity.compose.BackHandler
89
import androidx.compose.foundation.layout.Arrangement
910
import androidx.compose.foundation.layout.Box
1011
import androidx.compose.foundation.layout.Column
@@ -16,12 +17,16 @@ import androidx.compose.foundation.layout.padding
1617
import androidx.compose.material.icons.Icons
1718
import androidx.compose.material.icons.automirrored.filled.ArrowBack
1819
import androidx.compose.material.icons.outlined.Dashboard
20+
import androidx.compose.material.icons.outlined.DesktopWindows
1921
import androidx.compose.material3.Icon
2022
import androidx.compose.material3.Text
2123
import androidx.compose.runtime.Composable
2224
import androidx.compose.runtime.collectAsState
2325
import androidx.compose.runtime.getValue
2426
import androidx.compose.runtime.key
27+
import androidx.compose.runtime.mutableStateOf
28+
import androidx.compose.runtime.saveable.rememberSaveable
29+
import androidx.compose.runtime.setValue
2530
import androidx.compose.ui.Alignment
2631
import androidx.compose.ui.Modifier
2732
import androidx.compose.ui.text.style.TextOverflow
@@ -37,6 +42,17 @@ internal fun SessionDashboardScreen(
3742
) {
3843
val isConnected by viewModel.isConnected.collectAsState()
3944
val controlPage by viewModel.gatewayControlPage.collectAsState()
45+
val desktopObserveAvailable by viewModel.desktopObserveAvailable.collectAsState()
46+
var showingDesktop by rememberSaveable(sessionKey) { mutableStateOf(false) }
47+
if (showingDesktop) {
48+
// The viewer replaces this screen in place rather than pushing a shell tab, so it must
49+
// claim System Back itself; the shell handler would otherwise pop the whole dashboard.
50+
BackHandler { showingDesktop = false }
51+
// Session summaries do not advertise an environment id, so the viewer opens
52+
// its source picker instead of guessing a gateway or node association.
53+
DesktopScreen(viewModel = viewModel, source = null, onBack = { showingDesktop = false })
54+
return
55+
}
4056
ClawScaffold(
4157
contentPadding = PaddingValues(start = ClawTheme.spacing.lg, top = 14.dp, end = ClawTheme.spacing.lg, bottom = 6.dp),
4258
) {
@@ -59,6 +75,13 @@ internal fun SessionDashboardScreen(
5975
maxLines = 1,
6076
overflow = TextOverflow.Ellipsis,
6177
)
78+
if (desktopObserveAvailable) {
79+
ClawPlainIconButton(
80+
icon = Icons.Outlined.DesktopWindows,
81+
contentDescription = nativeString("Open desktop"),
82+
onClick = { showingDesktop = true },
83+
)
84+
}
6285
Icon(
6386
imageVector = Icons.Outlined.Dashboard,
6487
contentDescription = null,

‎apps/android/app/src/main/java/ai/openclaw/app/ui/SettingsScreens.kt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ internal enum class SettingsRoute {
189189
Dreaming,
190190
Canvas,
191191
Terminal,
192+
Desktop,
192193
Notifications,
193194
PhoneCapabilities,
194195
Gateway,
@@ -224,6 +225,7 @@ internal fun SettingsDetailScreen(
224225
SettingsRoute.Dreaming -> DreamingSettingsScreen(viewModel = viewModel, onBack = onBack)
225226
SettingsRoute.Canvas -> CanvasSettingsScreen(viewModel = viewModel, onBack = onBack)
226227
SettingsRoute.Terminal -> TerminalSettingsScreen(viewModel = viewModel, onBack = onBack)
228+
SettingsRoute.Desktop -> DesktopScreen(viewModel = viewModel, onBack = onBack)
227229
SettingsRoute.Notifications -> NotificationSettingsScreen(viewModel = viewModel, onBack = onBack)
228230
SettingsRoute.PhoneCapabilities -> PhoneCapabilitiesScreen(viewModel = viewModel, onBack = onBack)
229231
SettingsRoute.Gateway -> GatewaySettingsScreen(viewModel = viewModel, onBack = onBack)

‎apps/android/app/src/main/java/ai/openclaw/app/ui/ShellScreen.kt‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ import androidx.compose.material.icons.filled.Tune
9393
import androidx.compose.material.icons.outlined.AccessTime
9494
import androidx.compose.material.icons.outlined.ChatBubbleOutline
9595
import androidx.compose.material.icons.outlined.Dashboard
96+
import androidx.compose.material.icons.outlined.DesktopWindows
9697
import androidx.compose.material.icons.outlined.Folder
9798
import androidx.compose.material.icons.outlined.Inventory2
9899
import androidx.compose.material.icons.outlined.MicNone
@@ -1684,6 +1685,7 @@ private fun SettingsShellScreen(
16841685
val nodesDevicesSummary by viewModel.nodesDevicesSummary.collectAsState()
16851686
val channelsSummary by viewModel.channelsSummary.collectAsState()
16861687
val dreamingSummary by viewModel.dreamingSummary.collectAsState()
1688+
val desktopObserveAvailable by viewModel.desktopObserveAvailable.collectAsState()
16871689
val appearanceThemeMode by viewModel.appearanceThemeMode.collectAsState()
16881690
val providerRows = providerRows(providers = providers, models = models)
16891691
val readyProviderCount = providerRows.count { it.ready }
@@ -1748,7 +1750,7 @@ private fun SettingsShellScreen(
17481750
}
17491751

17501752
val settingsRows =
1751-
listOf(
1753+
listOfNotNull(
17521754
SettingsRow(
17531755
nativeText("Gateway"),
17541756
verbatimText(gatewaySummary(gatewayConnectionDisplay)),
@@ -1801,6 +1803,11 @@ private fun SettingsShellScreen(
18011803
),
18021804
SettingsRow(nativeText("Dreaming"), verbatimText(dreamingSummaryText(dreamingSummary)), Icons.Default.Storage, status = dreamingStatus(dreamingSummary), route = SettingsRoute.Dreaming),
18031805
SettingsRow(nativeText("Terminal"), nativeText("Shell in the agent workspace"), Icons.Outlined.Terminal, status = isConnected, route = SettingsRoute.Terminal),
1806+
if (desktopObserveAvailable) {
1807+
SettingsRow(nativeText("Desktop"), nativeText("View a machine screen"), Icons.Outlined.DesktopWindows, status = isConnected, route = SettingsRoute.Desktop)
1808+
} else {
1809+
null
1810+
},
18041811
SettingsRow(nativeText("Voice"), if (speakerEnabled) nativeText("Speaker on") else nativeText("Speaker muted"), Icons.Default.Mic, route = SettingsRoute.Voice),
18051812
SettingsRow(nativeText("Canvas"), nativeText("Screen surface"), Icons.AutoMirrored.Filled.ScreenShare, status = isConnected, route = SettingsRoute.Canvas),
18061813
SettingsRow(nativeText("Notifications"), if (notificationForwardingEnabled) nativeText("Smart delivery") else nativeText("Off"), Icons.Default.Notifications, route = SettingsRoute.Notifications),
@@ -2053,6 +2060,7 @@ internal fun settingsSectionTitleForRoute(route: SettingsRoute): NativeText =
20532060
SettingsRoute.SkillWorkshop,
20542061
SettingsRoute.Dreaming,
20552062
SettingsRoute.Terminal,
2063+
SettingsRoute.Desktop,
20562064
-> nativeText("Agents & automation")
20572065

20582066
SettingsRoute.Voice,

‎apps/android/app/src/test/java/ai/openclaw/app/AndroidScreenshotModeTest.kt‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class AndroidScreenshotModeTest {
4747
assertEquals(HomeDestination.Chat, AndroidScreenshotScene.Chat.homeDestination)
4848
assertEquals(HomeDestination.Chat, AndroidScreenshotScene.Swarm.homeDestination)
4949
assertEquals(HomeDestination.Settings, AndroidScreenshotScene.Settings.homeDestination)
50+
assertEquals(HomeDestination.Settings, AndroidScreenshotScene.Desktop.homeDestination)
5051
assertEquals(HomeDestination.Settings, AndroidScreenshotScene.VoiceWake.homeDestination)
5152
}
5253

@@ -81,4 +82,12 @@ class AndroidScreenshotModeTest {
8182
assertEquals(AndroidScreenshotScene.VoiceWake, scene)
8283
assertEquals(SettingsRoute.Voice, scene.settingsRoute)
8384
}
85+
86+
@Test
87+
fun desktopSceneTargetsDesktopSettings() {
88+
val scene = AndroidScreenshotScene.fromRawValue("desktop")
89+
90+
assertEquals(AndroidScreenshotScene.Desktop, scene)
91+
assertEquals(SettingsRoute.Desktop, scene.settingsRoute)
92+
}
8493
}

0 commit comments

Comments
 (0)