#!/bin/zsh
set -e

APP="/Applications/Atollon.app"
INFO="$APP/Contents/Info.plist"

if [ ! -d "$APP" ]; then
  echo "Atollon.app not found in /Applications"
  exit 1
fi

BUNDLE_ID=$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "$INFO")
echo "Bundle ID: $BUNDLE_ID"

LSREGISTER="/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister"
"$LSREGISTER" -f "$APP" || true

defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add \
  "{ LSHandlerURLScheme = atollon; LSHandlerRoleAll = \"$BUNDLE_ID\"; }" || true

killall cfprefsd >/dev/null 2>&1 || true

echo "Testing…"
open "atollon://test" || true
echo "Done."
