chiark
/
gitweb
/
~mdw
/
profile
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
pl/DisOrder.pm, etc.: Split `load_config' from `connect_to_server'.
[profile]
/
bin
/
disorder-notify
diff --git
a/bin/disorder-notify
b/bin/disorder-notify
index 092d2558a774ced8a3ebf4d89091f22a7836117b..4e0b354068b4429f20be1f1837e3d1f5f375612b 100755
(executable)
--- a/
bin/disorder-notify
+++ b/
bin/disorder-notify
@@
-124,8
+124,16
@@
sub get_state0 ($) {
return \%st;
}
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 () {
sub get_state () {
- my $sk = con
nect_to_server $C{config}
;
+ my $sk = con
figured_connection
;
send_command0 $sk, "log";
my $st = get_state0 $sk;
close $sk;
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) = @_;
sub watch_and_notify0 ($) {
my ($now_playing) = @_;
- my $sk = con
nect_to_server $C{config},
1;
- my $sk_log = con
nect_to_server $C{config},
1;
+ my $sk = con
figured_connection
1;
+ my $sk_log = con
figured_connection
1;
send_command0 $sk_log, "log";
my $st = get_state0 $sk_log;
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 {
sub { run_discard_output "amixer", "sset", $C{mixer}, "5\%-"; };
$OP{"scratch"} = sub {
- my $sk = con
nect_to_server $C{config}
;
+ my $sk = con
figured_connection
;
send_command $sk, "scratch";
close $sk;
};
$OP{"enable/disable"} = sub {
my $st = get_state;
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;
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;
$OP{"play/pause"} = sub {
my $st = get_state;
- my $sk = con
nect_to_server $C{config}
;
+ my $sk = con
figured_connection
;
if (!$st->{play}) {
send_command $sk, "enable";
if ($st->{pause}) { send_command $sk, "resume"; }
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 {
};
$OP{"now-playing"} = sub {
- my $sk = con
nect_to_server $C{config}
;
+ my $sk = con
figured_connection
;
my $info = get_now_playing $sk;
close $sk;
print format_now_playing %$info;
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 {
};
$OP{"notify-now-playing"} = sub {
- my $sk = con
nect_to_server $C{config}
;
+ my $sk = con
figured_connection
;
my $info = get_now_playing $sk;
close $sk;
notify "$TITLE: Now playing", format_now_playing %$info;
my $info = get_now_playing $sk;
close $sk;
notify "$TITLE: Now playing", format_now_playing %$info;