← Commit history

finishDemo relay-safe hwnd fallback

John Lauer ·e0b231726b ·2mo ago ·parent fb9a33c
1 file changed +22−4
web-control-demo.html+22−4
@@ -518,11 +518,29 @@ for (const w of mine) {     if (!cfg.stateCmd) { setRes(c.res, "ok", "Demo finished", "the bridge closed its windows"); c.btn.disabled = false; return; }     clog(c, "Fetching the bridge's full window state: " + cfg.stateCmd);     return postVerb(cfg.stateCmd, {}, target).then(function (sr) {-      if (!(sr.s === 200 && sr.j && renderShots(c, sr.j))) {-        setRes(c.res, "ok", "Demo finished", "the bridge already closed its windows - nothing to show");-        clog(c, "DONE - the demo completed; the bridge closed its windows before we captured state.");-        c.btn.disabled = false;+      if (sr.s === 200 && sr.j && renderShots(c, sr.j)) return;+      // The state verb's own capture may not ride the relay inline (fusion's+      // exceeds the 4MB cap and comes back as a far-machine PATH). Same+      // fallback as the live snaps: hwnd -> desktop_screenshot_base64.+      if (cfg.snap && cfg.snap.viaHwnd) {+        clog(c, "  no inline captures - falling back to an hwnd screenshot of the app");+        return postVerb(cfg.snap.viaHwnd, { screenshot: false }, target).then(function (wr) {+          var wd = (wr.j && (wr.j.data || wr.j)) || {};+          if (!wd.hwnd) throw new Error("no app window reported");+          return postVerb("desktop_screenshot_base64", { hwnd: wd.hwnd, maxWidth: 900 }, target).then(function (sh) {+            if (!(sh.s === 200 && sh.j && sh.j.image)) throw new Error("screenshot failed");+            addShot(c.card, sh.j.image, wd.title || "app window");+            setRes(c.res, "ok", "Demo done - final window below", "1 window on " + esc(c._who || selfLabel()) + " (generic capture)");+            c.btn.disabled = false;+          });+        }).catch(function (e2) {+          setRes(c.res, "ok", "Demo finished", "the bridge already closed its windows - nothing to show (" + String(e2 && e2.message || e2).slice(0, 60) + ")");+          c.btn.disabled = false;+        });       }+      setRes(c.res, "ok", "Demo finished", "the bridge already closed its windows - nothing to show");+      clog(c, "DONE - the demo completed; the bridge closed its windows before we captured state.");+      c.btn.disabled = false;     }).catch(function (e) { setRes(c.res, "err", "state fetch failed", String(e)); c.btn.disabled = false; });   }   // Find the bridge's window array wherever it rides: the final poll embeds it at