wem_features_check.sh 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #!/bin/bash
  2. # wem_features_check.sh <vm> <we_manager dist/linux-unpacked | .deb | flatpak:<bundle.flatpak | installed>> [screen] - the
  3. # we_manager features that decide what is on the screen, driven through the real app over DevTools (cdp.py): saved profiles,
  4. # schedule rules (run now and a time trigger that fires by itself), application rules (a program runs, another app plays
  5. # sound, revert afterwards), split screens, daytime playlists following the clock, copy and move between library folders,
  6. # custom thumbnails, the audio input device list and the graphics notice. With flatpak: the same inside the sandbox
  7. # (engines, host programs and the library folders go through flatpak-spawn and the sandbox's filesystem).
  8. # Not covered here (needs a Steam client): Verify files, Repair, backup of workshop items. Fonts need a file dialog.
  9. # Prints one PASS|FAIL|SKIP line per check. WEM_LAUNCH and WEM_FLAGS are added to the start line like in the other we_manager scripts.
  10. HERE=$(cd "$(dirname "$0")" && pwd)
  11. vm=$1 app=$2 screen=${3:-Virtual-1}
  12. sshv() { "$HERE/linuxvm.sh" ssh "$vm" "$@" </dev/null; }
  13. status=0
  14. pass() { echo "PASS $1"; }
  15. fail() { echo "FAIL $1"; status=1; }
  16. skip() { echo "SKIP $1"; }
  17. CDP_TIMEOUT=${CDP_TIMEOUT:-180}
  18. . "$HERE/wem_lib.sh"
  19. A=1120596121 B=1111948150 W=1078208425
  20. LOCAL_A=900000011 LOCAL_B=900000012
  21. FPAPP=io.github.WallpaperEngineLover.we_manager
  22. sshv 'mkdir -p ~/wem; pkill -f "[w]e-manager" 2>/dev/null; pkill -x lwe-ruletest 2>/dev/null; pkill -x paplay 2>/dev/null; true'
  23. wem_wait_gone
  24. if [[ $app == flatpak:* ]]; then
  25. bundle=${app#flatpak:}
  26. sshv 'mkdir -p ~/wem'
  27. "$HERE/linuxvm.sh" scp "$vm" "$HERE/cdp.py" wem/cdp.py
  28. if [ "$bundle" != installed ]; then
  29. "$HERE/linuxvm.sh" scp "$vm" "$bundle" wem/app.flatpak
  30. sshv "flatpak --user remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo; flatpak --user install -y --noninteractive --reinstall ~/wem/app.flatpak >/tmp/fp-install.log 2>&1" \
  31. && pass "the bundle installs" || { fail "bundle install: $(sshv 'tail -3 /tmp/fp-install.log')"; exit 1; }
  32. fi
  33. wem_start_line="${WEM_LAUNCH:-} flatpak run $FPAPP ${WEM_FLAGS:-}"
  34. mode="inside the Flatpak"
  35. else
  36. wem_install || exit 1
  37. wem_engine_fallback
  38. mode="native"
  39. fi
  40. wem_steam_lib $A $B $W
  41. wem_run || exit 1
  42. pass "we_manager starts ($mode)"
  43. HOME_DIR=$(sshv 'echo $HOME')
  44. LIBS=$HOME_DIR/lwe-features-lib
  45. LIB_A=$LIBS/a LIB_B=$LIBS/b
  46. engine_args() { sshv 'pgrep -af "/[l]inux-wallpaperengine(\.bin)? "'; }
  47. assigned() { cdp "window.electronAPI.wallpaper.getAssignments().then(a => { const x = a.find(e => e.screen === '$screen'); return x ? x.wallpaperId : '' })" | tr -d '"'; }
  48. wait_assigned() { # <wallpaper id> <seconds>
  49. local end=$((SECONDS + $2))
  50. while [ $SECONDS -lt $end ]; do [ "$(assigned)" = "$1" ] && return 0; sleep 2; done
  51. return 1
  52. }
  53. apply() { cdp "window.electronAPI.wallpaper.apply({wallpaperId: '$1', screen: '$screen'})" >/dev/null; sleep 6; }
  54. engine_runs() { [ -n "$(engine_args | grep -- "wp-$1\|/$1")" ]; }
  55. cleanup() {
  56. cdp 'window.electronAPI.lwe.killAll()' >/dev/null
  57. cdp "(async () => { const api = window.electronAPI;
  58. for (const r of await api.schedule.getAll()) if (r.name.startsWith('wem-')) await api.schedule.delete(r.id);
  59. for (const r of await api.appRules.getAll()) if (r.name.startsWith('wem-')) await api.appRules.delete(r.id);
  60. for (const p of await api.profiles.getAll()) if (p.name.startsWith('wem-')) await api.profiles.delete(p.id);
  61. for (const p of await api.playlist.getAll()) if (p.title.startsWith('wem-')) await api.playlist.delete(p.id);
  62. await api.wallpaper.setSplit('$screen', null);
  63. await api.config.setExtraLibraries([]); await api.config.setDisplayMode('shared'); })()" >/dev/null
  64. sshv 'pkill -x lwe-ruletest; pkill -x paplay; pkill -f "[w]e-manager"; rm -rf ~/lwe-features-lib /tmp/lwe-ruletest /tmp/lwe-features-silence.wav; true'
  65. }
  66. cdp "window.electronAPI.config.setLanguage('en')" >/dev/null
  67. cdp "window.electronAPI.config.setDisplayMode('per-screen')" >/dev/null
  68. cdp "window.electronAPI.config.setWorkshopPath('$HOME_DIR/.steam/steam/steamapps/workshop/content/431960')" >/dev/null
  69. for _ in 1 2 3 4 5 6; do
  70. scanned=$(cdp 'window.electronAPI.library.scan()' | tr '\n' ' ')
  71. have=$(cdp "window.electronAPI.library.getAll().then(a => [$A, $B].filter(id => a.some(w => w.id === String(id))).length)")
  72. [ "$have" = 2 ] && break
  73. sleep 5
  74. done
  75. if [ "$have" = 2 ]; then pass "the test wallpapers are in the library"; else
  76. fail "library lacks the test wallpapers ($have of 2), last scan: $scanned, workshop path: $(cdp 'window.electronAPI.config.get().then(c => c.workshopPath)' | tr -d '\n')"
  77. cleanup; exit 1
  78. fi
  79. # profiles
  80. apply $A
  81. out=$(cdp "window.electronAPI.profiles.capture('wem-profile').then(p => p.id + ' ' + JSON.stringify(p.screens))")
  82. pid=$(echo "$out" | tr -d '"' | cut -d' ' -f1)
  83. [[ $out == *"$A"* ]] && pass "a profile captures what is on the screen" || fail "profile capture: $out"
  84. apply $B
  85. [ "$(assigned)" = $B ] && pass "another wallpaper replaces it" || fail "apply $B: screen shows $(assigned)"
  86. cdp "window.electronAPI.profiles.apply('$pid')" >/dev/null
  87. wait_assigned $A 30 && pass "applying the profile brings the first wallpaper back" || fail "profile apply: screen shows $(assigned)"
  88. engine_runs $A && pass "the engine runs the profile's wallpaper" || fail "no engine for $A after the profile: $(engine_args | cut -c1-200)"
  89. # schedule: run now, a profile as action, a time trigger firing by itself
  90. rule=$(cdp "window.electronAPI.schedule.save({name: 'wem-run', enabled: true, trigger: {type: 'time', time: '03:33', days: []}, action: {type: 'wallpaper', wallpaperId: '$B'}, screen: '$screen'}).then(r => r.id)" | tr -d '"')
  91. cdp "window.electronAPI.schedule.run('$rule')" >/dev/null
  92. wait_assigned $B 30 && pass "schedule: run now applies the rule's wallpaper" || fail "schedule run now: screen shows $(assigned)"
  93. prule=$(cdp "window.electronAPI.schedule.save({name: 'wem-profile-rule', enabled: true, trigger: {type: 'time', time: '03:34', days: []}, action: {type: 'profile', profileId: '$pid'}, screen: '*'}).then(r => r.id)" | tr -d '"')
  94. cdp "window.electronAPI.schedule.run('$prule')" >/dev/null
  95. wait_assigned $A 30 && pass "schedule: a rule can load a profile" || fail "schedule profile action: screen shows $(assigned)"
  96. cdp "window.electronAPI.schedule.delete('$prule')" >/dev/null
  97. at=$(sshv "date -d '+2 minutes' +%H:%M")
  98. cdp "window.electronAPI.schedule.save({id: '$rule', name: 'wem-run', enabled: true, trigger: {type: 'time', time: '$at', days: []}, action: {type: 'wallpaper', wallpaperId: '$B'}, screen: '$screen'})" >/dev/null
  99. [ "$(assigned)" = $A ] || apply $A
  100. if wait_assigned $B 200; then pass "schedule: a time trigger set for $at fires by itself"; else fail "schedule: nothing happened at $at, screen shows $(assigned)"; fi
  101. cdp "window.electronAPI.schedule.delete('$rule')" >/dev/null
  102. # application rules
  103. sshv 'cp "$(command -v sleep)" /tmp/lwe-ruletest'
  104. apply $A
  105. arule=$(cdp "window.electronAPI.appRules.save({name: 'wem-process', enabled: true, condition: {type: 'process', names: ['lwe-ruletest']}, action: {type: 'wallpaper', wallpaperId: '$B'}, screen: '$screen', revert: true}).then(r => r.id)" | tr -d '"')
  106. sleep 8
  107. [ "$(assigned)" = $A ] && pass "app rule: nothing changes while the program is not running" || fail "app rule fired without the program: $(assigned)"
  108. sshv ". ~/sessenv; (${WEM_LAUNCH:-} setsid nohup /tmp/lwe-ruletest 3000 >/dev/null 2>&1 &); sleep 2"
  109. if wait_assigned $B 45; then
  110. pass "app rule: starting the program shows the rule's wallpaper"
  111. [[ $(cdp 'window.electronAPI.appRules.active()') == *"$arule"* ]] && pass "app rule: it is listed as active" || fail "app rule not listed as active"
  112. else
  113. fail "app rule: program running, screen shows $(assigned)"
  114. fi
  115. sshv 'pkill -x lwe-ruletest; true'
  116. if wait_assigned $A 45; then pass "app rule: the previous wallpaper comes back when the program ends"; else fail "app rule did not revert, screen shows $(assigned)"; fi
  117. cdp "window.electronAPI.appRules.delete('$arule')" >/dev/null
  118. if [ "$(cdp 'window.electronAPI.appRules.audioAvailable()')" = true ] && sshv 'command -v paplay >/dev/null && pactl info >/dev/null 2>&1'; then
  119. sshv "python3 -c \"
  120. import wave
  121. w = wave.open('/tmp/lwe-features-silence.wav', 'w'); w.setnchannels(2); w.setsampwidth(2); w.setframerate(44100)
  122. w.writeframes(b'\0' * 44100 * 4 * 60); w.close()\""
  123. apply $A
  124. srule=$(cdp "window.electronAPI.appRules.save({name: 'wem-audio', enabled: true, condition: {type: 'audio'}, action: {type: 'wallpaper', wallpaperId: '$B'}, screen: '$screen', revert: true}).then(r => r.id)" | tr -d '"')
  125. sleep 8
  126. sshv ". ~/sessenv; (${WEM_LAUNCH:-} setsid nohup paplay /tmp/lwe-features-silence.wav >/dev/null 2>&1 &); sleep 2"
  127. wait_assigned $B 45 && pass "app rule: another app's sound shows the rule's wallpaper" || fail "audio rule: sound playing, screen shows $(assigned)"
  128. sshv 'pkill -x paplay; true'
  129. wait_assigned $A 60 && pass "app rule: back to the previous wallpaper after the sound stops" || fail "audio rule did not revert: $(assigned)"
  130. cdp "window.electronAPI.appRules.delete('$srule')" >/dev/null
  131. else
  132. skip "app rule on sound: no pulse tools or server in this guest"
  133. fi
  134. # split screen (per-screen display mode)
  135. cdp "window.electronAPI.wallpaper.setSplit('$screen', {layout: 'equal', slots: [{wallpaperId: '$A'}, {wallpaperId: '$B'}]})" >/dev/null
  136. cdp "window.electronAPI.wallpaper.showSplit('$screen')" >/dev/null
  137. sleep 20
  138. slots=$(engine_args | grep -o -- '--screen-slot' | wc -l)
  139. [ "$slots" -ge 2 ] && pass "split screen: one engine with $slots slots" || fail "split screen: $slots --screen-slot in $(engine_args | cut -c1-300)"
  140. [ "$(sshv 'pgrep -fc "/[l]inux-wallpaperengine(\.bin)? "')" -ge 1 ] && pass "split screen: the engine stays up" || fail "split screen: no engine running"
  141. apply $A
  142. [ "$(engine_args | grep -c -- '--screen-slot')" = 0 ] && pass "split screen: a normal wallpaper replaces the split" || fail "the split is still running: $(engine_args | cut -c1-300)"
  143. cdp "window.electronAPI.wallpaper.setSplit('$screen', null)" >/dev/null
  144. # playlist following the clock (daytime)
  145. now=$(sshv 'echo $((10#$(date +%H) * 60 + 10#$(date +%M)))')
  146. cdp "(async () => { const api = window.electronAPI; const p = await api.playlist.create('wem-daytime');
  147. await api.playlist.addItems(p.id, ['$A', '$B']);
  148. await api.playlist.updateSettings(p.id, {mode: 'daytime', sortBy: 'manual', randomize: false}); return p.id })()" > /dev/null
  149. plid=$(cdp "window.electronAPI.playlist.getAll().then(a => a.find(p => p.title === 'wem-daytime').id)" | tr -d '"')
  150. if [ "$now" -lt 1380 ]; then
  151. cdp "window.electronAPI.playlist.updateItem('$plid', '$A', {endMinute: $((now + 30))})" >/dev/null
  152. cdp "window.electronAPI.playlist.start('$plid', '$screen')" >/dev/null
  153. wait_assigned $A 40 && pass "daytime playlist: before the first item's end that item is shown" || fail "daytime playlist (before end): $(assigned)"
  154. fi
  155. if [ "$now" -ge 30 ]; then
  156. cdp "window.electronAPI.playlist.updateItem('$plid', '$A', {endMinute: $((now - 30))})" >/dev/null
  157. cdp "window.electronAPI.playlist.start('$plid', '$screen')" >/dev/null
  158. wait_assigned $B 40 && pass "daytime playlist: past the first item's end the next one is shown" || fail "daytime playlist (past end): $(assigned)"
  159. fi
  160. cdp "window.electronAPI.playlist.delete('$plid')" >/dev/null
  161. # copy and move between library folders
  162. sshv "rm -rf $LIBS; mkdir -p $LIB_A $LIB_B && cp -a ~/lwe/wp-$A $LIB_A/$LOCAL_A && cp -a ~/lwe/wp-$A $LIB_A/$LOCAL_B"
  163. cdp "window.electronAPI.config.setExtraLibraries([{path: '$LIB_A', name: 'feat-a'}, {path: '$LIB_B', name: 'feat-b'}])" >/dev/null
  164. cdp 'window.electronAPI.library.scan()' >/dev/null
  165. [ "$(cdp "window.electronAPI.library.getOne('$LOCAL_A').then(w => w ? w.source : 'none')" | tr -d '"')" = local ] && pass "extra library folder: its wallpapers are imported as local" || fail "extra library folder not scanned"
  166. out=$(cdp "window.electronAPI.library.transfer(['$LOCAL_A'], '$LIB_B', 'copy').then(r => r.done + ' ' + r.alreadyThere + ' ' + r.failed.length)" | tr -d '"')
  167. [ "$out" = "1 0 0" ] && sshv "test -f $LIB_B/$LOCAL_A/project.json && test -f $LIB_A/$LOCAL_A/project.json" && pass "transfer: copy leaves the original and fills the target ($out)" || fail "transfer copy: $out"
  168. out=$(cdp "window.electronAPI.library.transfer(['$LOCAL_A'], '$LIB_B', 'copy').then(r => r.done + ' ' + r.alreadyThere + ' ' + r.failed.length)" | tr -d '"')
  169. [ "$out" = "1 0 0" ] && sshv "test -f $LIB_B/$LOCAL_A/project.json" && pass "transfer: an identical folder at the target is reused ($out)" || fail "transfer copy again: $out"
  170. out=$(cdp "window.electronAPI.library.transfer(['$LOCAL_B'], '$LIB_B', 'move').then(r => r.done + ' ' + r.alreadyThere + ' ' + r.failed.length)" | tr -d '"')
  171. if [ "$out" = "1 0 0" ] && sshv "test -f $LIB_B/$LOCAL_B/project.json && ! test -e $LIB_A/$LOCAL_B"; then pass "transfer: move removes the original ($out)"; else fail "transfer move: $out"; fi
  172. out=$(cdp "window.electronAPI.library.transfer(['$LOCAL_B'], '$LIB_B', 'copy').then(r => r.done + ' ' + r.alreadyThere + ' ' + r.failed.length)" | tr -d '"')
  173. [ "$out" = "0 1 0" ] && pass "transfer: a wallpaper already in that library is left alone ($out)" || fail "transfer into its own library: $out"
  174. # custom thumbnails (engine screenshot of the wallpaper)
  175. meta=$(cdp "window.electronAPI.wallpaper.generateThumbnail('$LOCAL_A').then(w => w.customPreview || 'none')" | tr -d '"')
  176. if [ -n "$meta" ] && [ "$meta" != none ] && [[ $meta != *Error* ]] && sshv "test -s '$meta'"; then
  177. pass "thumbnail: captured to $(basename "$meta")"
  178. meta=$(cdp "window.electronAPI.wallpaper.deleteThumbnail('$LOCAL_A').then(w => w.customPreview || 'none')" | tr -d '"')
  179. [ "$meta" = none ] && pass "thumbnail: deleting it restores the original preview" || fail "thumbnail still set after delete: $meta"
  180. else
  181. fail "thumbnail capture: $meta"
  182. fi
  183. # audio inputs and the graphics notice answer
  184. out=$(cdp "window.electronAPI.lwe.listAudioInputs().then(a => Array.isArray(a) ? 'list ' + a.length : 'bad')" | tr -d '"')
  185. [[ $out == list* ]] && pass "audio input devices are listed ($out)" || fail "audio input list: $out"
  186. out=$(cdp "window.electronAPI.graphics.warning().then(w => w ? w.kind : 'none')" | tr -d '"')
  187. case $out in
  188. none|software|flatpak-nvidia) pass "graphics notice: $out" ;;
  189. *) fail "graphics notice answered: $out" ;;
  190. esac
  191. skip "Verify files, Repair and backup of workshop items need a Steam client in the guest"
  192. cleanup
  193. exit $status