* 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>
100 lines
2.6 KiB
Bash
Executable File
100 lines
2.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# omarchy:summary=Save incoming Taildrop files and announce them
|
|
# omarchy:args=[--once] [directory]
|
|
# omarchy:examples=omarchy tailscale receive | omarchy tailscale receive --once ~/Desktop
|
|
|
|
set -euo pipefail
|
|
|
|
once=false
|
|
if [[ ${1:-} == "--once" ]]; then
|
|
once=true
|
|
shift
|
|
fi
|
|
|
|
dir="${1:-${XDG_DOWNLOAD_DIR:-$HOME/Downloads}}"
|
|
|
|
# Taildrop lands in a staging directory next door rather than straight in the
|
|
# downloads directory: waiting for a delivery can take hours, and everything
|
|
# else that shows up meanwhile is somebody else's file. Same filesystem, so
|
|
# handing the finished file over is a rename.
|
|
staging="$dir/.omarchy-taildrop"
|
|
mkdir -p "$staging"
|
|
|
|
# Take the name by linking to it rather than by looking and then renaming.
|
|
# link(2) refuses an existing name, so nothing can land on the chosen one in
|
|
# the gap between the two. Staging shares the filesystem with the downloads
|
|
# directory, so the link always resolves and unlinking the staged name
|
|
# finishes the move. Prints the name it took.
|
|
claim_path() {
|
|
local staged="$1" name="${staged##*/}" base ext candidate index=0
|
|
|
|
base="${name%.*}"
|
|
ext="${name#"$base"}"
|
|
[[ -z $base ]] && { base="$name"; ext=""; }
|
|
|
|
while (( index < 1000 )); do
|
|
if (( index == 0 )); then
|
|
candidate="$dir/$name"
|
|
else
|
|
candidate="$dir/$base-$index$ext"
|
|
fi
|
|
|
|
if ln -- "$staged" "$candidate" 2>/dev/null; then
|
|
rm -f -- "$staged"
|
|
printf '%s\n' "$candidate"
|
|
return 0
|
|
fi
|
|
|
|
# Only a taken name is worth another spin. Anything else failed the link
|
|
# itself, and the file keeps its place in staging for the next run.
|
|
[[ -e $candidate ]] || return 1
|
|
|
|
((index++))
|
|
done
|
|
|
|
return 1
|
|
}
|
|
|
|
announce() {
|
|
local path="$1"
|
|
local name="${path##*/}"
|
|
local args=("Received $name" "Saved to ${dir/#$HOME/~}")
|
|
|
|
case "${name,,}" in
|
|
*.png | *.jpg | *.jpeg | *.gif | *.webp | *.avif | *.bmp | *.tif | *.tiff)
|
|
args+=(--image "$path")
|
|
;;
|
|
*)
|
|
args+=(-g )
|
|
;;
|
|
esac
|
|
|
|
# Announcing is best-effort: the file is already delivered, and under `set -e`
|
|
# a notification outage would otherwise kill the long-running receiver.
|
|
omarchy-notification-send "${args[@]}" --exec "$(printf 'xdg-open %q' "$path")" || true
|
|
}
|
|
|
|
deliver() {
|
|
local staged target
|
|
|
|
while IFS= read -r staged; do
|
|
target=$(claim_path "$staged") || continue
|
|
announce "$target"
|
|
done < <(find "$staging" -mindepth 1 -maxdepth 1)
|
|
}
|
|
|
|
# Anything left staged by an interrupted run still deserves delivering.
|
|
deliver
|
|
|
|
while true; do
|
|
if ! tailscale file get --wait --conflict=rename "$staging"; then
|
|
$once && exit 1
|
|
sleep 10
|
|
continue
|
|
fi
|
|
|
|
deliver
|
|
$once && exit 0
|
|
done
|