#!/bin/dash

# james note: 2019 - we disable this by default since
# in FD 800 we don't have a bluetooth-applet yet
# JakeSFR note: 2022 - re-enable and re-write for James' btmanager.sh

### std localisation stanza
export TEXTDOMAIN=fatdog
#. gettext.sh

MAXWAIT=20
ICON='/usr/share/pixmaps/midi-icons/bluetooth48.png'
TOOLTIP="$(gettext "Bluetooth Applet")"
EXEC='btmanager.sh'
CONFIRM='Xdialog --title "$(gettext "Confirmation")" --yesno "$(gettext "Do you really want to quit?")" 0 0'

# Show the icon only if the bluetooth service is running
# and there is actually a bluetooth device available.
if [ -x /etc/init.d/85-bluetooth ] && [ ! -z "$(hciconfig)" ]; then
	while ! pidof bluetoothd >/dev/null && [ $MAXWAIT -gt 0 ] ; do
		sleep 1
		MAXWAIT=$(( $MAXWAIT - 1))
	done
	if pidof bluetoothd >/dev/null; then
		sit "$ICON" "$TOOLTIP" "$EXEC" "{ $CONFIRM && pkill -P $$; }"
	fi
fi
