ReviewOS

also looking at this

craft-native/craft

fix(bridge): stop discarding the fields the page actually sends

#82
Merged glennmichael123 wants to merge fix/bridge-field-names into main
7 files +375 -34
packages/zig/src/bridge_bluetooth.zigmodified+21-16
Changes to packages/zig/src/bridge_bluetooth.zig
@@ -463,16 +463,28 @@ pub const BluetoothBridge = struct {
463463
464464 /// Connect to a Bluetooth device
465465 /// JSON: {"address": "XX:XX:XX:XX:XX:XX"}
466 fn connectDevice(self: *Self, data: []const u8) !void {
467 _ = self;
468 var address: []const u8 = "";
469
470 if (std.mem.indexOf(u8, data, "\"address\":\"")) |idx| {
471 const start = idx + 11;
472 if (std.mem.indexOfPos(u8, data, start, "\"")) |end| {
473 address = data[start..end];
466 /// The device a connect/disconnect names.
467 ///
468 /// `craft.bluetooth.connectDevice(id)` sends `{"id":"…"}`, and both
469 /// handlers scanned only for `"address":"`. The needle never matched, the
470 /// address stayed empty, and the call failed its own `MissingData` check —
471 /// so connecting to a device found by `craft.bluetooth.onDeviceFound` was
472 /// impossible. `address` stays accepted for anything posting raw messages.
473 fn deviceAddress(data: []const u8) []const u8 {
474 for ([_][]const u8{ "\"id\":\"", "\"address\":\"" }) |key| {
475 if (std.mem.indexOf(u8, data, key)) |idx| {
476 const start = idx + key.len;
477 if (std.mem.indexOfPos(u8, data, start, "\"")) |end| {
478 return data[start..end];
479 }
474480 }
475481 }
482 return "";
483 }
484
485 fn connectDevice(self: *Self, data: []const u8) !void {
486 _ = self;
487 const address = deviceAddress(data);
476488
477489 if (address.len == 0) return BridgeError.MissingData;
478490
@@ -497,14 +509,7 @@ pub const BluetoothBridge = struct {
497509 /// JSON: {"address": "XX:XX:XX:XX:XX:XX"}
498510 fn disconnectDevice(self: *Self, data: []const u8) !void {
499511 _ = self;
500 var address: []const u8 = "";
501
502 if (std.mem.indexOf(u8, data, "\"address\":\"")) |idx| {
503 const start = idx + 11;
504 if (std.mem.indexOfPos(u8, data, start, "\"")) |end| {
505 address = data[start..end];
506 }
507 }
512 const address = deviceAddress(data);
508513
509514 if (address.len == 0) return BridgeError.MissingData;
510515