X-Git-Url: https://git.jacobcasper.com/?p=xsetrootd.git;a=blobdiff_plain;f=src%2Fmain.rs;fp=src%2Fmain.rs;h=d6beac7ba3346ed73d4af4f776ecc6d03e22a5ef;hp=800cf54534953f41411b65342c1a4825565e835c;hb=be7f5d4dbc41d4267ddded3c7e00a79079de99e7;hpb=6d3ac36bd8cf04e1357e6853a059692e42089288 diff --git a/src/main.rs b/src/main.rs index 800cf54..d6beac7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -95,41 +95,49 @@ fn main() -> Result<(), Box> { let spotify_match_map = arc_locked_xset_map.clone(); let _ = spotify_proxy.match_signal( move |pc: PropertiesPropertiesChanged, _: &Connection, _: &Message| { - pc.changed_properties["Metadata"] - .0 - .as_iter() - .and_then(|mut iter| { - // Iterating over a RefArg goes key, value, key, value... Insane honestly. - while let Some(key) = iter.next() { - let key_str = key.as_str()?; - let value = iter.next(); + match pc.changed_properties.get("Metadata") { + Some(variant) => { + variant.0.as_iter().and_then(|mut iter| { + // Iterating over a RefArg goes key, value, key, value... Insane honestly. + while let Some(key) = iter.next() { + let key_str = key.as_str()?; + let value = iter.next(); - match key_str { - "xesam:artist" => { - // Variant holding a variant that should just be a Vec<&str> I - // believe. This is _the recommended_ way to do this by the author. - let inner_value = value?.as_iter()?.next()?.as_iter()?.next()?; - let artist = inner_value.as_str()?; - update_map(spotify_match_map.clone(), "artist", artist); + match key_str { + "xesam:artist" => { + // Variant holding a variant that should just be a Vec<&str> I + // believe. This is _the recommended_ way to do this by the author. + let inner_value = + value?.as_iter()?.next()?.as_iter()?.next()?; + let artist = inner_value.as_str()?; + update_map(spotify_match_map.clone(), "artist", artist); + } + "xesam:title" => { + let title = value?.as_iter()?.next()?.as_str()?; + update_map(spotify_match_map.clone(), "title", title); + } + _ => (), } - "xesam:title" => { - let title = value?.as_iter()?.next()?.as_str()?; - update_map(spotify_match_map.clone(), "title", title); - } - _ => (), } - } - Some(()) - }); - let playback_status = &pc.changed_properties["PlaybackStatus"].0; - update_map( - spotify_match_map.clone(), - "playback_status", - match &*playback_status.as_str().unwrap_or("") { - "Playing" => "🔊", - _ => "🔈", - }, - ); + Some(()) + }); + } + None => (), + } + match &pc.changed_properties.get("PlaybackStatus") { + Some(variant) => { + let playback_status = &variant.0; + update_map( + spotify_match_map.clone(), + "playback_status", + match &*playback_status.as_str().unwrap_or("") { + "Playing" => "🔊", + _ => "🔈", + }, + ); + } + None => (), + } true }, );