gstack-browser
75 lines · scripts/app/gstack-browser at 3f79d81
1#!/bin/bash
2# GStack Browser launcher — starts browse server + headed Chromium with extension
3#
4# Works in two modes:
5# 1. Inside .app bundle: Contents/MacOS/gstack-browser → Resources are at ../Resources/
6# 2. Dev mode (run directly): uses global gstack install at ~/.claude/skills/gstack/
7#
8# Usage:
9# open "GStack Browser.app" # .app bundle mode
10# scripts/app/gstack-browser # dev mode (uses global gstack install)
12set -euo pipefail
14SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
16# Detect mode: .app bundle or dev
17if [ -d "$SCRIPT_DIR/../Resources" ]; then
18 # .app bundle mode — resources are alongside in the bundle
19 DIR="$(cd "$SCRIPT_DIR/../Resources" && pwd)"
20else
21 # Dev mode — use global gstack install
22 DIR="$HOME/.claude/skills/gstack"
23fi
25# Point Playwright at bundled Chromium (only in .app mode)
26if [ -d "$DIR/chromium" ]; then
27 CHROMIUM_APP=$(ls -d "$DIR/chromium/"*.app 2>/dev/null | head -1)
28 if [ -n "$CHROMIUM_APP" ]; then
29 export GSTACK_CHROMIUM_PATH="$CHROMIUM_APP/Contents/MacOS/$(ls "$CHROMIUM_APP/Contents/MacOS/" | head -1)"
30 fi
31fi
33# Browse server config
34export BROWSE_PORT=34567
35export BROWSE_HEADED=1
37# Extension: bundled first, then global install
38if [ -d "$DIR/extension" ]; then
39 export BROWSE_EXTENSIONS_DIR="$DIR/extension"
40fi
42# Server script: bundled source first, then global install
43if [ -f "$DIR/src/server.ts" ]; then
44 export BROWSE_SERVER_SCRIPT="$DIR/src/server.ts"
45elif [ -f "$HOME/.claude/skills/gstack/browse/src/server.ts" ]; then
46 export BROWSE_SERVER_SCRIPT="$HOME/.claude/skills/gstack/browse/src/server.ts"
47fi
49# Browse binary: bundled .app first, then global install
50# Note: -x on a directory is true, so check -f (regular file) too
51BROWSE_BIN=""
52for candidate in "$DIR/browse" "$DIR/browse/dist/browse" "$HOME/.claude/skills/gstack/browse/dist/browse"; do
53 if [ -f "$candidate" ] && [ -x "$candidate" ]; then
54 BROWSE_BIN="$candidate"
55 break
56 fi
57done
59if [ -z "$BROWSE_BIN" ]; then
60 echo "ERROR: browse binary not found. Run 'bun run build' in the gstack repo or reinstall GStack Browser."
61 exit 1
62fi
64# Ensure profile directory
65mkdir -p ~/.gstack/chromium-profile
67# Project binding: use last-used project dir, default to home
68PROJECT_DIR=$(cat ~/.gstack/last-project 2>/dev/null || echo "$HOME")
69if [ ! -d "$PROJECT_DIR" ]; then
70 PROJECT_DIR="$HOME"
71fi
72cd "$PROJECT_DIR"
74# Launch browse in connect mode
75exec "$BROWSE_BIN" connect "$@"