#!/bin/bash
# Launcher used by Meeting Helper.app — finds the meeting-helper CLI
# regardless of Spotlight's minimal PATH and exec's `meeting-helper gui
# --foreground`. The --foreground flag is critical: it keeps this process
# in the foreground for the lifetime of the window, so macOS keeps the
# dock icon alive. Without it, gui forks the shell as a detached
# subprocess and the .app's process exits immediately, causing macOS to
# remove the dock icon (and act as if the app crashed).
set -e
for prefix in \
    "$HOME/.local/bin" \
    /opt/homebrew/bin \
    /usr/local/bin \
    /usr/bin \
    "$HOME/.pyenv/shims" \
    "$HOME/.venv/bin"; do
  if [ -x "$prefix/meeting-helper" ]; then
    exec "$prefix/meeting-helper" gui --foreground
  fi
done
osascript -e 'display dialog "Could not find the `meeting-helper` command. Install it first via:\n\n  pipx install meeting-helper" with title "Meeting Helper" buttons {"OK"} default button "OK" with icon caution'
exit 1
