Skip to content

Commit

Permalink
add audio control
Browse files Browse the repository at this point in the history
  • Loading branch information
nnyyxxxx committed Sep 23, 2024
1 parent 70ddc4f commit e642f61
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 1 deletion.
112 changes: 112 additions & 0 deletions core/tabs/utils/audio-control.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/sh -e

. ../common-script.sh

setupAudio() {
if systemctl --user is-active --quiet pipewire; then
audio_server="pipewire"
elif systemctl --user is-active --quiet pulseaudio; then
audio_server="pulseaudio"
else
clear
printf "%b\n" "${YELLOW}Pick an Audio Server${RC}"
printf "%b\n" "1. PulseAudio"
printf "%b\n" "2. PipeWire"
printf "%b" "Choose an option: "
read -r choice

case $choice in
1) audio_server="pulseaudio" ;;
2) audio_server="pipewire pipewire-pulse" ;;
*) return ;;
esac

case "$PACKAGER" in
pacman)
"$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm "$audio_server"
;;
*)
"$ESCALATION_TOOL" "$PACKAGER" install -y "$audio_server"
;;
esac
fi
}

menu() {
while true; do
clear
printf "%b\n" "${YELLOW}Audio Manager${RC}"
printf "%b\n" "${YELLOW}=============${RC}"
printf "%b\n" "1. Mute Audio"
printf "%b\n" "2. Unmute Audio"
printf "%b\n" "3. Set Volume"
printf "%b\n" "4. List Current Volume"
printf "%b" "Choose an option: "
read -r choice

case $choice in
1) muteAudio ;;
2) unmuteAudio ;;
3) setVolume ;;
4) listVolume ;;
*) printf "%b\n" "${RED}Invalid option. Please try again.${RC}" ;;
esac
done
}

muteAudio() {
clear
if pactl set-sink-mute @DEFAULT_SINK@ toggle; then
printf "%b\n" "${GREEN}Audio muted.${RC}"
else
printf "%b\n" "${RED}Failed to mute audio.${RC}"
fi
printf "%b\n" "Press enter to return to the main menu..."
read -r dummy
}

unmuteAudio() {
clear
if pactl set-sink-mute @DEFAULT_SINK@ toggle; then
printf "%b\n" "${GREEN}Audio unmuted.${RC}"
else
printf "%b\n" "${RED}Failed to unmute audio.${RC}"
fi
printf "%b\n" "Press enter to return to the main menu..."
read -r dummy
}

setVolume() {
while true; do
clear
printf "%b" "Enter the volume percentage (1-100): "
read -r volume
if [ "$volume" -ge 1 ] && [ "$volume" -le 100 ]; then
if pactl set-sink-volume @DEFAULT_SINK@ "$volume%"; then
printf "%b\n" "${GREEN}Volume set to $volume% successfully.${RC}"
else
printf "%b\n" "${RED}Failed to set volume.${RC}"
fi
break
else
printf "%b\n" "${RED}Invalid volume percentage.${RC}"
printf "%b\n" "Press enter to try again..."
read -r dummy
fi
done
printf "%b\n" "Press enter to return to the main menu..."
read -r dummy
}

listVolume() {
clear
volume=$(pactl get-sink-volume @DEFAULT_SINK@ | grep -oP '\d+%' | head -1)
printf "%b\n" "${YELLOW}Current volume: $volume${RC}"
printf "%b\n" "Press enter to return to the main menu..."
read -r dummy
}

checkEnv
checkEscalationTool
setupAudio
menu
7 changes: 6 additions & 1 deletion core/tabs/utils/tab_data.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ name = "Auto Detect Displays"
description = "This utility is designed to detect and apply recommended configuration for monitors connected with your system"
script = "monitor-control/auto_detect_displays.sh"

[[data]]
name = "Audio Control"
script = "audio-control.sh"
task_list = "I SS"

[[data]]
name = "Auto Mount Drive"
script = "auto-mount.sh"
Expand Down Expand Up @@ -161,4 +166,4 @@ task_list = "I"
name = "WiFi Manager"
description = "This utility is designed to manage wifi in your system"
script = "wifi-control.sh"
task_list = "I SS"
task_list = "I SS"

0 comments on commit e642f61

Please sign in to comment.