#!/usr/bin/env bash

PID_FILE="/tmp/vpn-socks.pid"
VPN_SCRIPT="$HOME/.config/waybar/scripts/vpn.sh"

get_status() {
    if pgrep -f "ssh -D 1080" > /dev/null 2>&1; then
        echo '{"text": " 󱚿 ", "class": "connected", "tooltip": "VPN Connected (Click to disconnect)"}'
    else
        echo '{"text": " 󰖩 ", "class": "disconnected", "tooltip": "VPN Disconnected (Click to connect)"}'
    fi
}

toggle() {
    if pgrep -f "ssh -D 1080" > /dev/null 2>&1; then
        "$VPN_SCRIPT" stop
    else
        "$VPN_SCRIPT" start
    fi
}

case "$1" in
    status)
        get_status
        ;;
    toggle)
        toggle
        ;;
    *)
        get_status
        ;;
esac
