wip(watch): sauvegarde travail en cours lot critique (#157 #163 #164 #174 #175 #178)

This commit is contained in:
2026-07-29 12:34:07 +02:00
parent f523a5a8b5
commit 74d6000606
26 changed files with 516 additions and 62 deletions

View File

@ -26,6 +26,7 @@ object WatchBridgePlugin {
const val SENSOR_SUMMARY_PATH = "/gametime/watch/sensor-summary"
const val SENSOR_SAMPLE_PATH = "/gametime/watch/sensor-sample"
const val ACK_PATH = "/gametime/phone/ack"
const val ALERT_PATH = "/gametime/phone/alert"
const val STATE_PATH = "/gametime/phone/projection"
const val WATCH_CAPABILITY = "gametime_watch_companion"
@ -140,6 +141,7 @@ object WatchBridgePlugin {
}
when (call.method) {
"publishProjection" -> publishProjection(context, call.arguments, result)
"publishAlert" -> publishAlert(context, call.arguments, result)
"sendCommandAck" -> sendCommandAck(context, call.arguments, result)
"requestCapabilityRefresh" -> {
requestCapabilityRefresh(context)
@ -202,7 +204,7 @@ object WatchBridgePlugin {
val targetNode = commandId?.let { pendingCommandNodes.remove(it) }
val payload = JSONObject(map).toString().toByteArray(StandardCharsets.UTF_8)
if (targetNode != null) {
sendMessage(context, targetNode, payload, result)
sendMessage(context, targetNode, ACK_PATH, payload, result)
return
}
Wearable.getCapabilityClient(context)
@ -236,14 +238,57 @@ object WatchBridgePlugin {
private fun sendMessage(
context: Context,
nodeId: String,
path: String,
payload: ByteArray,
result: MethodChannel.Result,
) {
Wearable.getMessageClient(context)
.sendMessage(nodeId, ACK_PATH, payload)
.sendMessage(nodeId, path, payload)
.addOnSuccessListener { result.success(null) }
.addOnFailureListener { error ->
result.error("send_ack_failed", error.message, null)
result.error("send_message_failed", error.message, null)
}
}
private fun publishAlert(
context: Context,
arguments: Any?,
result: MethodChannel.Result,
) {
val map = arguments as? Map<*, *>
if (map == null) {
result.error("invalid_alert", "Alert payload must be a map.", null)
return
}
val payload = JSONObject(map).toString().toByteArray(StandardCharsets.UTF_8)
Wearable.getCapabilityClient(context)
.getCapability(WATCH_CAPABILITY, CapabilityClient.FILTER_REACHABLE)
.addOnSuccessListener { capability ->
val nodes = capability.nodes.toList()
if (nodes.isEmpty()) {
result.success(null)
return@addOnSuccessListener
}
var remaining = nodes.size
var failed = false
for (node in nodes) {
Wearable.getMessageClient(context)
.sendMessage(node.id, ALERT_PATH, payload)
.addOnSuccessListener {
remaining -= 1
if (remaining == 0 && !failed) result.success(null)
}
.addOnFailureListener { error ->
if (failed) {
return@addOnFailureListener
}
failed = true
result.error("send_alert_failed", error.message, null)
}
}
}
.addOnFailureListener { error ->
result.error("capability_lookup_failed", error.message, null)
}
}