pkgs: change-audio: 0.1.2 -> 0.2.0

Allow muting microphone and speakers, with refactor to make it DRY.
This commit is contained in:
Bruno BELANYI 2021-11-12 10:17:39 +01:00
parent 2d7f01f035
commit 119504d0b5
2 changed files with 56 additions and 17 deletions

View file

@ -2,6 +2,13 @@
set -euo pipefail set -euo pipefail
NOTIFY=(
notify-send
-u low
-h string:x-canonical-private-synchronous:change-audio
)
do_change_volume() {
if [ "$1" = "up" ]; then if [ "$1" = "up" ]; then
upDown="-i" upDown="-i"
else else
@ -16,8 +23,40 @@ MSG="Set volume to $newVolume%"
if [ "${isMuted:-false}" = true ]; then if [ "${isMuted:-false}" = true ]; then
MSG="$MSG (muted)" MSG="$MSG (muted)"
fi fi
"${NOTIFY[@]}" \
notify-send -u low \
-h string:x-canonical-private-synchronous:change-audio \
-h "int:value:$newVolume" \ -h "int:value:$newVolume" \
-- "$MSG" -- "$MSG"
}
do_toggle() {
args=()
if [ "${2:-audio}" = mic ]; then
args+=(--default-source)
MSG="Toggled microphone"
else
MSG="Toggled audio output"
fi
pamixer "${args[@]}" --toggle-mute
if [ "$(pamixer "${args[@]}" --get-mute)" = true ]; then
MSG="$MSG (muted)"
else
MSG="$MSG (unmuted)"
fi
"${NOTIFY[@]}" -- "$MSG"
}
case "$1" in
up|down)
do_change_volume "$@"
;;
toggle)
do_toggle "$@"
;;
*)
echo "No suche option '$1'" >&2
exit 1
;;
esac

View file

@ -1,7 +1,7 @@
{ lib, libnotify, makeWrapper, pamixer, shellcheck, stdenvNoCC }: { lib, libnotify, makeWrapper, pamixer, shellcheck, stdenvNoCC }:
stdenvNoCC.mkDerivation rec { stdenvNoCC.mkDerivation rec {
pname = "change-audio"; pname = "change-audio";
version = "0.1.2"; version = "0.2.0";
src = ./change-audio; src = ./change-audio;