#!/bin/sh
# init=/usr/bin/desk-win : the compositor, then a Windows (PE) program in a window.
#   DESK_EXE=hello5.exe (default)   DESK_WITH_CALC=1 also starts the Linux calculator.
. /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
[ -n "${DESK_WITH_CALC:-}" ] && { /usr/bin/pomelo-calc 2>/tmp/calc.log & }
/usr/bin/pe_load -v /usr/bin/${DESK_EXE:-hello5.exe} &
epid=$!
# Run until the time is up or the program ends by itself (its window was closed).
N=${DESK_RUN_SECONDS:-15}; t=0
while [ $t -lt $N ] && kill -0 $epid 2>/dev/null; do sleep 1; t=$((t+1)); done
if kill -0 $epid 2>/dev/null; then ended=no; else ended=yes; wait $epid; echo "desk-win: exe exit status $?"; sleep 5; fi
echo "desk-win: compositor alive=$(kill -0 $cpid 2>/dev/null && echo yes || echo no) exe ended=$ended"
kill $epid $cpid 2>/dev/null; wait
echo "--- compositor log"; tail -8 /tmp/compositor.log
exit 0
