chiark / gitweb /
bin/disorder-notify: Improve startup notifications.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 21 Jul 2018 14:20:56 +0000 (15:20 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 21 Jul 2018 14:59:17 +0000 (15:59 +0100)
Accumulate the startup state dump, and also report the current track if
there is one.

bin/disorder-notify

index 780aadcd400d8da30a2575bb204857ae205b37ca..ac329ba4d472e4b73049f0aa6d77bdd58f8a5da4 100755 (executable)
@@ -48,6 +48,8 @@ sub now_playing (;$) {
 
 for (;;) {
   open my $log, "-|", "disorder", "log";
+  my $startp = 1;
+  my $stateinfo = undef;
   LINE: while (<$log>) {
     chomp;
     my @f = ();
@@ -76,7 +78,11 @@ for (;;) {
     push @f, $t if defined $t;
 
     my $what = $f[1];
-    if ($what eq "state") {
+    if ($what eq "volume" && $startp) {
+      $startp = 0;
+      notify "DisOrder state", "Connected: $startinfo";
+      now_playing;
+    } elsif ($what eq "state") {
       my $st = $f[2];
       my $msg;
       my $np = 0;
@@ -87,8 +93,12 @@ for (;;) {
       elsif ($st eq "pause") { $msg = "paused"; }
       elsif ($st eq "resume") { $msg = "playing"; $np = 1; }
       else { next LINE; }
-      notify "DisOrder state", ucfirst $msg;
-      now_playing if $np;
+      if (!$startp) {
+       notify "DisOrder state", ucfirst $msg;
+       now_playing if $np;
+      } else {
+       if (defined $startinfo) { $startinfo .= "; " . $msg; }
+       else { $startinfo = $msg; }
       }
     } elsif ($what eq "playing") {
       now_playing $f[2];