#!/bin/sh
set -eu

# This script is called when the app is quit from the Finder.
# If the app is run from launchd, this script is not called.

pidpath="$HOME/Library/Application Support/com.example.App/com.example.App.pid"
if test -f "$pidpath"; then
    pid=$(cat "$pidpath")
    if kill -0 "$pid" 2>/dev/null; then
        echo "Stopping dev server with PID $pid"
        kill "$pid"
        rm -f "$pidpath"
    else
        echo "No running dev server found with PID $pid"
    fi
else
    echo "No PID file found at $pidpath"
fi