This commit is contained in:
Erica Z 2024-11-21 22:23:50 +01:00
parent 0aa7984092
commit e4c54dc6f5

View file

@ -4,7 +4,7 @@ use gtk::glib::SendWeakRef;
use std::collections::HashMap; use std::collections::HashMap;
use tracing::{event, Level}; use tracing::{event, Level};
use zbus::object_server::{InterfaceRef, SignalEmitter}; use zbus::object_server::{InterfaceRef, SignalEmitter};
use zbus::zvariant::{ObjectPath, OwnedValue, Value}; use zbus::zvariant::{ObjectPath, Value};
pub const MICROSECONDS: f64 = 1e6; // in a second pub const MICROSECONDS: f64 = 1e6; // in a second
@ -153,21 +153,17 @@ impl Player {
} }
#[zbus(property)] #[zbus(property)]
fn metadata(&self) -> HashMap<&'static str, OwnedValue> { fn metadata(&self) -> HashMap<&'static str, Value<'_>> {
let mut map = HashMap::new(); let mut map = HashMap::new();
if let Some(song) = self.window().song() { if let Some(song) = self.window().song() {
map.insert( map.insert(
"mpris:trackid", "mpris:trackid",
Value::new(format!("/eu/callcc/audrey/Track/{}", song.counter())) Value::new(format!("/eu/callcc/audrey/Track/{}", song.counter())).to_owned(),
.try_into()
.unwrap(),
); );
map.insert( map.insert(
"mpris:length", "mpris:length",
Value::new((self.window().duration() * MICROSECONDS) as i64) Value::new((self.window().duration() * MICROSECONDS) as i64),
.try_into()
.unwrap(),
); );
map.insert( map.insert(
"mpris:artUrl", "mpris:artUrl",
@ -176,15 +172,12 @@ impl Player {
.unwrap() .unwrap()
.to_string(), .to_string(),
) )
.try_into() .to_owned(),
.unwrap(),
); );
map.insert("xesam:album", Value::new(song.album()).try_into().unwrap()); map.insert("xesam:album", Value::new(song.album()));
map.insert( // TODO: use the right opensubsonic data
"xesam:artist", map.insert("xesam:artist", Value::new(vec![song.artist()]));
Value::new(vec![song.artist()]).try_into().unwrap(), map.insert("xesam:title", Value::new(song.title()));
);
map.insert("xesam:title", Value::new(song.title()).try_into().unwrap());
} }
map map