X-Git-Url: https://git.distorted.org.uk/~mdw/profile/blobdiff_plain/33edf1fb89d0b4ef7493d3753a2ed12568c46d90..be626dd5fa368d4adb39458af61a877e100e5b4e:/bin/disorder-notify?ds=sidebyside diff --git a/bin/disorder-notify b/bin/disorder-notify index 092d255..4e0b354 100755 --- a/bin/disorder-notify +++ b/bin/disorder-notify @@ -124,8 +124,16 @@ sub get_state0 ($) { return \%st; } +my $CONF = undef; + +sub configured_connection (;$) { + my ($quietp) = @_; + $CONF //= load_config $C{config}; + return connect_to_server %$CONF, $quietp // 0; +} + sub get_state () { - my $sk = connect_to_server $C{config}; + my $sk = configured_connection; send_command0 $sk, "log"; my $st = get_state0 $sk; close $sk; @@ -173,8 +181,8 @@ sub get_now_playing ($) { sub watch_and_notify0 ($) { my ($now_playing) = @_; - my $sk = connect_to_server $C{config}, 1; - my $sk_log = connect_to_server $C{config}, 1; + my $sk = configured_connection 1; + my $sk_log = configured_connection 1; send_command0 $sk_log, "log"; my $st = get_state0 $sk_log; @@ -269,14 +277,14 @@ $OP{"volume-down"} = sub { run_discard_output "amixer", "sset", $C{mixer}, "5\%-"; }; $OP{"scratch"} = sub { - my $sk = connect_to_server $C{config}; + my $sk = configured_connection; send_command $sk, "scratch"; close $sk; }; $OP{"enable/disable"} = sub { my $st = get_state; - my $sk = connect_to_server $C{config}; + my $sk =configured_connection; if ($st->{play}) { send_command $sk, "disable"; } else { send_command $sk, "enable"; } close $sk; @@ -284,7 +292,7 @@ $OP{"enable/disable"} = sub { $OP{"play/pause"} = sub { my $st = get_state; - my $sk = connect_to_server $C{config}; + my $sk = configured_connection; if (!$st->{play}) { send_command $sk, "enable"; if ($st->{pause}) { send_command $sk, "resume"; } @@ -304,7 +312,7 @@ $OP{"watch"} = sub { }; $OP{"now-playing"} = sub { - my $sk = connect_to_server $C{config}; + my $sk = configured_connection; my $info = get_now_playing $sk; close $sk; print format_now_playing %$info; @@ -312,7 +320,7 @@ $OP{"now-playing"} = sub { }; $OP{"notify-now-playing"} = sub { - my $sk = connect_to_server $C{config}; + my $sk = configured_connection; my $info = get_now_playing $sk; close $sk; notify "$TITLE: Now playing", format_now_playing %$info;