Dotfiles/desktopenvs/hyprdrive/scripts/astro-menu.sh

58 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Toggle the astro-menu popup (or open it to a section). Forwards a verb to the
# resident daemon over D-Bus; if the daemon isn't running yet, starts it first.
# Mirrors hyprlua's menu-toggle.sh (same app, renamed for hyprdrive).
# (No `set -e`: a non-zero `grep`/`busctl` in the wait loop is expected and must
# not abort the script before it forwards the verb.)
#
# astro-menu.sh -> --toggle (top, the default)
# astro-menu.sh appdrawer -> open with the app drawer expanded
# astro-menu.sh left -> toggle, sliding in from / pinned to the left
# astro-menu.sh toggle right -> same, explicit verb
# astro-menu.sh appdrawer bottom
#
# Verbs: (toggle) | show | hide | appdrawer. Sides: top | bottom | left | right.
BUS="eu.abdelbaki.astromenu"
OBJ="/eu/abdelbaki/astromenu"
APP="${HOME}/.config/astro-menu/main.py"
verb="${1:-}"; side="${2:-}"
case "$verb" in
top|bottom|left|right) side="$verb"; verb="" ;;
esac
case "$verb" in
appdrawer) VERB="--appdrawer"; ACTION="appdrawer"; HAS_PARAM=1 ;;
show) VERB="--show"; ACTION="show"; HAS_PARAM=1 ;;
hide) VERB="--hide"; ACTION="hide"; HAS_PARAM=0 ;;
*) VERB="--toggle"; ACTION="toggle"; HAS_PARAM=1 ;;
esac
case "$side" in
top|bottom|left|right) SIDE=(--side "$side") ;;
*) side=""; SIDE=() ;;
esac
registered() { busctl --user list 2>/dev/null | grep -q "$BUS"; }
if registered; then
if [[ $HAS_PARAM -eq 1 ]]; then
param="[<'${side}'>]"
else
param="[]"
fi
exec gdbus call --session --dest "$BUS" --object-path "$OBJ" \
--method org.gtk.Actions.Activate "$ACTION" "$param" "{}" >/dev/null
fi
"${HOME}/.config/scripts/astro-menu-start.sh" >/dev/null 2>&1 &
for _ in $(seq 1 25); do
if registered; then
exec "$0" "$@"
fi
sleep 0.2
done
exec python3 "$APP" "$VERB" "${SIDE[@]}"