diff --git a/Cargo.lock b/Cargo.lock index 635f7f1..c0cb58f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -220,6 +220,7 @@ dependencies = [ "async-channel", "base16ct", "bindgen", + "bytes", "chrono", "event-listener", "futures", diff --git a/Cargo.toml b/Cargo.toml index f08ba96..fbbbd1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" adw = { version = "0.7.0", package = "libadwaita", features = ["v1_6"] } async-channel = "2.3.1" base16ct = { version = "0.2.0", features = ["std"] } +bytes = "1.8.0" chrono = { version = "0.4.38", features = ["serde"] } event-listener = "5.3.1" futures = "0.3.31" diff --git a/src/subsonic.rs b/src/subsonic.rs index 3f3b9bc..83c8680 100644 --- a/src/subsonic.rs +++ b/src/subsonic.rs @@ -181,6 +181,29 @@ impl Client { self.url(&["rest", "coverArt"], &[("id", id)]) } + pub async fn cover_art(&self, id: &str) -> Result { + let (sender, receiver) = async_channel::bounded(1); + + let future = self.client.get(self.cover_art_url(id)).send(); + runtime().spawn(async move { + async fn perform( + response: Result, + ) -> Result { + Ok(response?.error_for_status()?.bytes().await?) + } + + sender + .send(perform(future.await).await) + .await + .expect("could not send cover art bytes back to the main loop"); + }); + + receiver + .recv() + .await + .expect("could not receive cover art bytes from tokio") + } + pub fn stream_url(&self, id: &str) -> url::Url { self.url(&["rest", "stream"], &[("id", id)]) } diff --git a/src/ui/window.rs b/src/ui/window.rs index a071a3c..2170b9f 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -61,6 +61,8 @@ mod imp { pub(crate) initial_setup_handle: RefCell>>, mpv_event_loop_handle: RefCell>>, // really !, not () zbus_executor_loop_handle: RefCell>>, // same + + loading_cover_handle: RefCell>>>, } impl Default for Window { @@ -111,6 +113,8 @@ mod imp { initial_setup_handle: Default::default(), mpv_event_loop_handle: Default::default(), zbus_executor_loop_handle: Default::default(), + + loading_cover_handle: Default::default(), } } } @@ -205,7 +209,16 @@ mod imp { event!(Level::INFO, "start file event"); window.notify("song"); window.imp().buffering_start(); - // TODO: load cover art + + /* + let window = window.clone(); + window + .imp() + .loading_cover_handle + .replace(Some(glib::spawn_future_local( + async move { todo!() }, + ))) + .map(|handle| handle.abort());*/ } Event::Hook(event) => match event.reply_userdata {