fix: compile errors - WatchBridge uses node.id (Node is public field); MainActivity wrap JSONObject.put in try/catch

This commit is contained in:
2026-09-02 00:23:07 +08:00
parent 96abfb10e5
commit d1d1ebf18d
2 changed files with 11 additions and 9 deletions
@@ -46,13 +46,15 @@ public class MainActivity extends AppCompatActivity {
if (s != null) { if (s != null) {
runOnUiThread(() -> status.setText("状态: " + s.optString("model") + " / " + s.optString("cwd"))); runOnUiThread(() -> status.setText("状态: " + s.optString("model") + " / " + s.optString("cwd")));
JSONObject payload = new JSONObject(); JSONObject payload = new JSONObject();
payload.put("model", s.optString("model"));
payload.put("running", s.optBoolean("running", false));
payload.put("activeSessionId", s.optString("activeSessionId"));
JSONObject msg = new JSONObject(); JSONObject msg = new JSONObject();
msg.put("type", "status"); try {
msg.put("payload", payload); payload.put("model", s.optString("model"));
if (watchBridge != null) watchBridge.sendToWatch(msg.toString()); payload.put("running", s.optBoolean("running", false));
payload.put("activeSessionId", s.optString("activeSessionId"));
msg.put("type", "status");
msg.put("payload", payload);
if (watchBridge != null) watchBridge.sendToWatch(msg.toString());
} catch (Exception ignore) {}
} }
} }
@@ -42,7 +42,7 @@ public class WatchBridge {
.addOnSuccessListener(nodes -> { .addOnSuccessListener(nodes -> {
if (nodes != null && nodes.size() > 0) { if (nodes != null && nodes.size() > 0) {
node = nodes.get(0); node = nodes.get(0);
main.post(() -> listener.onWatchConnected(true, node.getId())); main.post(() -> listener.onWatchConnected(true, node.id));
registerListener(); registerListener();
} else { } else {
main.post(() -> listener.onWatchConnected(false, null)); main.post(() -> listener.onWatchConnected(false, null));
@@ -59,14 +59,14 @@ public class WatchBridge {
main.post(() -> listener.onWatchMessage(json)); main.post(() -> listener.onWatchMessage(json));
} }
}; };
messageApi.addListener(node.getId(), l) messageApi.addListener(node.id, l)
.addOnSuccessListener(ignore -> { }) .addOnSuccessListener(ignore -> { })
.addOnFailureListener(e -> main.post(() -> listener.onError("addListener: " + e.getMessage()))); .addOnFailureListener(e -> main.post(() -> listener.onError("addListener: " + e.getMessage())));
} }
public void sendToWatch(String json) { public void sendToWatch(String json) {
if (node == null) return; if (node == null) return;
messageApi.sendMessage(node.getId(), json.getBytes()) messageApi.sendMessage(node.id, json.getBytes())
.addOnSuccessListener(ignore -> { }) .addOnSuccessListener(ignore -> { })
.addOnFailureListener(e -> main.post(() -> listener.onError("sendMessage: " + e.getMessage()))); .addOnFailureListener(e -> main.post(() -> listener.onError("sendMessage: " + e.getMessage())));
} }