Keep clicking a notification working after a shell restart (#6636)

* Keep clicking a notification working after a shell restart

Notification actions lived only in the sending process: `-a` appended
`-A default=default`, so notify-send blocked on a D-Bus ActionInvoked signal and
the caller ran the command when it arrived. Nothing about that reached disk, so a
restored popup had no action to run and its sender stayed blocked forever.

Replace `-a` with `--exec <command>`, carried as an `omarchy-exec` hint into the
snapshot's `exec` role. It travels through the popup files and history, and the
shell runs it on click, so restored toasts behave exactly like live ones and the
sender exits immediately.

That drops the scaffolding whose only job was keeping a blocked sender alive: the
first-run invitations lose their `--show` re-entry and two transient units each,
omarchy-migrate-notify loses its transient service, and the screenshot,
recording, download, and taildrop toasts lose their wrapper subshells.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Keep a failed toast from failing the work it announces

Moving these sends out of their backgrounded subshells put a fallible command
on the foreground path, where the `&` used to swallow its exit status. A
notification outage — including the shell restart this branch targets — now
propagates:

- taildrop's receiver dies under `set -e` mid-delivery
- omarchy-capture-screenshot reports failure for a screenshot it already saved
- a completed download exits before scheduling its thumbnail cleanup, leaking
  the mktemp file

Announcing is best-effort in all three: the work is already done by the time
the toast goes out.

Also drop the first-run sleep that spaced out the welcome and Wi-Fi toasts.
It compensated for the background notify-send processes this branch removes;
each send now returns only once the server has taken the toast, so sending in
order is enough to stack them newest-on-top.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Stop tying the preview cleanup to the toast's expiry

The shell loads a notification thumbnail into memory when the toast appears and
never re-reads the file, so the preview only has to outlive that load. Deriving
the cleanup delay from the expiry was false precision, and it turned -t into a
variable for no reason: -t is already the helper's expiry setting.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
David Heinemeier Hansson
2026-08-09 12:30:47 +02:00
committed by GitHub
co-authored by Claude Opus 5
parent 99293aa05a
commit 5a58f79876
19 changed files with 220 additions and 226 deletions
+20 -52
View File
@@ -22,23 +22,6 @@ fi
SH
chmod +x "$stub_bin/omarchy-migrate"
cat >"$stub_bin/systemd-run" <<'SH'
#!/bin/bash
if [[ ${OMARCHY_TEST_SYSTEMD_RUN:-run} == "fail" ]]; then
exit 1
fi
command=${!#}
# --scope blocks on the command, a transient service detaches it.
if [[ " $* " == *" --scope "* ]]; then
bash -c "$command"
else
setsid bash -c "$command" >/dev/null 2>&1 &
fi
SH
chmod +x "$stub_bin/systemd-run"
# Waiting for the notification server is the notifier's one long pause, so it is
# also where an update can start underneath it. Stand one up from inside the
# wait to prove the notifier re-checks afterwards instead of sending a toast it
@@ -67,18 +50,8 @@ chmod +x "$stub_bin/omarchy-notification-wait"
cat >"$stub_bin/omarchy-notification-send" <<'SH'
#!/bin/bash
# Written whole so a reader polling for the file never sees half the arguments.
printf '%s\n' "$@" >"$OMARCHY_TEST_NOTIFY_ARGS.partial"
mv "$OMARCHY_TEST_NOTIFY_ARGS.partial" "$OMARCHY_TEST_NOTIFY_ARGS"
# Stands in for a toast nobody has answered yet, until the test releases it.
if [[ -n ${OMARCHY_TEST_NOTIFY_HOLD:-} ]]; then
for _ in {1..200}; do
[[ -e $OMARCHY_TEST_NOTIFY_HOLD ]] || break
sleep 0.05
done
: >"$OMARCHY_TEST_NOTIFY_ANSWERED"
fi
[[ ${OMARCHY_TEST_NOTIFY_SEND:-send} == "fail" ]] && exit 1
printf '%s\n' "$@" >"$OMARCHY_TEST_NOTIFY_ARGS"
SH
chmod +x "$stub_bin/omarchy-notification-send"
@@ -91,21 +64,14 @@ run_notify() {
XDG_RUNTIME_DIR="$runtime_dir" \
OMARCHY_TEST_PENDING_MIGRATIONS="$1" \
OMARCHY_TEST_NOTIFY_ARGS="$test_tmp/notify-args" \
OMARCHY_TEST_SYSTEMD_RUN="${2:-run}" \
OMARCHY_TEST_NOTIFY_SEND="${2:-send}" \
OMARCHY_TEST_LOCK_DURING_WAIT="${OMARCHY_TEST_LOCK_DURING_WAIT:-0}" \
OMARCHY_TEST_LOCK_HOLDER_PID="$test_tmp/lock-holder-pid" \
OMARCHY_TEST_NOTIFY_HOLD="${OMARCHY_TEST_NOTIFY_HOLD:-}" \
OMARCHY_TEST_NOTIFY_ANSWERED="$test_tmp/notify-answered" \
"$ROOT/bin/omarchy-migrate-notify"
}
# The notification outlives the notifier, so its arguments land after it exits.
wait_for_notify_args() {
for _ in {1..200}; do
[[ -s $test_tmp/notify-args ]] && return 0
sleep 0.05
done
return 1
notify_args_written() {
[[ -s $test_tmp/notify-args ]]
}
run_notify 0 >"$test_tmp/not-pending.out" 2>"$test_tmp/not-pending.err"
@@ -119,7 +85,7 @@ grep -q '200-migration.sh' "$test_tmp/pending.err" || fail "migration notifier l
pass "migration notifier reports pending migrations"
run_notify 1 >"$test_tmp/notified.out" 2>"$test_tmp/notified.err"
wait_for_notify_args || fail "migration notifier sends a notification for pending migrations"
notify_args_written || fail "migration notifier sends a notification for pending migrations"
grep -Fx 'Pending Omarchy Migrations' "$test_tmp/notify-args" >/dev/null || fail "migration notifier uses pending migrations title"
grep -Fx 'Click to run 1 pending migration.' "$test_tmp/notify-args" >/dev/null || fail "migration notifier describes the pending migration"
grep -Fx '' "$test_tmp/notify-args" >/dev/null || fail "migration notifier includes the large-slot glyph"
@@ -143,7 +109,7 @@ pass "migration notifier stays quiet while omarchy update holds its lock"
exec {update_lock_fd}>&-
run_notify 1 >/dev/null 2>&1
wait_for_notify_args &&
notify_args_written &&
grep -Fx 'Pending Omarchy Migrations' "$test_tmp/notify-args" >/dev/null ||
fail "migration notifier resumes notifying once the update lock is released"
pass "migration notifier resumes notifying after the update releases its lock"
@@ -172,20 +138,22 @@ exec {foreign_lock_fd}>"$foreign_lock"
flock -n "$foreign_lock_fd" || fail "test could not hold the foreign update lock"
run_notify 1 >/dev/null 2>&1
wait_for_notify_args &&
notify_args_written &&
grep -Fx 'Pending Omarchy Migrations' "$test_tmp/notify-args" >/dev/null ||
fail "migration notifier ignores update locks outside its own runtime directory"
pass "migration notifier ignores update locks outside its own runtime directory"
exec {foreign_lock_fd}>&-
# The notifier is a Type=oneshot with no start timeout, so blocking on the toast
# leaves it activating until the user answers.
rm -f "$test_tmp/notify-args" "$test_tmp/notify-answered"
: >"$test_tmp/notify-hold"
OMARCHY_TEST_NOTIFY_HOLD="$test_tmp/notify-hold" run_notify 1 >/dev/null 2>&1
wait_for_notify_args || fail "migration notifier sends the notification it detaches"
[[ ! -e $test_tmp/notify-answered ]] ||
fail "migration notifier waited for the toast to be answered before exiting"
rm -f "$test_tmp/notify-hold"
pass "migration notifier exits while the toast is still unanswered"
# The notifier is a Type=oneshot with no start timeout, so it must not stay
# activating until the toast is answered. Handing the click command to the shell
# is what lets it exit immediately -- and what keeps the toast working after the
# shell restart an update performs.
rm -f "$test_tmp/notify-args"
run_notify 1 >/dev/null 2>&1
notify_args_written || fail "migration notifier sends the notification before exiting"
grep -Fx -- '--exec' "$test_tmp/notify-args" >/dev/null ||
fail "migration notifier attaches the click command to the toast"
grep -Fx 'omarchy-launch-floating-terminal-with-presentation omarchy-migrate' "$test_tmp/notify-args" >/dev/null ||
fail "migration notifier points the click command at omarchy-migrate"
pass "migration notifier lets the shell own the click instead of waiting for it"