Android: drop screen.* invoke aliases
This commit is contained in:
@@ -19,7 +19,6 @@ import com.steipete.clawdis.node.node.CanvasController
|
||||
import com.steipete.clawdis.node.protocol.ClawdisCapability
|
||||
import com.steipete.clawdis.node.protocol.ClawdisCameraCommand
|
||||
import com.steipete.clawdis.node.protocol.ClawdisCanvasCommand
|
||||
import com.steipete.clawdis.node.protocol.ClawdisInvokeCommandAliases
|
||||
import com.steipete.clawdis.node.voice.VoiceWakeManager
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -446,12 +445,9 @@ class NodeRuntime(context: Context) {
|
||||
}
|
||||
|
||||
private suspend fun handleInvoke(command: String, paramsJson: String?): BridgeSession.InvokeResult {
|
||||
// Back-compat: accept screen.* commands and map them to canvas.*.
|
||||
val canonicalCommand = ClawdisInvokeCommandAliases.canonicalizeScreenToCanvas(command)
|
||||
|
||||
if (
|
||||
canonicalCommand.startsWith(ClawdisCanvasCommand.NamespacePrefix) ||
|
||||
canonicalCommand.startsWith(ClawdisCameraCommand.NamespacePrefix)
|
||||
command.startsWith(ClawdisCanvasCommand.NamespacePrefix) ||
|
||||
command.startsWith(ClawdisCameraCommand.NamespacePrefix)
|
||||
) {
|
||||
if (!isForeground.value) {
|
||||
return BridgeSession.InvokeResult.error(
|
||||
@@ -460,14 +456,14 @@ class NodeRuntime(context: Context) {
|
||||
)
|
||||
}
|
||||
}
|
||||
if (canonicalCommand.startsWith(ClawdisCameraCommand.NamespacePrefix) && !cameraEnabled.value) {
|
||||
if (command.startsWith(ClawdisCameraCommand.NamespacePrefix) && !cameraEnabled.value) {
|
||||
return BridgeSession.InvokeResult.error(
|
||||
code = "CAMERA_DISABLED",
|
||||
message = "CAMERA_DISABLED: enable Camera in Settings",
|
||||
)
|
||||
}
|
||||
|
||||
return when (canonicalCommand) {
|
||||
return when (command) {
|
||||
ClawdisCanvasCommand.Show.rawValue -> BridgeSession.InvokeResult.ok(null)
|
||||
ClawdisCanvasCommand.Hide.rawValue -> BridgeSession.InvokeResult.ok(null)
|
||||
ClawdisCanvasCommand.SetMode.rawValue -> {
|
||||
|
||||
@@ -6,20 +6,6 @@ enum class ClawdisCapability(val rawValue: String) {
|
||||
VoiceWake("voiceWake"),
|
||||
}
|
||||
|
||||
enum class ClawdisScreenCommand(val rawValue: String) {
|
||||
Show("screen.show"),
|
||||
Hide("screen.hide"),
|
||||
SetMode("screen.setMode"),
|
||||
Navigate("screen.navigate"),
|
||||
Eval("screen.eval"),
|
||||
Snapshot("screen.snapshot"),
|
||||
;
|
||||
|
||||
companion object {
|
||||
const val NamespacePrefix: String = "screen."
|
||||
}
|
||||
}
|
||||
|
||||
enum class ClawdisCanvasCommand(val rawValue: String) {
|
||||
Show("canvas.show"),
|
||||
Hide("canvas.hide"),
|
||||
@@ -43,13 +29,3 @@ enum class ClawdisCameraCommand(val rawValue: String) {
|
||||
const val NamespacePrefix: String = "camera."
|
||||
}
|
||||
}
|
||||
|
||||
object ClawdisInvokeCommandAliases {
|
||||
fun canonicalizeScreenToCanvas(command: String): String {
|
||||
if (command.startsWith(ClawdisScreenCommand.NamespacePrefix)) {
|
||||
return ClawdisCanvasCommand.NamespacePrefix +
|
||||
command.removePrefix(ClawdisScreenCommand.NamespacePrefix)
|
||||
}
|
||||
return command
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,36 +5,13 @@ import org.junit.Test
|
||||
|
||||
class ClawdisProtocolConstantsTest {
|
||||
@Test
|
||||
fun mapsKnownScreenCommandsToCanvas() {
|
||||
val mappings =
|
||||
listOf(
|
||||
Pair(ClawdisScreenCommand.Show, ClawdisCanvasCommand.Show),
|
||||
Pair(ClawdisScreenCommand.Hide, ClawdisCanvasCommand.Hide),
|
||||
Pair(ClawdisScreenCommand.SetMode, ClawdisCanvasCommand.SetMode),
|
||||
Pair(ClawdisScreenCommand.Navigate, ClawdisCanvasCommand.Navigate),
|
||||
Pair(ClawdisScreenCommand.Eval, ClawdisCanvasCommand.Eval),
|
||||
Pair(ClawdisScreenCommand.Snapshot, ClawdisCanvasCommand.Snapshot),
|
||||
)
|
||||
|
||||
for ((screen, canvas) in mappings) {
|
||||
assertEquals(
|
||||
canvas.rawValue,
|
||||
ClawdisInvokeCommandAliases.canonicalizeScreenToCanvas(screen.rawValue),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun mapsUnknownScreenNamespaceToCanvas() {
|
||||
assertEquals("canvas.foo", ClawdisInvokeCommandAliases.canonicalizeScreenToCanvas("screen.foo"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun leavesNonScreenCommandsUnchanged() {
|
||||
assertEquals(
|
||||
ClawdisCameraCommand.Snap.rawValue,
|
||||
ClawdisInvokeCommandAliases.canonicalizeScreenToCanvas(ClawdisCameraCommand.Snap.rawValue),
|
||||
)
|
||||
fun canvasCommandsUseStableStrings() {
|
||||
assertEquals("canvas.show", ClawdisCanvasCommand.Show.rawValue)
|
||||
assertEquals("canvas.hide", ClawdisCanvasCommand.Hide.rawValue)
|
||||
assertEquals("canvas.setMode", ClawdisCanvasCommand.SetMode.rawValue)
|
||||
assertEquals("canvas.navigate", ClawdisCanvasCommand.Navigate.rawValue)
|
||||
assertEquals("canvas.eval", ClawdisCanvasCommand.Eval.rawValue)
|
||||
assertEquals("canvas.snapshot", ClawdisCanvasCommand.Snapshot.rawValue)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user