Start flrig at login after radio configure --flrig

--flrig adds an autostart entry, ~/.config/autostart/hampack-flrig.desktop,
so flrig is running before the programs that reach the radio through
rigctld and it. If an autostart entry of yours already runs flrig, none
is added: two flrigs would fight over the port. Running it without
--flrig removes the entry, since flrig would take the port from rigctld
at login, and so does hampackremove. Both remove it only if it carries
HamPack's mark (X-HamPack).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David Young
2026-11-28 13:43:34 -07:00
co-authored by Claude Opus 5.5
parent 53e748ccb9
commit 357f72583e
7 changed files with 115 additions and 12 deletions
+58 -3
View File
@@ -36,6 +36,8 @@ QLOG_DB="$HOME/.var/app/$QLOG_FLATPAK/data/hamradio/QLog/qlog.db"
POTACAT_DIR="$CONFIG_HOME/potacat"
GRAYWOLF_DB="$HOME/.local/share/graywolf/graywolf.db"
FLRIG_DIR="$HOME/.flrig"
AUTOSTART_DIR="$CONFIG_HOME/autostart"
FLRIG_AUTOSTART="$AUTOSTART_DIR/hampack-flrig.desktop"
# flrig's baud rates; it saves the rate as its place in this list
FLRIG_BAUDS=(300 600 1200 2400 4800 9600 19200 38400 57600 115200 230400 460800)
DIREWOLF_CONF="$HAMPACK_STATE/conf.d/direwolf.conf"
@@ -633,6 +635,43 @@ fltk_set() {
' "$1" > "$tmp" && chmod --reference="$1" "$tmp" && mv -f "$tmp" "$1"
}
# Print the autostart entries, other than HamPack's, that start flrig when
# you log in
other_flrig_autostarts() {
local entry exec
for entry in "$AUTOSTART_DIR"/*.desktop; do
[ -f "$entry" ] && [ "$entry" != "$FLRIG_AUTOSTART" ] || continue
grep -qix 'Hidden=true' "$entry" && continue
exec="$(sed -n 's/^Exec=//p' "$entry" | head -1)"
exec="${exec%% *}"
[ "${exec##*/}" = flrig ] && echo "$entry"
done
return 0
}
# Start flrig when you log in, so rigctld has it to talk to: an autostart
# entry, marked as HamPack's so it's only ever removed by HamPack
add_flrig_autostart() {
mkdir -p "$AUTOSTART_DIR" && cat > "$FLRIG_AUTOSTART" << 'EOF'
[Desktop Entry]
Type=Application
Name=flrig
Comment=Controls the radio, for rigctld and the programs that use it. Added by HamPack's radio configure --flrig
Exec=flrig
Icon=flrig
Terminal=false
X-GNOME-Autostart-enabled=true
X-HamPack=radio configure --flrig
EOF
}
# Remove HamPack's flrig autostart entry, if that's what it is. Prints
# whether it removed one
remove_flrig_autostart() {
[ -f "$FLRIG_AUTOSTART" ] && grep -qx 'X-HamPack=radio configure --flrig' "$FLRIG_AUTOSTART" || return 1
rm -f "$FLRIG_AUTOSTART"
}
# flrig can't reach a radio through rigctld, and the two can't both have its
# port open. With --flrig, flrig gets the radio, its port, baud rate and PTT
# by CAT, and rigctld (Hamlib's FLRig backend) passes everything to it;
@@ -644,9 +683,24 @@ configure_flrig() {
return
fi
if (( ! USE_FLRIG )); then
report flrig "not set up: it and rigctld can't both use the radio's port. \`radio configure --flrig\` puts flrig in charge of the radio, with rigctld passing the other programs through it"
if remove_flrig_autostart; then
report flrig "no longer starts when you log in, since rigctld has the radio's port again. \`radio configure --flrig\` puts flrig back in charge"
else
report flrig "not set up: it and rigctld can't both use the radio's port. \`radio configure --flrig\` puts flrig in charge of the radio, with rigctld passing the other programs through it"
fi
return
fi
local autostart="" others
others="$(other_flrig_autostarts)"
if [ -n "$others" ]; then
autostart=" It starts when you log in, from ${others##*/}"
elif [ -f "$FLRIG_AUTOSTART" ]; then
autostart=" It starts when you log in"
elif add_flrig_autostart; then
autostart=" It now starts when you log in; start it yourself this time"
else
autostart=" Couldn't add it to $AUTOSTART_DIR, so start it before the other programs"
fi
for i in "${!FLRIG_BAUDS[@]}"; do
[ "${FLRIG_BAUDS[i]}" = "$3" ] && index="$i"
done
@@ -655,11 +709,12 @@ configure_flrig() {
SAID=() LEFT=()
if [ "$current_name" = "$1" ] && [ "$current_port" = "$2" ] && [ "$(fltk_get "$rig" serial_baudrate)" = "$index" ] &&
[ "$(fltk_get "$rig" ptt_via_cat)" = 1 ]; then
report flrig "already set up. Start it before the other programs, and leave it running"
report flrig "already set up.$autostart, and leave it running"
return
fi
if (( ! FORCE )) && { [[ ! "$current_name" =~ ^(|NONE|$1)$ ]] || [[ ! "$current_port" =~ ^(|NONE)$ && "$current_port" != "$2" ]]; }; then
[[ "$current_name" =~ ^(|NONE|$1)$ ]] && LEFT+=("its port ($current_port)") || LEFT+=("its radio ($current_name)")
SAID+=("${autostart# }")
say_changes flrig
return
fi
@@ -674,7 +729,7 @@ configure_flrig() {
report flrig "couldn't change its settings in $FLRIG_DIR"
return 1
fi
report flrig "controls the $1 on $2 at $3 baud, PTT by CAT. Start it before the other programs, and leave it running"
report flrig "controls the $1 on $2 at $3 baud, PTT by CAT.$autostart, and leave it running"
}
# Pat: add rigctld to its rigs as "hampack", and use it for ARDOP and VARA