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_window.zigmodified+25-5
Changes to packages/zig/src/bridge_window.zig
@@ -216,7 +216,12 @@ pub const WindowBridge = struct {
216216 // a payload like `{"resize":false,"fullscreen":true}` was read as
217217 // `fullscreen=false` because the `:false` needle fired first.
218218 const should_be_fullscreen = if (data) |json_data|
219 json_utils.getBool(json_data, "fullscreen") orelse true
219 // `craft.window.setFullscreen(on)` sends `{"value":…}`; this read
220 // `fullscreen`, which the page has never sent, so `orelse true`
221 // fired on every call and `setFullscreen(false)` *entered*
222 // fullscreen. `fullscreen` stays accepted for raw callers.
223 json_utils.getBool(json_data, "value") orelse
224 json_utils.getBool(json_data, "fullscreen") orelse true
220225 else
221226 true;
222227
@@ -325,8 +330,19 @@ pub const WindowBridge = struct {
325330 // Parse vibrancy type from {"vibrancy": "..."}
326331 var vibrancy_type: []const u8 = "none";
327332 if (data) |json_data| {
328 if (std.mem.indexOf(u8, json_data, "\"vibrancy\":\"")) |idx| {
329 const start = idx + 12;
333 // `setVibrancy(material)` sends `{"material":"sidebar"}`;
334 // this scanned for `"vibrancy":"`, never matched, and left
335 // "none" — which takes the *removal* branch below, so the call
336 // stripped vibrancy instead of applying it.
337 const vkey = if (std.mem.indexOf(u8, json_data, "\"material\":\"") != null)
338 "\"material\":\""
339 else
340 "\"vibrancy\":\"";
341 if (std.mem.indexOf(u8, json_data, vkey)) |idx| {
342 // `vkey.len`, not a literal: the two spellings happen to
343 // be the same length, which is luck and not something the
344 // next key added here would inherit.
345 const start = idx + vkey.len;
330346 if (std.mem.indexOfPos(u8, json_data, start, "\"")) |end| {
331347 vibrancy_type = json_data[start..end];
332348 }
@@ -423,8 +439,12 @@ pub const WindowBridge = struct {
423439 var opacity: f64 = 1.0;
424440 if (data) |json_data| {
425441 // Parse {"opacity": 0.8}
426 if (std.mem.indexOf(u8, json_data, "\"opacity\":")) |idx| {
427 var start = idx + 10;
442 // The page sends `{"value":0.4}`; this scanned for `"opacity":`,
443 // never matched, and left the default 1.0 — so every opacity was
444 // fully opaque and each value was indistinguishable from the next.
445 const key = if (std.mem.indexOf(u8, json_data, "\"value\":") != null) "\"value\":" else "\"opacity\":";
446 if (std.mem.indexOf(u8, json_data, key)) |idx| {
447 var start = idx + key.len;
428448 while (start < json_data.len and (json_data[start] == ' ' or json_data[start] == '\t')) : (start += 1) {}
429449 var end = start;
430450 while (end < json_data.len and ((json_data[end] >= '0' and json_data[end] <= '9') or json_data[end] == '.')) : (end += 1) {}