1d8624e3b0caf7b8d8b69b58d87fed09177f53cd
[xsetrootd.git] / src / main.rs
1 use dbus::blocking::stdintf::org_freedesktop_dbus::PropertiesPropertiesChanged;
2 use dbus::blocking::Connection;
3 use dbus::message::Message;
4 use std::time::Duration;
5
6 fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let conn = Connection::new_session()?;
8
9 let proxy = conn.with_proxy(
10 "org.mpris.MediaPlayer2.spotify",
11 "/org/mpris/MediaPlayer2",
12 Duration::from_millis(5000),
13 );
14
15 let _ = proxy.match_signal(
16 |pc: PropertiesPropertiesChanged, _: &Connection, _: &Message| {
17 pc.changed_properties["Metadata"]
18 .0
19 .as_iter()
20 .and_then(|mut iter| {
21 // Iterating over a RefArg goes key, value, key, value... Insane honestly.
22 while let Some(key) = iter.next() {
23 let key_str = key.as_str()?;
24 let value = iter.next();
25
26 match key_str {
27 "xesam:artist" => {
28 // Variant holding a variant that should just be a Vec<&str> I
29 // believe. This is _the recommended_ way to do this by the author.
30 let inner_value = value?.as_iter()?.next()?.as_iter()?.next()?;
31 let artist = String::from(inner_value.as_str()?);
32 println!("artist: {}", artist);
33 }
34 _ => (),
35 }
36 }
37 Some(())
38 });
39 true
40 },
41 );
42
43 loop {
44 conn.process(Duration::from_millis(1000))?;
45 }
46 }