#!/bin/bash # desktop-assistant: start, stop, restart or check the voice loop. # Copyright (C) 2026 Danilo M. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License version 2 as published # by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # assistant.sh start|stop|restart|status # # stop: SIGTERM any running assistant.py (whisper-server and amixer die # with it through PDEATHSIG), SIGKILL after 10 s; same for the quickshell # overlay (OVERLAY, default the quickshell repo next to this one). # start: run both in their own session, detached from the terminal, # logging where the Hyprland autostart does; does nothing for one already # running. restart: stop, then start. status: processes, children, stray # recorders, socket, pause flags and the log's tail; exit 1 if either is # down. Run it from the login session: it needs its # audio, bus, Wayland display and XDG_RUNTIME_DIR. set -eu dir=$(cd "$(dirname "$0")" && pwd) log="${XDG_RUNTIME_DIR:?not in a login session}/desktop-assistant.log" overlay=$(realpath -m "${OVERLAY:-$dir/../quickshell/assistant}") pat='^\S*python3 (-u )?\S*assistant\.py' qpat="^qs -p $overlay\$" kill_wait() { pkill -u "$USER" -f "$1" || return 0 for _ in $(seq 50); do pgrep -u "$USER" -f "$1" >/dev/null || return 0 sleep 0.2 done pkill -KILL -u "$USER" -f "$1" && sleep 0.5 || true } running() { pgrep -u "$USER" -f "$1" >/dev/null; } stop() { kill_wait "$pat" kill_wait "$qpat" } start() { cd "$dir" running "$pat" || setsid -f python3 -u "$dir/assistant.py" >>"$log" 2>&1 /dev/null 2>&1 /dev/null)" = 1 ] && echo "paused: $f mode on" done echo "log: $log" tail -n 5 "$log" 2>/dev/null | sed 's/^/ /' return $rc } case "${1:-}" in start) start ;; stop) stop ;; restart) stop; start ;; status) status ;; *) echo "usage: $0 start|stop|restart|status" >&2; exit 2 ;; esac