#!/bin/sh
# PerliStream Server tray icon (per desktop user). The server is the
# perlistream-server system service; this only shows its state and controls it.
#   perlistream-server-tray [--port N] [--status]
# Uses the distro python3 (GTK + AppIndicator bindings are distro packages:
# python3-gi, gir1.2-ayatanaappindicator3-0.1). The app folder is APPENDED to
# sys.path so none of its modules can shadow the standard library.
SELF="$(readlink -f "$0" 2>/dev/null || echo "$0")"
PREFIX="$(cd "$(dirname "$SELF")/.." && pwd)"
PY=/usr/bin/python3
[ -x "$PY" ] || PY="$(command -v python3)"
if ! "$PY" -c 'import gi' >/dev/null 2>&1; then
    echo "perlistream-server-tray: python3-gi is not installed (sudo apt install python3-gi gir1.2-ayatanaappindicator3-0.1)" >&2
    exit 1
fi
exec "$PY" -I -c 'import sys, runpy; sys.path.append(sys.argv.pop(1)); sys.argv[0] = "perlistream-server-tray"; runpy.run_module("tray", run_name="__main__", alter_sys=True)' "$PREFIX/app" "$@"
