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}'
|
'{"is_paused": $is_paused, "song": $info, "radio": $radio_id, "stations": $stations, "media": $media}'
|
||||||
}
|
}
|
||||||
|
|
||||||
get_mpv_node() {
|
get_stream_node() {
|
||||||
wpctl status 2>/dev/null | awk '
|
local name="$1"
|
||||||
|
wpctl status 2>/dev/null | awk -v pat="$name" '
|
||||||
/Streams:/ { in_s = 1 }
|
/Streams:/ { in_s = 1 }
|
||||||
/Sinks:|Sources:|Clients:/ { in_s = 0 }
|
/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() {
|
get_volume() {
|
||||||
if [ "$PID" -gt 0 ] && kill -0 "$PID" 2>/dev/null; then
|
if [ "$PID" -gt 0 ] && kill -0 "$PID" 2>/dev/null; then
|
||||||
local node_id; node_id=$(get_mpv_node)
|
local node_id; node_id=$(get_mpv_node)
|
||||||
@@ -112,23 +119,19 @@ do_vol() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
do_mute() {
|
do_mute() {
|
||||||
|
local node_id
|
||||||
if [ "$PID" -gt 0 ] && kill -0 "$PID" 2>/dev/null; then
|
if [ "$PID" -gt 0 ] && kill -0 "$PID" 2>/dev/null; then
|
||||||
local node_id; node_id=$(get_mpv_node)
|
node_id=$(get_mpv_node)
|
||||||
if [ -n "$node_id" ]; then
|
|
||||||
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
|
else
|
||||||
wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
|
local player; player=$(playerctl -l 2>/dev/null | grep -Ev '^mpv' | head -1)
|
||||||
if wpctl get-volume @DEFAULT_AUDIO_SINK@ 2>/dev/null | grep -q MUTED; then
|
[ -n "$player" ] && node_id=$(get_stream_node "${player%%.*}")
|
||||||
eww update radio-muted=true
|
fi
|
||||||
else
|
[ -z "$node_id" ] && return
|
||||||
eww update radio-muted=false
|
wpctl set-mute "$node_id" toggle
|
||||||
fi
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user