~mil/sxmo-utils

46b98c39cf6eced2d817e1de288caec1eaecacc5 — shivers 8 days ago ac6de55 master
Add ring profiles for incoming calls and texts

Signed-off-by: Stacy Harper <contact@stacyharper.net>
M configs/appcfg/profile_template => configs/appcfg/profile_template +16 -0
@@ 46,3 46,19 @@ case "$SXMO_WM" in
	dwm)
		;;
esac

#Set RINGTONE to audio file to play for incoming call
export SXMO_RINGTONE="/usr/share/sxmo/ring.ogg"

#Set TEXTSOUND to audio file to play when received text message
export SXMO_TEXTSOUND="/usr/share/sxmo/notify.ogg"

#Set RINGTIME to number of seconds the phone will ring
export SXMO_RINGTIME=20

#Set RINGNUMBER to number of times phone will ring or repeat ringtone
#(whichever of SXMO_RINGTIME or SXMO_RINGNUMBER runs less will limit how long phone rings)
export SXMO_RINGNUMER=10

# default to ring and vibrate
touch "$XDG_CONFIG_HOME"/sxmo/.ringmode

M configs/default_hooks/sxmo_hook_notification.sh => configs/default_hooks/sxmo_hook_notification.sh +13 -7
@@ 5,10 5,16 @@
# shellcheck source=scripts/core/sxmo_common.sh
. sxmo_common.sh

VIBS=5
VIBI=0
while [ $VIBI -lt $VIBS ]; do
	sxmo_vibrate 400 &
	sleep 0.5
	VIBI=$(echo $VIBI+1 | bc)
done
case "$(cat "$XDG_CONFIG_HOME"/sxmo/.ringmode)" in
	Mute|Ring)
		;;
	*) # can vibrate
		VIBS=5
		VIBI=0
		while [ $VIBI -lt $VIBS ]; do
			sxmo_vibrate 400 &
			sleep 0.5
			VIBI=$(echo $VIBI+1 | bc)
		done
esac


M configs/default_hooks/sxmo_hook_ring.sh => configs/default_hooks/sxmo_hook_ring.sh +28 -10
@@ 25,13 25,31 @@ if ! sxmo_modemcall.sh list_active_calls \
	exit
fi

# Start the mpv ring until another hook kill it or the max (10) is reached
mpv --quiet --no-video --loop=10 "$(xdg_data_path sxmo/ring.ogg)" &
MPVID=$!
echo "$MPVID" > "$XDG_RUNTIME_DIR/sxmo.ring.pid"

# Vibrate while mpv is running
while kill -0 $MPVID; do
		sxmo_vibrate 1500
		sleep 0.5
done
# Start the mpv ring until another hook kill it or the max SXMO_RINGTIME or SXMO_RINGNUMBER is reached
case "$(cat "$XDG_CONFIG_HOME"/sxmo/.ringmode)" in
	Mute)
	;;
	Vibrate)
		for _ in $(seq 5); do
			sxmo_vibrate 1500
			sleep 0.5
		done
		;;
	Ring)
		timeout "$SXMO_RINGTIME" mpv --no-resume-playback --quiet --no-video \
			--loop="$SXMO_RINGNUMBER" "$SXMO_RINGTONE" &
		MPVID=$!
		echo "$MPVID" > "$XDG_RUNTIME_DIR/sxmo.ring.pid"
	;;
	*) #Default ring and vibrate
		timeout "$SXMO_RINGTIME" mpv --no-resume-playback --quiet --no-video \
			--loop="$SXMO_RINGNUMBER" "$SXMO_RINGTONE" &
		MPVID=$!
		echo "$MPVID" > "$XDG_RUNTIME_DIR/sxmo.ring.pid"
		# Vibrate while mpv is running
		while kill -0 $MPVID; do
				sxmo_vibrate 1500
				sleep 0.5
		done
		;;
esac

M configs/default_hooks/sxmo_hook_sms.sh => configs/default_hooks/sxmo_hook_sms.sh +14 -1
@@ 16,4 16,17 @@
# shellcheck source=scripts/core/sxmo_common.sh
. sxmo_common.sh

mpv --quiet --no-video "$(xdg_data_path sxmo/notify.ogg)"
case "$(cat "$XDG_CONFIG_HOME"/sxmo/.ringmode)" in
	Mute)
		;;
	Vibrate)
		sxmo_vibrate 500
		;;
	Ring)
		mpv --no-resume-playback --quiet --no-video "$SXMO_TEXTSOUND"
		;;
	*) #Default: ring&vibrate
		mpv --no-resume-playback --quiet --no-video "$SXMO_TEXTSOUND" &
		sxmo_vibrate 500
		;;
esac

M scripts/core/sxmo_audio.sh => scripts/core/sxmo_audio.sh +40 -0
@@ 106,6 106,44 @@ _callaudiodsubmenu() {
	fi
}

_ringmodesubmenu() {
	curmode="$(cat "$XDG_CONFIG_HOME"/sxmo/.ringmode)"
	[ -z "$curmode" ] && curmode="Ring&Vibrate"

	if [ "$curmode" = "Ring&Vibrate" ]; then
		printf "%s" "$icon_chk"
	else
		printf "%s" "$icon_cls"
	fi
	# carefull, this one can easily match for the Ring one too
	# shellcheck disable=SC2016
	printf ' Mode Ring&vibrate ^ echo "" > "$XDG_CONFIG_HOME/sxmo/.ringmode"\n'

	if [ "$curmode" = Vibrate ]; then
		printf "%s" "$icon_chk"
	else
		printf "%s" "$icon_cls"
	fi
	# shellcheck disable=SC2016
	printf ' Mode Vibrate ^ echo Vibrate > "$XDG_CONFIG_HOME/sxmo/.ringmode"\n'

	if [ "$curmode" = Ring ]; then
		printf "%s" "$icon_chk"
	else
		printf "%s" "$icon_cls"
	fi
	# shellcheck disable=SC2016
	printf ' Mode Ring ^ echo Ring > "$XDG_CONFIG_HOME/sxmo/.ringmode"\n'

	if [ "$curmode" = Mute ]; then
		printf "%s" "$icon_chk"
	else
		printf "%s" "$icon_cls"
	fi
	# shellcheck disable=SC2016
	printf ' Mode Muted ^ echo Mute > "$XDG_CONFIG_HOME/sxmo/.ringmode"\n'
}

pulsemenuchoices() {
	grep . <<EOF
$icon_cls Close Menu  ^ exit


@@ 113,6 151,7 @@ $icon_aru Volume up   ^ pulsevolup
$icon_ard Volume down ^ pulsevoldown
$(pulsesinksget | sed -e "s/^/$icon_spk /" -e 's/\^ \([0-9]\+\)$/^ pulsesinksset \1/')
$(_callaudiodsubmenu)
$(_ringmodesubmenu)
EOF
}



@@ 210,6 249,7 @@ $icon_phn Earpiece $([ "$CURRENTDEV" = "Earpiece" ] && echo "$icon_chk")    ^ al
$icon_mut None $([ -z "$CURRENTDEV" ] && echo "$icon_chk")                  ^ alsadeviceset
$icon_aru Volume up                                                         ^ alsavolup
$icon_ard Volume down                                                       ^ alsavoldown
$(_ringmodesubmenu)
EOF
}