Send and receive files with Taildrop (#6375)
* Send files to a tailnet machine with Taildrop The panel gets a send button next to the copy one on every machine that Tailscale grades as a Taildrop target, and `s` does the same from the keyboard. Picking runs through the XDG portal chooser, so it looks like the file dialog every other app opens. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TJQJfHXXApUk6En8EZisHg * Save incoming Taildrop files and say so Linux keeps Taildrop files in the daemon's inbox until someone asks for them, so nothing arrived until you ran `tailscale file get` by hand. A user service now stages each delivery next to the downloads directory, hands it over under a free name, and announces it — with a preview when it's an image, and a click to open it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TJQJfHXXApUk6En8EZisHg * Float every portal dialog, not just the titled ones The portal only ever shows dialogs, and the title regex missed any chooser an app names something else — ours included. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TJQJfHXXApUk6En8EZisHg * Re-run the Taildrop enable now that the unit ships The unit was never installed to /usr/lib/systemd/user/, so the enable had nothing to act on and machines that already ran the migration carry a marker for a no-op. Rename it so they get a working pass, and report what systemctl says instead of a bare failure line. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Wait for the file chooser on the connection that asked for it The portal answers a request with a Response signal directed at the connection that made it, and dbus-daemon delivers directed signals only to that connection. gdbus monitor registers with AddMatch rather than BecomeMonitor, so it never saw the reply: every pick left omarchy-file-select blocked on a read that could not arrive, taking omarchy-tailscale-send down with it before it reached either its notification or the transfer. Make the call and wait for the signal on one connection, and give up after ten minutes so an unanswered dialog cannot strand the caller. Drop the "Sending to" notification while here, so a send reports once. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Mark Taildrop notifications with the panel's send glyph Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Stop a hung tailscale poll from freezing the panel Each poll is skipped while its own process is still running, so one that never exits leaves the panel showing whatever it last read, for good: the peer list keeps a woken machine missing, and opening the panel cannot help because open runs the same refresh that hits the same guard. Reap anything still running fifteen seconds after a refresh, well inside the thirty second interval, so the next tick starts clean. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Place a moved widget where an added one lands 'move omarchy.media left' named a section, not a slot, but the section went through as an explicit target, which resolves a missing index by appending. The widget landed on the far end of the row instead of after the section anchor where 'add' puts it. Its test has never run: the assertion covering this went in four hours after an unrelated layout change had already stopped the file, and the runner stops the whole suite at the first failure. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Keep the config test from failing on things it is not about The center layout assertion pinned the whole row, so parking the indicators left of the clock broke a test named for update sitting next to weather. Assert that adjacency instead. The package-defaults check reads PKGBUILDs from the omarchy-pkgs repo and blew up with a traceback wherever that is not a sibling checkout. Skip it when the checkout is absent, honour OMARCHY_PKGS_ROOT when it is somewhere else, and keep failing when it is present and wrong. Between them these stopped the suite eighty files early. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Make the file chooser a Python command rather than a bash host for one The portal work was a heredoc wedged inside a bash script that existed only to parse two flags. Drop the host: argparse covers the flags, and the file says at the top why it is the one command here not written in bash. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Tell a chooser that never opened apart from one that was dismissed Three fixes from review: The poll watchdog rearmed on every refresh, so a refresh interval shorter than its timeout — the setting goes down to five seconds — pushed the deadline ahead of a hung process forever. Arm it on the launch that needs watching and leave it alone. omarchy-file-select exited 1 both for nothing picked and for a chooser that could not run, and omarchy-tailscale-send read it through a process substitution, which drops the status anyway. A session bus that was not there looked exactly like someone changing their mind. Separate the two exits and read them with a command substitution. Delivery picked a free name and then renamed, which overwrites anything that takes the name in between. Link to the name instead: link(2) refuses one that is taken, so the check and the claim are the same step. 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:
co-authored by
Claude Opus 5
parent
6465513534
commit
e57f3b286c
@@ -45,6 +45,7 @@ GROUP_DESCRIPTIONS[dev]="Omarchy development tools"
|
||||
GROUP_DESCRIPTIONS[display]="Display and text scaling"
|
||||
GROUP_DESCRIPTIONS[dns]="DNS resolver configuration"
|
||||
GROUP_DESCRIPTIONS[drive]="Drive selection and encryption"
|
||||
GROUP_DESCRIPTIONS[file]="File selection helpers"
|
||||
GROUP_DESCRIPTIONS[font]="Font management"
|
||||
GROUP_DESCRIPTIONS[games]="Game launchers and helpers"
|
||||
GROUP_DESCRIPTIONS[hibernation]="Hibernation setup and removal"
|
||||
@@ -78,6 +79,7 @@ GROUP_DESCRIPTIONS[snapshot]="System snapshots"
|
||||
GROUP_DESCRIPTIONS[style]="Global UI style controls"
|
||||
GROUP_DESCRIPTIONS[sudo]="Sudo configuration helpers"
|
||||
GROUP_DESCRIPTIONS[system]="System status, reboot, shutdown, logout, and lock"
|
||||
GROUP_DESCRIPTIONS[tailscale]="Tailscale helpers"
|
||||
GROUP_DESCRIPTIONS[theme]="Theme management"
|
||||
GROUP_DESCRIPTIONS[tmux]="Tmux session helpers"
|
||||
GROUP_DESCRIPTIONS[toggle]="Toggle Omarchy features"
|
||||
|
||||
+10
-1
@@ -288,6 +288,15 @@ cmd_move() {
|
||||
fi
|
||||
|
||||
local default_section="${PLACEMENT_SECTION:-}"
|
||||
|
||||
# A bare section names the section, not the slot, so let it fall through to
|
||||
# the same anchor placement 'add' uses. Passing it as an explicit target
|
||||
# instead drops the widget on the far end of the row.
|
||||
local target_section="$PLACEMENT_SECTION"
|
||||
if [[ -z $PLACEMENT_INDEX && -z $PLACEMENT_BEFORE && -z $PLACEMENT_AFTER ]]; then
|
||||
target_section=""
|
||||
fi
|
||||
|
||||
local prog
|
||||
prog=$(cat <<JQ
|
||||
$JQ_DEFS $NORMALIZE
|
||||
@@ -302,7 +311,7 @@ JQ
|
||||
commit "$prog" \
|
||||
--arg id "$id" \
|
||||
--arg defaultSection "$default_section" \
|
||||
--arg targetSection "$PLACEMENT_SECTION" \
|
||||
--arg targetSection "$target_section" \
|
||||
--arg targetIndex "$PLACEMENT_INDEX" \
|
||||
--arg before "$PLACEMENT_BEFORE" \
|
||||
--arg after "$PLACEMENT_AFTER" \
|
||||
|
||||
Executable
+107
@@ -0,0 +1,107 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
# omarchy:summary=Pick files with the desktop file chooser
|
||||
# omarchy:args=[--title <title>] [--multiple]
|
||||
# omarchy:examples=omarchy file select --title "Send with Tailscale" --multiple
|
||||
|
||||
# Python rather than bash, alone among the commands here, because the portal
|
||||
# answers a request with a Response signal addressed to the connection that
|
||||
# asked, and D-Bus delivers a directed signal only to that connection. Every
|
||||
# shell-callable client — gdbus call, busctl call, dbus-send — opens its own
|
||||
# connection and exits before the answer arrives, and gdbus monitor registers
|
||||
# with AddMatch rather than BecomeMonitor, so it never sees one either. Holding
|
||||
# a single connection across both the call and the wait is the whole job, and
|
||||
# bash has no way to hold one.
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
import gi
|
||||
|
||||
gi.require_version("Gio", "2.0")
|
||||
from gi.repository import Gio, GLib
|
||||
|
||||
# A dialog nobody ever answers would otherwise keep this process, and whatever
|
||||
# waits on its output, alive forever.
|
||||
ANSWER_TIMEOUT_SEC = 600
|
||||
|
||||
# Callers act on these: nothing picked is a decision, a chooser that never ran
|
||||
# is a fault, and the two want different handling.
|
||||
EXIT_NOTHING_PICKED = 1
|
||||
EXIT_CHOOSER_FAILED = 2
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(add_help=False)
|
||||
parser.add_argument("--title", default="Select file")
|
||||
parser.add_argument("--multiple", action="store_true")
|
||||
args, unknown = parser.parse_known_args()
|
||||
|
||||
if unknown:
|
||||
print("omarchy-file-select: unknown option %s" % unknown[0], file=sys.stderr)
|
||||
return EXIT_CHOOSER_FAILED
|
||||
|
||||
bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
|
||||
loop = GLib.MainLoop()
|
||||
uris = []
|
||||
|
||||
def on_response(connection, sender, path, interface, signal, params):
|
||||
code, results = params.unpack()
|
||||
if code == 0:
|
||||
uris.extend(results.get("uris", []))
|
||||
loop.quit()
|
||||
|
||||
def subscribe(path):
|
||||
bus.signal_subscribe(
|
||||
"org.freedesktop.portal.Desktop",
|
||||
"org.freedesktop.portal.Request",
|
||||
"Response",
|
||||
path,
|
||||
None,
|
||||
Gio.DBusSignalFlags.NONE,
|
||||
on_response,
|
||||
)
|
||||
|
||||
# The request path is derived from our bus name and the token we pass, so it
|
||||
# can be subscribed to up front. Asking first would race a dialog that gets
|
||||
# answered immediately.
|
||||
token = "omarchy%d" % os.getpid()
|
||||
sender = bus.get_unique_name()[1:].replace(".", "_")
|
||||
predicted = "/org/freedesktop/portal/desktop/request/%s/%s" % (sender, token)
|
||||
subscribe(predicted)
|
||||
|
||||
handle = bus.call_sync(
|
||||
"org.freedesktop.portal.Desktop",
|
||||
"/org/freedesktop/portal/desktop",
|
||||
"org.freedesktop.portal.FileChooser",
|
||||
"OpenFile",
|
||||
GLib.Variant("(ssa{sv})", ("", args.title, {
|
||||
"handle_token": GLib.Variant("s", token),
|
||||
"multiple": GLib.Variant("b", args.multiple),
|
||||
})),
|
||||
None,
|
||||
Gio.DBusCallFlags.NONE,
|
||||
-1,
|
||||
None,
|
||||
).unpack()[0]
|
||||
|
||||
# Portals predating the token convention answer on a path of their choosing.
|
||||
if handle != predicted:
|
||||
subscribe(handle)
|
||||
|
||||
GLib.timeout_add_seconds(ANSWER_TIMEOUT_SEC, loop.quit)
|
||||
loop.run()
|
||||
|
||||
for uri in uris:
|
||||
print(GLib.filename_from_uri(uri)[0])
|
||||
|
||||
return 0 if uris else EXIT_NOTHING_PICKED
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
sys.exit(main())
|
||||
except GLib.Error as error:
|
||||
print("omarchy-file-select: %s" % error.message, file=sys.stderr)
|
||||
sys.exit(EXIT_CHOOSER_FAILED)
|
||||
@@ -13,6 +13,9 @@ sudo tailscale up --accept-routes
|
||||
echo -e "\nAllowing $USER to manage Tailscale..."
|
||||
sudo tailscale set --operator="$USER"
|
||||
|
||||
echo -e "\nReceiving Taildrop files in $HOME/Downloads..."
|
||||
systemctl --user enable --now omarchy-tailscale-receive.service
|
||||
|
||||
echo -e "\nAdding Tailscale to the bar..."
|
||||
omarchy-bar-plugin add omarchy.tailscale
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
# omarchy:requires-sudo=true
|
||||
|
||||
tailscale down 2>/dev/null || true
|
||||
systemctl --user disable --now omarchy-tailscale-receive.service 2>/dev/null || true
|
||||
sudo systemctl disable --now tailscaled.service 2>/dev/null || true
|
||||
omarchy-bar-plugin remove omarchy.tailscale
|
||||
omarchy-webapp-remove "Tailscale" 2>/dev/null || true
|
||||
|
||||
Executable
+101
@@ -0,0 +1,101 @@
|
||||
#!/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
|
||||
|
||||
# Clicking the notification opens the file, so this waits for the toast to
|
||||
# go away. Callers background it to keep receiving in the meantime.
|
||||
if [[ -n $(omarchy-notification-send "${args[@]}" -a) ]]; then
|
||||
xdg-open "$path"
|
||||
fi
|
||||
}
|
||||
|
||||
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
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
#!/bin/bash
|
||||
|
||||
# omarchy:summary=Send files to a machine on your tailnet with Taildrop
|
||||
# omarchy:args=<machine> [file...]
|
||||
# omarchy:examples=omarchy tailscale send dhh-fd | omarchy tailscale send dhh-fd ~/Downloads/notes.pdf
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if (($# < 1)); then
|
||||
echo "Usage: omarchy-tailscale-send <machine> [file...]" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
machine="$1"
|
||||
shift
|
||||
|
||||
# Address the machine by whatever name we were handed, but talk about it by
|
||||
# its short name, so a MagicDNS name does not spill into every message.
|
||||
name="${machine%%.*}"
|
||||
|
||||
files=("$@")
|
||||
|
||||
if ((${#files[@]} == 0)); then
|
||||
# Command substitution so the chooser's exit status survives: reading it
|
||||
# through a process substitution reports success for a chooser that never
|
||||
# opened, which is indistinguishable here from someone deciding not to send.
|
||||
picked=$(omarchy-file-select --title "Send to $name" --multiple) || status=$?
|
||||
|
||||
if ((${status:-0} > 1)); then
|
||||
omarchy-notification-send -g "" -u critical "Could not send to $name" \
|
||||
"The file chooser did not open"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
readarray -t files <<<"$picked"
|
||||
[[ -n $picked ]] || exit 0
|
||||
fi
|
||||
|
||||
if ((${#files[@]} == 1)); then
|
||||
what=$(basename "${files[0]}")
|
||||
else
|
||||
what="${#files[@]} files"
|
||||
fi
|
||||
|
||||
if error=$(tailscale file cp --update-interval=0 -- "${files[@]}" "$machine:" 2>&1); then
|
||||
omarchy-notification-send -g "" "Sent to $name" "$what"
|
||||
else
|
||||
omarchy-notification-send -g "" -u critical "Could not send to $name" "${error:-Taildrop transfer failed}"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user