Nodes: handle canvas.* commands on iOS/Android

This commit is contained in:
Peter Steinberger
2025-12-18 01:17:23 +00:00
parent 22516437b7
commit 21a27e3b65
4 changed files with 18 additions and 19 deletions

View File

@@ -422,11 +422,11 @@ class NodeRuntime(context: Context) {
}
private suspend fun handleInvoke(command: String, paramsJson: String?): BridgeSession.InvokeResult {
if (command.startsWith("screen.") || command.startsWith("camera.")) {
if (command.startsWith("canvas.") || command.startsWith("camera.")) {
if (!isForeground.value) {
return BridgeSession.InvokeResult.error(
code = "NODE_BACKGROUND_UNAVAILABLE",
message = "NODE_BACKGROUND_UNAVAILABLE: screen/camera commands require foreground",
message = "NODE_BACKGROUND_UNAVAILABLE: canvas/camera commands require foreground",
)
}
}
@@ -438,19 +438,19 @@ class NodeRuntime(context: Context) {
}
return when (command) {
"screen.show" -> BridgeSession.InvokeResult.ok(null)
"screen.hide" -> BridgeSession.InvokeResult.ok(null)
"screen.setMode" -> {
"canvas.show" -> BridgeSession.InvokeResult.ok(null)
"canvas.hide" -> BridgeSession.InvokeResult.ok(null)
"canvas.setMode" -> {
val mode = CanvasController.parseMode(paramsJson)
canvas.setMode(mode)
BridgeSession.InvokeResult.ok(null)
}
"screen.navigate" -> {
"canvas.navigate" -> {
val url = CanvasController.parseNavigateUrl(paramsJson)
if (url != null) canvas.navigate(url)
BridgeSession.InvokeResult.ok(null)
}
"screen.eval" -> {
"canvas.eval" -> {
val js =
CanvasController.parseEvalJs(paramsJson)
?: return BridgeSession.InvokeResult.error(
@@ -468,7 +468,7 @@ class NodeRuntime(context: Context) {
}
BridgeSession.InvokeResult.ok("""{"result":${result.toJsonString()}}""")
}
"screen.snapshot" -> {
"canvas.snapshot" -> {
val maxWidth = CanvasController.parseSnapshotMaxWidth(paramsJson)
val base64 =
try {

View File

@@ -185,7 +185,7 @@ class BridgeSessionTest {
writer.flush()
// Ask the node to invoke something; handler will throw.
writer.write("""{"type":"invoke","id":"i1","command":"screen.snapshot","paramsJSON":null}""")
writer.write("""{"type":"invoke","id":"i1","command":"canvas.snapshot","paramsJSON":null}""")
writer.write("\n")
writer.flush()

View File

@@ -265,16 +265,15 @@ final class NodeAppModel {
}
private func handleInvoke(_ req: BridgeInvokeRequest) async -> BridgeInvokeResponse {
// Alias for "canvas" capability: accept canvas.* commands and map them to screen.*.
let command = ClawdisInvokeCommandAliases.canonicalizeCanvasToScreen(req.command)
let command = req.command
if command.hasPrefix("screen.") || command.hasPrefix("camera."), self.isBackgrounded {
if command.hasPrefix("canvas.") || command.hasPrefix("camera."), self.isBackgrounded {
return BridgeInvokeResponse(
id: req.id,
ok: false,
error: ClawdisNodeError(
code: .backgroundUnavailable,
message: "NODE_BACKGROUND_UNAVAILABLE: screen/camera commands require foreground"))
message: "NODE_BACKGROUND_UNAVAILABLE: canvas/camera commands require foreground"))
}
if command.hasPrefix("camera."), !self.isCameraEnabled() {

View File

@@ -6,12 +6,12 @@ public enum ClawdisScreenMode: String, Codable, Sendable {
}
public enum ClawdisScreenCommand: String, Codable, Sendable {
case show = "screen.show"
case hide = "screen.hide"
case setMode = "screen.setMode"
case navigate = "screen.navigate"
case evalJS = "screen.eval"
case snapshot = "screen.snapshot"
case show = "canvas.show"
case hide = "canvas.hide"
case setMode = "canvas.setMode"
case navigate = "canvas.navigate"
case evalJS = "canvas.eval"
case snapshot = "canvas.snapshot"
}
public struct ClawdisScreenNavigateParams: Codable, Sendable, Equatable {