also looking at this
fix(bridge): stop discarding the fields the page actually sends
#82
7 files
+375
-34
| @@ -216,7 +216,12 @@ pub const WindowBridge = struct { | ||
| 216 | 216 | // a payload like `{"resize":false,"fullscreen":true}` was read as |
| 217 | 217 | // `fullscreen=false` because the `:false` needle fired first. |
| 218 | 218 | 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 | |
| 220 | 225 | else |
| 221 | 226 | true; |
| 222 | 227 | |
| @@ -325,8 +330,19 @@ pub const WindowBridge = struct { | ||
| 325 | 330 | // Parse vibrancy type from {"vibrancy": "..."} |
| 326 | 331 | var vibrancy_type: []const u8 = "none"; |
| 327 | 332 | 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; | |
| 330 | 346 | if (std.mem.indexOfPos(u8, json_data, start, "\"")) |end| { |
| 331 | 347 | vibrancy_type = json_data[start..end]; |
| 332 | 348 | } |
| @@ -423,8 +439,12 @@ pub const WindowBridge = struct { | ||
| 423 | 439 | var opacity: f64 = 1.0; |
| 424 | 440 | if (data) |json_data| { |
| 425 | 441 | // 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; | |
| 428 | 448 | while (start < json_data.len and (json_data[start] == ' ' or json_data[start] == '\t')) : (start += 1) {} |
| 429 | 449 | var end = start; |
| 430 | 450 | while (end < json_data.len and ((json_data[end] >= '0' and json_data[end] <= '9') or json_data[end] == '.')) : (end += 1) {} |