Files

72 lines
2.8 KiB
Bash
Executable File

#!/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=""
[ "$#" -eq 0 ] || shift
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; }
DISPLAY_FILE=$(mktemp)
XPID=""; APID=""; WARM=""
cleanup() {
[ -z "$APID" ] || kill "$APID" 2>/dev/null || true
[ -z "$WARM" ] || kill "$WARM" 2>/dev/null || true
[ -z "$XPID" ] || kill "$XPID" 2>/dev/null || true
rm -f "$DISPLAY_FILE"
}
trap cleanup EXIT
Xvfb -displayfd 3 -screen 0 1280x850x24 -nolisten tcp 3>"$DISPLAY_FILE" >/dev/null 2>&1 &
XPID=$!
for _ in {1..30}; do
[ -s "$DISPLAY_FILE" ] && break
kill -0 "$XPID" 2>/dev/null || { echo "Xvfb exited before startup" >&2; exit 3; }
sleep 0.1
done
[ -s "$DISPLAY_FILE" ] || { echo "Xvfb did not start" >&2; exit 3; }
DISP=":$(cat "$DISPLAY_FILE")"
# 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
if [ "$LIVE" = "1" ]; then
DISPLAY="$DISP" GDK_BACKEND=x11 "$BIN" >/dev/null 2>&1 &
else
DISPLAY="$DISP" GDK_BACKEND=x11 ALKANE_FAKE_SCAN=1 "$BIN" >/dev/null 2>&1 &
fi
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
[ -n "$WID" ] || { echo "no app window mapped" >&2; exit 1; }
DISPLAY="$DISP" import -window "$WID" "$OUT" || exit 1
echo "wrote $OUT (window $WID, ${t}s)"