fix mute
This commit is contained in:
@@ -80,14 +80,21 @@ emit_status() {
|
||||
'{"is_paused": $is_paused, "song": $info, "radio": $radio_id, "stations": $stations, "media": $media}'
|
||||
}
|
||||
|
||||
get_mpv_node() {
|
||||
wpctl status 2>/dev/null | awk '
|
||||
get_stream_node() {
|
||||
local name="$1"
|
||||
wpctl status 2>/dev/null | awk -v pat="$name" '
|
||||
/Streams:/ { in_s = 1 }
|
||||
/Sinks:|Sources:|Clients:/ { in_s = 0 }
|
||||
in_s && /[0-9]+\..*mpv/ { match($0, /[0-9]+/); print substr($0, RSTART, RLENGTH); exit }
|
||||
in_s && /[0-9]+\./ && tolower($0) ~ tolower(pat) {
|
||||
match($0, /[0-9]+/); print substr($0, RSTART, RLENGTH); exit
|
||||
}
|
||||
'
|
||||
}
|
||||
|
||||
get_mpv_node() {
|
||||
get_stream_node "mpv"
|
||||
}
|
||||
|
||||
get_volume() {
|
||||
if [ "$PID" -gt 0 ] && kill -0 "$PID" 2>/dev/null; then
|
||||
local node_id; node_id=$(get_mpv_node)
|
||||
@@ -112,24 +119,20 @@ do_vol() {
|
||||
}
|
||||
|
||||
do_mute() {
|
||||
local node_id
|
||||
if [ "$PID" -gt 0 ] && kill -0 "$PID" 2>/dev/null; then
|
||||
local node_id; node_id=$(get_mpv_node)
|
||||
if [ -n "$node_id" ]; then
|
||||
node_id=$(get_mpv_node)
|
||||
else
|
||||
local player; player=$(playerctl -l 2>/dev/null | grep -Ev '^mpv' | head -1)
|
||||
[ -n "$player" ] && node_id=$(get_stream_node "${player%%.*}")
|
||||
fi
|
||||
[ -z "$node_id" ] && return
|
||||
wpctl set-mute "$node_id" toggle
|
||||
if wpctl get-volume "$node_id" 2>/dev/null | grep -q MUTED; then
|
||||
eww update radio-muted=true
|
||||
else
|
||||
eww update radio-muted=false
|
||||
fi
|
||||
fi
|
||||
else
|
||||
wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
|
||||
if wpctl get-volume @DEFAULT_AUDIO_SINK@ 2>/dev/null | grep -q MUTED; then
|
||||
eww update radio-muted=true
|
||||
else
|
||||
eww update radio-muted=false
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
do_start() {
|
||||
|
||||
Reference in New Issue
Block a user