#!/bin/bash

PIDFILE="/tmp/dmp_widget.pid"

if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")" 2>/dev/null; then
  kill "$(cat "$PIDFILE")"
  rm -f "$PIDFILE"
else
  yad --title="DMP-A6 Info" \
      --window-icon=audio-x-generic \
      --on-top --skip-taskbar \
      --undecorated \
      --geometry=500x300+40+40 \
      --no-buttons \
      --image="/tmp/dmp_cover.jpg" \
      --text="$(~/.config/eww/scripts/get_dmp_state.sh | jq -r '.title + "\n" + .artist + "\n" + .info')" \
      --text-align=center \
      --fontname="JetBrains Mono 11" \
      --borders=12 &
  echo $! > "$PIDFILE"
fi

