#!/bin/sh
# init=/usr/bin/desk-win11 : the whole Windows 11 style Pomelo desktop: compositor, panel (the bottom taskbar), pomelo-desktop
# (desktop icons over the bloom wallpaper); then, for the test, the Start menu (pomelo-launcher) opens at 14 s and closes at 26 s,
# the file explorer opens on C:\ at 30 s and a Windows program (Notes.exe through pe_load) starts at 42 s.
. /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 1
/usr/bin/pomelo-desktop 2>/tmp/desktop.log &
dpid=$!
sleep 13
/usr/bin/pomelo-launcher 2>/tmp/launcher.log &
sleep 12
/usr/bin/pomelo-launcher 2>>/tmp/launcher.log &      # a second start toggles the menu closed
sleep 4
/usr/bin/pomelo-files /c 2>/tmp/files.log &
fpid=$!
sleep 12
/usr/bin/pe_load "/c/Program Files/Pomelo Notes/Notes.exe" 2>/tmp/notes.log &
npid=$!
N=${DESK_WIN11_SECONDS:-60}; t=0
while [ $t -lt $N ] && kill -0 $cpid 2>/dev/null; do sleep 1; t=$((t+1)); done
echo "desk-win11: compositor=$(kill -0 $cpid 2>/dev/null && echo up || echo down) panel=$(kill -0 $ppid 2>/dev/null && echo up || echo down) desktop=$(kill -0 $dpid 2>/dev/null && echo up || echo down) files=$(kill -0 $fpid 2>/dev/null && echo up || echo down) notes=$(kill -0 $npid 2>/dev/null && echo up || echo down)"
echo "--- panel log"; tail -6 /tmp/panel.log
echo "--- notes log"; head -3 /tmp/notes.log
echo "--- compositor log"; tail -4 /tmp/compositor.log
kill $npid $fpid $dpid $ppid $cpid 2>/dev/null; wait
exit 0
