fix: compile errors - WatchBridge uses node.id (Node is public field); MainActivity wrap JSONObject.put in try/catch
This commit is contained in:
@@ -46,13 +46,15 @@ public class MainActivity extends AppCompatActivity {
|
||||
if (s != null) {
|
||||
runOnUiThread(() -> status.setText("状态: " + s.optString("model") + " / " + s.optString("cwd")));
|
||||
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();
|
||||
msg.put("type", "status");
|
||||
msg.put("payload", payload);
|
||||
if (watchBridge != null) watchBridge.sendToWatch(msg.toString());
|
||||
try {
|
||||
payload.put("model", s.optString("model"));
|
||||
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 -> {
|
||||
if (nodes != null && nodes.size() > 0) {
|
||||
node = nodes.get(0);
|
||||
main.post(() -> listener.onWatchConnected(true, node.getId()));
|
||||
main.post(() -> listener.onWatchConnected(true, node.id));
|
||||
registerListener();
|
||||
} else {
|
||||
main.post(() -> listener.onWatchConnected(false, null));
|
||||
@@ -59,14 +59,14 @@ public class WatchBridge {
|
||||
main.post(() -> listener.onWatchMessage(json));
|
||||
}
|
||||
};
|
||||
messageApi.addListener(node.getId(), l)
|
||||
messageApi.addListener(node.id, l)
|
||||
.addOnSuccessListener(ignore -> { })
|
||||
.addOnFailureListener(e -> main.post(() -> listener.onError("addListener: " + e.getMessage())));
|
||||
}
|
||||
|
||||
public void sendToWatch(String json) {
|
||||
if (node == null) return;
|
||||
messageApi.sendMessage(node.getId(), json.getBytes())
|
||||
messageApi.sendMessage(node.id, json.getBytes())
|
||||
.addOnSuccessListener(ignore -> { })
|
||||
.addOnFailureListener(e -> main.post(() -> listener.onError("sendMessage: " + e.getMessage())));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user