#!/bin/bash # Off-screen screenshot of the running UI, for visual review. # # Runs alkane-toolkit under a private Xvfb display (never the real desktop), # waits for its window to map, and captures it to a PNG. By default it renders # the offline bench-fleet fixtures (ALKANE_FAKE_SCAN) so the shot is # deterministic and needs no hardware; pass --live to scan the real network. # # Usage: scripts/ui-screenshot.sh [out.png] [--live] [binary] set -u REPO=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) WX_PREFIX="${WX_PREFIX:-$HOME/.cache/wx-3.3.3-linux}" export WX_RS_WXCONFIG="${WX_RS_WXCONFIG:-$WX_PREFIX/bin/wx-config}" OUT="${1:-alkane-toolkit.png}" LIVE=0; BIN="" shift 2>/dev/null || true for a in "$@"; do case "$a" in --live) LIVE=1 ;; *) BIN="$a" ;; esac done if [ -z "$BIN" ]; then if [ ! -x "$WX_PREFIX/bin/wx-config" ]; then "$REPO/scripts/build-wx-linux.sh"; fi ( cd "$REPO" && cargo build --release -p alkane-gui --offline ) || exit 3 TDIR=$(cd "$REPO" && cargo metadata --no-deps --format-version 1 --offline 2>/dev/null \ | tr ',' '\n' | grep -o '"target_directory":"[^"]*"' | head -1 | cut -d'"' -f4) [ -n "$TDIR" ] || TDIR="$REPO/target" BIN="$TDIR/release/alkane-toolkit" fi [ -x "$BIN" ] || { echo "binary not found: $BIN" >&2; exit 3; } DISP=":98" FAKE_ENV="ALKANE_FAKE_SCAN=1" [ "$LIVE" = "1" ] && FAKE_ENV="" Xvfb "$DISP" -screen 0 1280x850x24 -nolisten tcp >/dev/null 2>&1 & XPID=$! sleep 1.2 # warm the font/GTK caches so the first window map is not stalled DISPLAY="$DISP" xclock >/dev/null 2>&1 & WARM=$!; sleep 1.2; kill "$WARM" 2>/dev/null # shellcheck disable=SC2086 DISPLAY="$DISP" GDK_BACKEND=x11 $FAKE_ENV "$BIN" >/dev/null 2>&1 & APID=$! WID=""; t=0 while [ "$t" -lt 25 ]; do sleep 1; t=$((t+1)) kill -0 "$APID" 2>/dev/null || { echo "app exited early" >&2; break; } line=$(DISPLAY="$DISP" xwininfo -root -tree 2>/dev/null | grep '"alkane-toolkit"' | grep -E '1[0-9]{3}x[0-9]{3}' | head -1) [ -n "$line" ] && { WID=$(echo "$line" | awk '{print $1}'); break; } done sleep 2 # let it paint and drain a scan tick if [ -n "$WID" ]; then DISPLAY="$DISP" import -window "$WID" "$OUT" && echo "wrote $OUT (window $WID, ${t}s)" else DISPLAY="$DISP" import -window root "$OUT"; echo "no app window; captured root -> $OUT" >&2 fi kill "$APID" 2>/dev/null kill "$XPID" 2>/dev/null