Prevent small race when both track and artist change master
authorJacob Casper <dev@jacobcasper.com>
Mon, 11 Sep 2023 20:57:39 +0000 (15:57 -0500)
committerJacob Casper <dev@jacobcasper.com>
Mon, 11 Sep 2023 20:57:39 +0000 (15:57 -0500)
Iteration order can cause the xsetroot command to be updated with only
one or the other value at times, which remains incorrect until after
another update call such as from the clock or mail listeners.

src/main.rs

index d6beac7ba3346ed73d4af4f776ecc6d03e22a5ef..d2d1df26a6fe9cc7fb921788bbfbcad2acc6d0a2 100644 (file)
@@ -51,6 +51,11 @@ fn update_map(arc_map: Arc<Mutex<HashMap<String, String>>>, key: &str, val: &str
     let clone_arc = arc_map.clone();
     let mut map = clone_arc.lock().unwrap();
     map.insert(String::from(key), String::from(val));
+}
+
+fn update_xsetroot(arc_map: Arc<Mutex<HashMap<String, String>>>) {
+    let clone_arc = arc_map.clone();
+    let map = clone_arc.lock().unwrap();
     let _ = Command::new("xsetroot")
         .arg("-name")
         .arg(format!(
@@ -82,6 +87,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
                 "unread_count",
                 m.count.to_string().as_str(),
             );
+            update_xsetroot(mail_match_map.clone());
             true
         },
     );
@@ -119,6 +125,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
                                 _ => (),
                             }
                         }
+                        update_xsetroot(spotify_match_map.clone());
                         Some(())
                     });
                 }
@@ -135,6 +142,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
                             _ => "🔈",
                         },
                     );
+                    update_xsetroot(spotify_match_map.clone());
                 }
                 None => (),
             }
@@ -155,6 +163,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
                     "date_time",
                     get_local_time_string().as_str(),
                 );
+                update_xsetroot(date_time_map.clone());
             }
             thread::sleep(Duration::from_millis(5000));
         }