diff --git a/install/user/first-run/install-voxtype.hook b/install/user/first-run/install-voxtype.hook index 1f4f30d7..63d025a0 100644 --- a/install/user/first-run/install-voxtype.hook +++ b/install/user/first-run/install-voxtype.hook @@ -2,10 +2,17 @@ set -e -if omarchy-done ensure voxtype-install-invitation; then - ( - if [[ -n $(omarchy-notification-send -u critical -g  "Install Dictation with Voxtype" "Click to install voice dictation for Omarchy." -a) ]]; then - omarchy-launch-floating-terminal-with-presentation omarchy-voxtype-install - fi - ) >/dev/null 2>&1 & +show_invitation() { + if [[ -n $(omarchy-notification-send -u critical -g  "Install Dictation with Voxtype" "Click to install voice dictation for Omarchy." -a) ]]; then + omarchy-launch-floating-terminal-with-presentation omarchy-voxtype-install + fi +} + +if [[ ${1:-} == "--show" ]]; then + show_invitation +elif omarchy-done ensure voxtype-install-invitation; then + # Keep the notification action alive after the update terminal closes. + systemd-run --user --collect --quiet --service-type=exec \ + --unit=omarchy-voxtype-install-invitation \ + bash "$0" --show fi diff --git a/test/shell.d/voxtype-invitation-test.sh b/test/shell.d/voxtype-invitation-test.sh index 9f5954f8..827e4638 100644 --- a/test/shell.d/voxtype-invitation-test.sh +++ b/test/shell.d/voxtype-invitation-test.sh @@ -28,6 +28,17 @@ echo launch >>"$TEST_LOG" EOF chmod +x "$test_bin/omarchy-launch-floating-terminal-with-presentation" +cat >"$test_bin/systemd-run" <<'EOF' +#!/bin/bash +echo "systemd-run:$*" >>"$TEST_LOG" +while (($# > 0)); do + [[ $1 == "bash" ]] && exec "$@" + shift +done +exit 1 +EOF +chmod +x "$test_bin/systemd-run" + run_invitation_hook() { cp "$ROOT/install/user/first-run/install-voxtype.hook" "$hook_path" HOME="$test_home" PATH="$test_bin:$ROOT/bin:$PATH" TEST_LOG="$log_file" bash "$hook_path" @@ -35,20 +46,17 @@ run_invitation_hook() { run_invitation_hook -for _ in {1..50}; do - [[ $(wc -l <"$log_file") -eq 2 ]] && break - sleep 0.02 -done - [[ -f $test_home/.local/state/omarchy/done/voxtype-install-invitation ]] || fail "Voxtype invitation records completion" [[ -f $hook_path ]] || fail "Voxtype invitation keeps its hook installed" +[[ $(grep -c '^systemd-run:' "$log_file") -eq 1 ]] || fail "Voxtype invitation uses a durable user service" +grep -q -- '--user --collect --quiet --service-type=exec --unit=omarchy-voxtype-install-invitation' "$log_file" || fail "Voxtype invitation configures its user service" [[ $(grep -c '^notification$' "$log_file") -eq 1 ]] || fail "Voxtype invitation sends one notification" [[ $(grep -c '^launch$' "$log_file") -eq 1 ]] || fail "Voxtype invitation handles the notification action" HOME="$test_home" PATH="$test_bin:$ROOT/bin:$PATH" TEST_LOG="$log_file" bash "$hook_path" -sleep 0.05 [[ -f $hook_path ]] || fail "completed Voxtype invitation keeps its hook installed" +[[ $(grep -c '^systemd-run:' "$log_file") -eq 1 ]] || fail "completed Voxtype invitation does not schedule again" [[ $(grep -c '^notification$' "$log_file") -eq 1 ]] || fail "completed Voxtype invitation hook does not notify again" [[ $(grep -c '^launch$' "$log_file") -eq 1 ]] || fail "completed Voxtype invitation hook does not launch again"