#!/bin/sh
# init=/usr/bin/desk-apps : compositor + shell (pomelo-panel: Dock, menu bar) and, after DESK_LAUNCHER_AT seconds
# (default 8), the launcher (the same program the Super key / the menu's Launcher entry starts).  No program is
# started by us: scripts/test-apps.sh types into the launcher to start a Windows application.
. /usr/bin/desk-env
/usr/bin/pomelo-compositor 2>/tmp/compositor.log &
cpid=$!
i=0
while [ $i -lt 100 ] && [ ! -S "$XDG_RUNTIME_DIR/wayland-0" ]; do sleep 0.2; i=$((i+1)); done
export WAYLAND_DISPLAY=wayland-0
export XDG_DATA_DIRS=/usr/share
/usr/bin/pomelo-panel 2>/tmp/panel.log &
ppid=$!
sleep ${DESK_LAUNCHER_AT:-8}
echo "desk-apps: windows entries: $(ls /usr/share/applications | grep -c '^win-')"
/usr/bin/pomelo-launcher 2>/tmp/launcher.log &
lpid=$!
N=${DESK_APPS_SECONDS:-48}; t=0
while [ $t -lt $N ] && kill -0 $cpid 2>/dev/null; do sleep 1; t=$((t+1)); done
echo "--- panel log"; tail -10 /tmp/panel.log
echo "--- launcher log (also stderr of the programs it started)"; cat /tmp/launcher.log
echo "--- compositor log"; tail -6 /tmp/compositor.log
echo "--- processes"; ps 2>/dev/null | grep -E "pe_load|pomelo" | grep -v grep
kill $(pidof pe_load) 2>/dev/null; kill $lpid $ppid $cpid 2>/dev/null
i=0; while [ $i -lt 20 ] && [ -n "$(pidof pe_load pomelo-panel pomelo-compositor pomelo-launcher)" ]; do sleep 0.5; i=$((i+1)); done
wait $lpid $ppid $cpid 2>/dev/null
exit 0
