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.ClawdisCapability
|
||||||
import com.steipete.clawdis.node.protocol.ClawdisCameraCommand
|
import com.steipete.clawdis.node.protocol.ClawdisCameraCommand
|
||||||
import com.steipete.clawdis.node.protocol.ClawdisCanvasCommand
|
import com.steipete.clawdis.node.protocol.ClawdisCanvasCommand
|
||||||
import com.steipete.clawdis.node.protocol.ClawdisInvokeCommandAliases
|
|
||||||
import com.steipete.clawdis.node.voice.VoiceWakeManager
|
import com.steipete.clawdis.node.voice.VoiceWakeManager
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -446,12 +445,9 @@ class NodeRuntime(context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun handleInvoke(command: String, paramsJson: String?): BridgeSession.InvokeResult {
|
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 (
|
if (
|
||||||
canonicalCommand.startsWith(ClawdisCanvasCommand.NamespacePrefix) ||
|
command.startsWith(ClawdisCanvasCommand.NamespacePrefix) ||
|
||||||
canonicalCommand.startsWith(ClawdisCameraCommand.NamespacePrefix)
|
command.startsWith(ClawdisCameraCommand.NamespacePrefix)
|
||||||
) {
|
) {
|
||||||
if (!isForeground.value) {
|
if (!isForeground.value) {
|
||||||
return BridgeSession.InvokeResult.error(
|
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(
|
return BridgeSession.InvokeResult.error(
|
||||||
code = "CAMERA_DISABLED",
|
code = "CAMERA_DISABLED",
|
||||||
message = "CAMERA_DISABLED: enable Camera in Settings",
|
message = "CAMERA_DISABLED: enable Camera in Settings",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return when (canonicalCommand) {
|
return when (command) {
|
||||||
ClawdisCanvasCommand.Show.rawValue -> BridgeSession.InvokeResult.ok(null)
|
ClawdisCanvasCommand.Show.rawValue -> BridgeSession.InvokeResult.ok(null)
|
||||||
ClawdisCanvasCommand.Hide.rawValue -> BridgeSession.InvokeResult.ok(null)
|
ClawdisCanvasCommand.Hide.rawValue -> BridgeSession.InvokeResult.ok(null)
|
||||||
ClawdisCanvasCommand.SetMode.rawValue -> {
|
ClawdisCanvasCommand.SetMode.rawValue -> {
|
||||||
|
|||||||
@@ -6,20 +6,6 @@ enum class ClawdisCapability(val rawValue: String) {
|
|||||||
VoiceWake("voiceWake"),
|
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) {
|
enum class ClawdisCanvasCommand(val rawValue: String) {
|
||||||
Show("canvas.show"),
|
Show("canvas.show"),
|
||||||
Hide("canvas.hide"),
|
Hide("canvas.hide"),
|
||||||
@@ -43,13 +29,3 @@ enum class ClawdisCameraCommand(val rawValue: String) {
|
|||||||
const val NamespacePrefix: String = "camera."
|
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 {
|
class ClawdisProtocolConstantsTest {
|
||||||
@Test
|
@Test
|
||||||
fun mapsKnownScreenCommandsToCanvas() {
|
fun canvasCommandsUseStableStrings() {
|
||||||
val mappings =
|
assertEquals("canvas.show", ClawdisCanvasCommand.Show.rawValue)
|
||||||
listOf(
|
assertEquals("canvas.hide", ClawdisCanvasCommand.Hide.rawValue)
|
||||||
Pair(ClawdisScreenCommand.Show, ClawdisCanvasCommand.Show),
|
assertEquals("canvas.setMode", ClawdisCanvasCommand.SetMode.rawValue)
|
||||||
Pair(ClawdisScreenCommand.Hide, ClawdisCanvasCommand.Hide),
|
assertEquals("canvas.navigate", ClawdisCanvasCommand.Navigate.rawValue)
|
||||||
Pair(ClawdisScreenCommand.SetMode, ClawdisCanvasCommand.SetMode),
|
assertEquals("canvas.eval", ClawdisCanvasCommand.Eval.rawValue)
|
||||||
Pair(ClawdisScreenCommand.Navigate, ClawdisCanvasCommand.Navigate),
|
assertEquals("canvas.snapshot", ClawdisCanvasCommand.Snapshot.rawValue)
|
||||||
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),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user