aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-09 18:26:01 +0100
committerDanilo M. <danix@danix.xyz>2026-11-09 18:26:01 +0100
commit47421647d7d08919d28660a2b2201e0d1d704c18 (patch)
tree1ae98292e933d1e2697b4e057779b0e88c1ff97f
parent46a164e797c0fd77ee67e2bae9bec5c02ad1de2d (diff)
downloaddeck-it-47421647d7d08919d28660a2b2201e0d1d704c18.tar.gz
deck-it-47421647d7d08919d28660a2b2201e0d1d704c18.zip
fix: user-space autostart watch-usb
-rwxr-xr-xdeck-it52
1 files changed, 27 insertions, 25 deletions
diff --git a/deck-it b/deck-it
index a74fcdb..1463b5e 100755
--- a/deck-it
+++ b/deck-it
@@ -4,15 +4,15 @@
# deck-it env print MON/PORT/VNC_PORT for this config
# deck-it pair pair the tablet for Wi-Fi by scanning a QR code
# deck-it wifi start over Wi-Fi
-# deck-it install start automatically when this tablet is plugged in (asks for sudo)
-# deck-it uninstall remove the automatic start
+# deck-it install print the exec-once line for hypr-theme's autostart
+# deck-it uninstall forget the generated trigger
+# deck-it watch-usb start on plug-in, tear down on unplug (run from exec-once)
set -u
DIR="$(dirname "$(readlink -f "$0")")"
SELF="$DIR/deck-it"
CONF="${XDG_CONFIG_HOME:-$HOME/.config}/deck-it"
VNC="$CONF/vnc"
RUN="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/deck-it"
-RULE=/etc/udev/rules.d/70-deck-it.rules
if [[ "${1:-}" == "env" ]]; then
(cd "$DIR" && exec python3 -m deckit env)
@@ -74,24 +74,6 @@ usb_present() {
[[ "$(timeout 3 adb -d get-state 2>/dev/null)" == device ]]
}
-# udev RUN= cannot carry a quoted shell command, so the rule calls a generated
-# no-argument script that backgrounds the launcher and returns immediately.
-install_udev() {
- serial=$(timeout 5 adb -d get-serialno 2>/dev/null)
- [[ "$serial" =~ ^[A-Za-z0-9]+$ ]] || { echo "Plug in the tablet with USB debugging allowed, then retry"; exit 1; }
- mkdir -p "$CONF"
- trigger="$CONF/trigger"
- printf '#!/bin/sh\nsetsid "%s" start >/dev/null 2>&1 &\n' "$SELF" > "$trigger"
- chmod 0755 "$trigger"
- printf 'ACTION!="remove", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTR{serial}=="%s", RUN+="%s"\n' \
- "$serial" "$trigger" | sudo tee "$RULE" >/dev/null || exit 1
- sudo udevadm control --reload
- echo "Installed for tablet $serial. It starts when plugged in and stops when removed."
- echo "To also start at login when the tablet is already connected, add to hypr-theme's autostart:"
- echo " exec-once = $SELF"
- exit 0
-}
-
case "${1:-}" in
stop)
teardown
@@ -135,14 +117,34 @@ watch)
done
;;
install)
- install_udev
+ echo "Add this line to hypr-theme's autostart so the tablet is picked up at login and when plugged in:"
+ echo " exec-once = $SELF watch-usb"
+ echo "On a new tablet, run 'deck-it' once by hand to accept the USB debugging prompt."
+ exit 0
;;
uninstall)
- if [[ -f "$RULE" ]]; then sudo rm -f "$RULE" && sudo udevadm control --reload; fi
rm -f "$CONF/trigger"
- echo "Uninstalled"
+ echo "Remove the 'exec-once = $SELF watch-usb' line from hypr-theme's autostart."
exit 0
;;
+setup-display)
+ (cd "$DIR" && exec python3 -m deckit setup-display)
+ ;;
+watch-usb)
+ # A user-space watcher, so it can reach the session: udev RUN= cannot.
+ # Start on plug-in, tear down on unplug.
+ known=""
+ while sleep 5; do
+ now=$(timeout 4 adb -d get-serialno 2>/dev/null)
+ if [[ -n "$now" && "$now" != "$known" ]]; then
+ "$SELF" start >/dev/null 2>&1 &
+ known=$now
+ elif [[ -z "$now" && -n "$known" ]]; then
+ teardown
+ known=""
+ fi
+ done
+ ;;
wifi)
echo "Looking for the tablet on Wi-Fi..."
while :; do
@@ -158,7 +160,7 @@ wifi)
ANDROID_SERIAL=$(adb -d get-serialno)
;;
*)
- sed -n '2,8p' "$SELF" | sed 's/^# \{0,1\}//'
+ sed -n '2,9p' "$SELF" | sed 's/^# \{0,1\}//'
exit 1
;;
esac