#!/bin/sh
# init=/usr/bin/desk-bar : compositor + shell (menu bar, status bar, wallpaper) and nothing else, for the bar/background
# test.  The config (~/.config/pomelo/settings.conf) is whatever the image holds; settings the user changes are written
# there and shown again at the end of the run.  DESK_RUN_SECONDS ends it.
. /usr/bin/desk-env
echo "desk-bar: config at start: $(cat $XDG_CONFIG_HOME/pomelo/settings.conf 2>/dev/null | tr '\n' ';')"
/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=$!
N=${DESK_BAR_SECONDS:-75}; t=0
while [ $t -lt $N ] && kill -0 $cpid 2>/dev/null; do sleep 1; t=$((t+1)); done
echo "desk-bar: config at end: $(cat $XDG_CONFIG_HOME/pomelo/settings.conf 2>/dev/null | tr '\n' ';')"
echo "desk-bar: compositor alive=$(kill -0 $cpid 2>/dev/null && echo yes || echo no) panel alive=$(kill -0 $ppid 2>/dev/null && echo yes || echo no)"
echo "--- panel log"; tail -15 /tmp/panel.log
echo "--- compositor log"; tail -6 /tmp/compositor.log
kill $ppid $cpid 2>/dev/null; wait
exit 0
