desktop_icons_auto_check.sh 4.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/bash
  2. # desktop_icons_auto_check.sh <vm> <we_manager dist/linux-unpacked | .deb> - we_manager's "only draw the overlay while a wallpaper is
  3. # running" mode on a Plasma Wayland VM (the guest needs gtk4-layer-shell, ~/lwe from prep_guest.sh): the setting is on after a
  4. # fresh start, an enabled overlay is not drawn on a bare desktop, starts with the engine and goes away when the engine is
  5. # stopped in the app, killed with kill all, or killed from outside; with the mode off it stays up without an engine, and
  6. # switching the mode on removes it again. The master switch off removes it while an engine runs. FRESH=0 keeps the app's profile.
  7. # WEM_LAUNCH and WEM_FLAGS are added to the app's start line like in the other we_manager scripts.
  8. HERE=$(cd "$(dirname "$0")" && pwd)
  9. vm=$1 app=$2
  10. FRESH=${FRESH:-1}
  11. sshv() { "$HERE/linuxvm.sh" ssh "$vm" "$@" </dev/null; }
  12. status=0
  13. pass() { echo "PASS $1"; }
  14. fail() { echo "FAIL $1"; status=1; }
  15. skip() { echo "SKIP $1"; }
  16. . "$HERE/wem_lib.sh"
  17. overlay_count() { sshv 'n=0; for p in $(pgrep -x python3); do tr "\0" " " < /proc/$p/cmdline | grep -q desktop-icons-overlay.py && n=$((n+1)); done; echo $n' | tr -d '[:space:]'; }
  18. engines() { sshv 'pgrep -xc linux-wallpaper || true' | tr -d '\n'; }
  19. # wait_overlay up|down <seconds>
  20. wait_overlay() {
  21. local want=$1 end=$((SECONDS + $2)) n
  22. while [ $SECONDS -lt $end ]; do
  23. n=$(overlay_count)
  24. if [[ $n =~ ^[0-9]+$ ]]; then
  25. if [ "$want" = up ] && [ "$n" -ge 1 ]; then return 0; fi
  26. if [ "$want" = down ] && [ "$n" -eq 0 ]; then return 0; fi
  27. fi
  28. sleep 1
  29. done
  30. return 1
  31. }
  32. expect() { # expect <up|down> <seconds> <what>
  33. if wait_overlay "$1" "$2"; then pass "$3"; else fail "$3 (overlays: $(overlay_count))"; fi
  34. }
  35. launch() { cdp "window.electronAPI.lwe.launch('$WP_DIR/1111948150', {screen: '*'})" >/dev/null; }
  36. for _ in $(seq 60); do sshv 'bash ~/lwe/sessenv.sh' >/dev/null 2>&1 && break; sleep 5; done
  37. sshv 'bash ~/lwe/sessenv.sh' >/dev/null 2>&1 || { fail "no desktop session"; exit 1; }
  38. session=$(sshv '. ~/sessenv; echo "$XDG_CURRENT_DESKTOP $XDG_SESSION_TYPE"')
  39. if [[ $session != *KDE*wayland* ]]; then skip "the overlay only exists on Plasma Wayland ($session)"; exit 0; fi
  40. layer_shell() { sshv 'bash -c "ls /usr/lib64/libgtk4-layer-shell.so* /usr/lib/libgtk4-layer-shell.so* /usr/lib/x86_64-linux-gnu/libgtk4-layer-shell.so* 2>/dev/null | head -1"'; }
  41. if [ -z "$(layer_shell)" ]; then
  42. wem_layer_shell_install >/dev/null 2>&1
  43. if [ -z "$(layer_shell)" ]; then skip "gtk4-layer-shell can't be installed in the guest, the overlay can't run"; exit 0; fi
  44. fi
  45. sshv 'mkdir -p ~/wem; pkill -f "[w]e-manager"; pkill -x python3; pkill -x linux-wallpaper; true'
  46. wem_wait_gone
  47. [ "$FRESH" = 1 ] && sshv 'rm -rf ~/.config/we-manager'
  48. wem_install || exit 1
  49. wem_steam_lib 1111948150
  50. sshv 'd=$(xdg-user-dir DESKTOP); mkdir -p $d; touch $d/notes.txt $d/data.csv'
  51. wem_run || exit 1
  52. WP_DIR=$(sshv 'echo $HOME')/.steam/steam/steamapps/workshop/content/431960
  53. if [ "$FRESH" = 1 ]; then
  54. [ "$(cdp 'window.electronAPI.desktopIcons.getAuto()')" = true ] && pass "auto mode is on after a fresh start" || fail "auto mode is off after a fresh start"
  55. fi
  56. cdp 'window.electronAPI.desktopIcons.setAuto(true)' >/dev/null
  57. cdp 'window.electronAPI.desktopIcons.setEnabled(true)' >/dev/null
  58. sleep 6
  59. [ "$(overlay_count)" -eq 0 ] && pass "no overlay on a bare desktop" || fail "overlay drawn without a wallpaper"
  60. launch
  61. expect up 40 "overlay starts with the wallpaper"
  62. cdp 'window.electronAPI.lwe.stop()' >/dev/null
  63. expect down 15 "overlay removed when the wallpaper is stopped"
  64. launch
  65. expect up 40 "overlay comes back with the next wallpaper"
  66. cdp 'window.electronAPI.lwe.killAll()' >/dev/null
  67. expect down 15 "overlay removed after kill all"
  68. launch
  69. expect up 40 "overlay up again"
  70. sshv 'pkill -9 -x linux-wallpaper; true'
  71. expect down 15 "overlay removed when the engine is killed from outside"
  72. cdp 'window.electronAPI.desktopIcons.setAuto(false)' >/dev/null
  73. expect up 15 "auto mode off: overlay up without a wallpaper"
  74. cdp 'window.electronAPI.desktopIcons.setAuto(true)' >/dev/null
  75. expect down 15 "auto mode switched on: overlay removed on a bare desktop"
  76. launch
  77. expect up 40 "overlay up with the wallpaper again"
  78. cdp 'window.electronAPI.desktopIcons.setEnabled(false)' >/dev/null
  79. expect down 15 "master switch off removes the overlay while the engine runs"
  80. [ "$(engines)" -ge 1 ] && pass "engine still running" || fail "engine stopped by the master switch"
  81. cdp 'window.electronAPI.desktopIcons.setEnabled(true)' >/dev/null
  82. expect up 15 "master switch on: overlay up with the running engine"
  83. cdp 'window.electronAPI.desktopIcons.setEnabled(false)' >/dev/null
  84. cdp 'window.electronAPI.lwe.killAll()' >/dev/null
  85. sshv 'pkill -f "[w]e-manager"; pkill -x python3; true'
  86. exit $status