Skip to content

Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.

5.8 KB
Raw Blame
#!/bin/zsh
# Launch-window smoke (issue #58): the app must open its main window at launch even when the
# previous session ended with only the Settings window open. 0.8.0 added a Settings scene and
# macOS window restoration brought it back alone at relaunch; the library was reachable only via
# Cmd-N. This reproduces the report's shape on an empty HIGHBALL_HOME: launch, open Settings,
# close the main window, quit, relaunch, and assert a main window is visible. Then the
# same with Quit and Keep Windows, whose saved state restores no window at all.
# Needs the screen (Accessibility permission for System Events). Records
# private/launch-window-smoke/latest.json.
#
# Usage: Scripts/launch-window-smoke.sh [path/to/Highball.app]
set -u
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
APP="${1:-$ROOT/dist/Highball.app}"; BIN="$APP/Contents/MacOS/Highball"
[ -x "$BIN" ] || { echo "no app at $APP (run Scripts/make-app.sh)"; exit 2; }
OUT="$ROOT/private/launch-window-smoke"; mkdir -p "$OUT"
H="${TMPDIR:-/tmp}/hb-launch-window-smoke"; rm -rf "$H"; mkdir -p "$H"
# Address the test build by pid, never by name: the user's own Highball may be running too, and
# a name lookup then talks to the wrong app (2026-09-08: every step came back empty that way).
pid(){ pgrep -n -f "$BIN"; }
wins(){ osascript -e "tell application \"System Events\" to tell (first process whose unix id is $(pid)) to get name of every window" 2>/dev/null | tr -d '\n'; }
record(){ python3 -c "import json,time;json.dump({'passed':'$1'=='true','epoch':int(time.time()),'date':time.strftime('%Y-%m-%d'),'windows':'$2'},open('$OUT/latest.json','w'),indent=2)"; }
pkill -f "$BIN" 2>/dev/null; sleep 1
HIGHBALL_HOME="$H" "$BIN" >/dev/null 2>&1 & sleep 6
osascript -e "tell application \"System Events\" to set frontmost of (first process whose unix id is $(pid)) to true" >/dev/null 2>&1; sleep 1
echo "after launch:        $(wins)"
# Every step below goes through System Events, which answers with nothing for every app when
# Accessibility is denied to this shell, and the smoke then fails as "no main window" with each
# line blank (2026-09-24). CG still sees the window, so tell the two apart before going on.
if [ -z "$(wins)" ] && [ "$("$ROOT/Scripts/winlist" 2>/dev/null | grep "pid=$(pid)" | grep -c on=true)" -ge 1 ]; then
  # With the session locked or the display asleep, System Events reports no windows for any app
  # while CG still lists them, and every keystroke below would go nowhere (2026-09-28: a gate run
  # on the locked Mac). Denied Accessibility is a different answer, an outright refusal (-25211).
  # The main window is on screen, which is the fact the relaunch assertion is about; the
  # Settings-restoration scenario itself cannot be driven without a session, and the record says so.
  ax=$(osascript -e 'tell application "System Events" to get name of first process whose frontmost is true' 2>&1)
  if ! echo "$ax" | grep -qE "25211|assistive access"; then
    pkill -f "$BIN" 2>/dev/null; rm -rf "$H"; record true "session locked or display asleep, main window on screen per CG, restoration scenario not driven"
    echo "LAUNCH WINDOW SMOKE PASSED with a caveat: session locked or display asleep (System Events answers '$ax' but lists no windows), the main window is on screen per CG, the Settings-restoration scenario was not driven"; exit 0
  fi
  pkill -f "$BIN" 2>/dev/null; rm -rf "$H"; record false "accessibility denied"
  echo "LAUNCH WINDOW SMOKE FAILED: the window is on screen but System Events cannot see it: Accessibility is denied to this shell (System Settings, Privacy & Security, Accessibility)"; exit 1
fi
# Settings and Quit are pressed in the app's menu through Accessibility rather than typed: a
# typed Cmd-Q goes to whatever app is in front, so with someone at the Mac it can miss Highball
# or quit their app instead. The menu items run the same commands as the shortcuts.
menu(){ osascript -e "tell application \"System Events\" to tell (first process whose unix id is $(pid)) to click menu item \"$1\" of menu 1 of menu bar item 2 of menu bar 1" >/dev/null 2>&1; }
menu "Settings…"; sleep 2
echo "after Settings:      $(wins)"
osascript -e "tell application \"System Events\" to tell (first process whose unix id is $(pid)) to click button 1 of window \"Highball\"" >/dev/null 2>&1; sleep 1
echo "after closing main:  $(wins)"
menu "Quit Highball"; sleep 3
pgrep -f "$BIN" >/dev/null && pkill -9 -f "$BIN"; sleep 1
HIGHBALL_HOME="$H" "$BIN" >/dev/null 2>&1 & sleep 7
w=$(wins); echo "after relaunch:      $w"
if ! echo "$w" | grep -q 'Highball'; then
  pkill -f "$BIN" 2>/dev/null; rm -rf "$H"
  record false "$w"; echo "LAUNCH WINDOW SMOKE FAILED: no main window after relaunch (windows: $w)"; exit 1
fi
# The same session saved on purpose: Quit and Keep Windows with only Settings open (also what any
# quit does with "Close windows when quitting an application" off). That state restores zero
# windows, and every launch after it came back with none (2026-10-06, three gate runs).
menu "Settings…"; sleep 2
osascript -e "tell application \"System Events\" to tell (first process whose unix id is $(pid)) to click button 1 of window \"Highball\"" >/dev/null 2>&1; sleep 1
echo "settings only again: $(wins)"
menu "Quit and Keep Windows"; sleep 3
pgrep -f "$BIN" >/dev/null && pkill -9 -f "$BIN"; sleep 1
HIGHBALL_HOME="$H" "$BIN" >/dev/null 2>&1 & sleep 7
w=$(wins); echo "after kept relaunch: $w"
# A plain quit with the main window open discards the kept state, so the next launch of any
# Highball on this Mac (the installed one too) starts clean.
menu "Quit Highball"; sleep 3
pkill -f "$BIN" 2>/dev/null; rm -rf "$H"
if echo "$w" | grep -q 'Highball'; then record true "$w"; echo "LAUNCH WINDOW SMOKE PASSED (main window present after both relaunches)"; exit 0
else record false "$w"; echo "LAUNCH WINDOW SMOKE FAILED: no main window after a relaunch from kept windows (windows: $w)"; exit 1; fi