bin/wakey.zsh: Use `$SECONDS' rather than `$EPOCHREALTIME'.
[profile] / bin / disorder-notify
index 780aadc..84c702f 100755 (executable)
@@ -3,16 +3,16 @@
 sub notify ($$) {
   my ($head, $body) = @_;
 
+  $body =~ s:\&:&:g;
+  $body =~ s:\<:&lt;:g;
+  $body =~ s:\>:&gt;:g;
   my $kid = fork;
   defined $kid or return;
   if (!$kid) {
     open STDOUT, ">", "/dev/null";
-    exec "gdbus", "call", "-e",
-      "-d", "org.freedesktop.Notifications",
-      "-o", "/org/freedesktop/Notifications",
-      "-m", "org.freedesktop.Notifications.Notify", "--",
-      "DisOrder", "0", "audio-volume-high",
-      $head, $body, "[]", "{}", "5000";
+    exec "notify-send",
+      "-c", "DisOrder", "-i", "audio-volume-high", "-t", "5000",
+      $head, $body;
   }
   waitpid $kid, 0;
 }
@@ -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,9 +93,15 @@ 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 "scratched") {
+      notify "DisOrder state", "Scratched playing track";
     } elsif ($what eq "playing") {
       now_playing $f[2];
     }