#!/usr/bin/env bash
|
#
|
# qa-settings-window-macos.sh - Launch PrivateVoice and capture the Settings window.
|
#
|
# Usage:
|
# ./scripts/qa-settings-window-macos.sh [APP_PATH] [OUTPUT_DIR]
|
#
|
set -euo pipefail
|
|
APP_NAME="PrivateVoice Dictation"
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
INFO_PLIST="$PROJECT_DIR/build/darwin/Info.plist"
|
|
APP_PATH="${1:-/Applications/$APP_NAME.app}"
|
VERSION="$(defaults read "$INFO_PLIST" CFBundleShortVersionString 2>/dev/null || echo "unknown")"
|
BUILD_ID="$(defaults read "$INFO_PLIST" CFBundleVersion 2>/dev/null || date +%Y%m%d.%H%M)"
|
OUTPUT_DIR="${2:-$PROJECT_DIR/build/qa/settings-window-$VERSION-build$BUILD_ID}"
|
SCREENSHOT="$OUTPUT_DIR/settings-input-tab.png"
|
BOUNDS_FILE="$OUTPUT_DIR/settings-window-bounds.txt"
|
|
fail() {
|
echo "ERROR: $1" >&2
|
exit 1
|
}
|
|
[[ -d "$APP_PATH" ]] || fail "App bundle not found: $APP_PATH"
|
|
mkdir -p "$OUTPUT_DIR"
|
|
osascript -e "tell application \"$APP_NAME\" to quit" >/dev/null 2>&1 || true
|
pkill -x "$APP_NAME" >/dev/null 2>&1 || true
|
sleep 1
|
|
open "$APP_PATH"
|
|
osascript <<APPLESCRIPT
|
tell application "System Events"
|
repeat 60 times
|
if exists process "$APP_NAME" then exit repeat
|
delay 0.25
|
end repeat
|
if not (exists process "$APP_NAME") then error "process did not start"
|
|
tell process "$APP_NAME"
|
set frontmost to true
|
repeat 80 times
|
if exists window 1 then exit repeat
|
delay 0.25
|
end repeat
|
if not (exists window 1) then error "settings window did not appear"
|
|
set position of window 1 to {80, 80}
|
set size of window 1 to {980, 720}
|
delay 0.8
|
|
try
|
click button "输入" of window 1
|
on error
|
set windowPosition to position of window 1
|
click at {item 1 of windowPosition + 92, item 2 of windowPosition + 144}
|
end try
|
|
delay 0.8
|
set windowPosition to position of window 1
|
set windowSize to size of window 1
|
set x to item 1 of windowPosition
|
set y to item 2 of windowPosition
|
set w to item 1 of windowSize
|
set h to item 2 of windowSize
|
do shell script "printf '%s,%s,%s,%s' " & x & " " & y & " " & w & " " & h & " > " & quoted form of "$BOUNDS_FILE"
|
end tell
|
end tell
|
APPLESCRIPT
|
|
BOUNDS="$(cat "$BOUNDS_FILE")"
|
screencapture -x -R"$BOUNDS" "$SCREENSHOT"
|
|
if [[ ! -s "$SCREENSHOT" ]]; then
|
fail "Screenshot was not created: $SCREENSHOT"
|
fi
|
|
echo "Settings window screenshot: $SCREENSHOT"
|
echo "Window bounds: $BOUNDS"
|