Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(web): auto-install Cap Desktop in install-cli.sh when missing
Richie McIlroy5df3a4175bb8
diff --git a/apps/web/app/install-cli.sh/route.ts b/apps/web/app/install-cli.sh/route.tsindex bfef35a9a..c2134a70b 100644--- a/apps/web/app/install-cli.sh/route.ts+++ b/apps/web/app/install-cli.sh/route.ts@@ -1,40 +1,145 @@const capAppPathParameter = "$" + "{CAP_APP_PATH:-}";const capCliInstallDirParameter = "$" + "{CAP_CLI_INSTALL_DIR:-}";+const capDesktopInstallDirParameter = "$" + "{CAP_DESKTOP_INSTALL_DIR:-}";+const capDesktopForceInstallParameter = "$" + "{CAP_DESKTOP_FORCE_INSTALL:-}";const homeParameter = "$" + "{HOME:-}";const capNoModifyPathParameter = "$" + "{CAP_NO_MODIFY_PATH:-}";const shellParameter = "$" + "{SHELL:-/bin/sh}";+const tmpDirParameter = "$" + "{TMPDIR:-/tmp}";const script = String.raw`#!/usr/bin/env shset -euAPP_PATH="${capAppPathParameter}"CLI_INSTALL_DIR_OVERRIDE="${capCliInstallDirParameter}"+DESKTOP_INSTALL_DIR_OVERRIDE="${capDesktopInstallDirParameter}"+DESKTOP_FORCE_INSTALL="${capDesktopForceInstallParameter}"HOME_DIR="${homeParameter}"+TMP_BASE="${tmpDirParameter}"+TMP_ROOT=""+MOUNT_DIR=""+APP_TMP=""+MOUNTED=0-if [ -z "$APP_PATH" ]; then+find_cap_app() {for candidate in "/Applications/Cap.app" "$HOME_DIR/Applications/Cap.app"; doif [ -d "$candidate" ]; thenAPP_PATH="$candidate"+ return 0+ fi+ done++ return 1+}++cleanup_desktop_install() {+ if [ "$MOUNTED" = "1" ]; then+ hdiutil detach "$MOUNT_DIR" -quiet >/dev/null 2>&1 || true+ fi++ if [ -n "$TMP_ROOT" ]; then+ rm -rf "$TMP_ROOT"+ fi++ if [ -n "$APP_TMP" ]; then+ rm -rf "$APP_TMP"+ fi+}++install_cap_desktop() {+ if [ "$(uname -s)" != "Darwin" ]; then+ echo "Cap Desktop auto-install is only supported on macOS. Install Cap from https://cap.so/download, then run this script again." >&2+ exit 1+ fi++ case "$(uname -m)" in+ arm64|aarch64) DOWNLOAD_URL="https://cap.so/download/apple-silicon" ;;+ x86_64|amd64) DOWNLOAD_URL="https://cap.so/download/apple-intel" ;;+ *)+ echo "Unsupported Mac architecture: $(uname -m)" >&2+ exit 1+ ;;+ esac++ if [ -n "$DESKTOP_INSTALL_DIR_OVERRIDE" ]; then+ APP_DIR="$DESKTOP_INSTALL_DIR_OVERRIDE"+ elif [ -n "$APP_PATH" ] && [ -w "$(dirname "$APP_PATH")" ]; then+ APP_DIR="$(dirname "$APP_PATH")"+ elif [ -w "/Applications" ]; then+ APP_DIR="/Applications"+ else+ APP_DIR="$HOME_DIR/Applications"+ fi++ APP_PATH="$APP_DIR/Cap.app"+ APP_TMP="$APP_DIR/.Cap.app.installing"+ TMP_ROOT="$(mktemp -d "$TMP_BASE/cap-cli-install.XXXXXX")"+ DMG_PATH="$TMP_ROOT/Cap.dmg"+ MOUNT_DIR="$TMP_ROOT/mount"+ mkdir -p "$APP_DIR" "$MOUNT_DIR"++ trap cleanup_desktop_install EXIT HUP INT TERM++ echo "Downloading Cap Desktop..."+ curl -fL "$DOWNLOAD_URL" -o "$DMG_PATH"+ hdiutil attach "$DMG_PATH" -nobrowse -quiet -mountpoint "$MOUNT_DIR"+ MOUNTED=1++ SOURCE_APP=""+ for candidate in "$MOUNT_DIR"/Cap.app "$MOUNT_DIR"/*.app; do+ if [ -d "$candidate" ] && [ "$(basename "$candidate")" = "Cap.app" ]; then+ SOURCE_APP="$candidate"breakfidone++ if [ -z "$SOURCE_APP" ]; then+ echo "Downloaded Cap Desktop image did not contain Cap.app." >&2+ exit 1+ fi++ echo "Installing Cap Desktop to $APP_PATH..."+ rm -rf "$APP_TMP"+ ditto "$SOURCE_APP" "$APP_TMP"+ rm -rf "$APP_PATH"+ mv "$APP_TMP" "$APP_PATH"+ APP_TMP=""+ hdiutil detach "$MOUNT_DIR" -quiet+ MOUNTED=0+ rm -rf "$TMP_ROOT"+ TMP_ROOT=""+ trap - EXIT HUP INT TERM+}++if [ -z "$HOME_DIR" ]; then+ echo "Could not determine home directory. Set HOME, then run this script again." >&2+ exit 1fiif [ -z "$APP_PATH" ]; then- echo "Cap Desktop was not found. Install Cap from https://cap.so/download, then run this script again." >&2+ if ! find_cap_app; then+ install_cap_desktop+ fi+elif [ ! -d "$APP_PATH" ]; then+ echo "Cap Desktop was not found at $APP_PATH." >&2exit 1fi-if [ -z "$HOME_DIR" ]; then- echo "Could not determine home directory. Set CAP_CLI_INSTALL_DIR, then run this script again." >&2- exit 1+if [ -n "$DESKTOP_FORCE_INSTALL" ]; then+ install_cap_desktopfiCLI_TARGET="$APP_PATH/Contents/MacOS/cap-cli"if [ ! -x "$CLI_TARGET" ]; then- echo "This Cap Desktop install does not include the CLI. Update Cap, then run this script again." >&2- exit 1+ echo "This Cap Desktop install does not include the CLI. Reinstalling Cap Desktop..."+ install_cap_desktop+ CLI_TARGET="$APP_PATH/Contents/MacOS/cap-cli"++ if [ ! -x "$CLI_TARGET" ]; then+ echo "This Cap Desktop install does not include the CLI." >&2+ exit 1+ fifiif [ -n "$CLI_INSTALL_DIR_OVERRIDE" ]; then