only load thumbnails on play queue song bound
This commit is contained in:
parent
d50cc74698
commit
850450fdb4
4 changed files with 39 additions and 43 deletions
|
@ -106,10 +106,6 @@ template $AudreyUiWindow: Adw.ApplicationWindow {
|
||||||
pixel-size: 160;
|
pixel-size: 160;
|
||||||
halign: center;
|
halign: center;
|
||||||
hexpand: false;
|
hexpand: false;
|
||||||
|
|
||||||
styles [
|
|
||||||
"frame"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
|
|
|
@ -75,11 +75,7 @@ glib::wrapper! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Song {
|
impl Song {
|
||||||
pub fn from_child(
|
pub fn from_child(window: &crate::ui::Window, song: &subsonic::schema::Child) -> Self {
|
||||||
window: &crate::ui::Window,
|
|
||||||
song: &subsonic::schema::Child,
|
|
||||||
load_thumbnail: bool,
|
|
||||||
) -> Self {
|
|
||||||
let api = window.api();
|
let api = window.api();
|
||||||
let song: Song = Object::builder()
|
let song: Song = Object::builder()
|
||||||
.property("id", &song.id)
|
.property("id", &song.id)
|
||||||
|
@ -92,39 +88,41 @@ impl Song {
|
||||||
.property("stream-url", api.stream_url(&song.id).as_str())
|
.property("stream-url", api.stream_url(&song.id).as_str())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
if load_thumbnail {
|
|
||||||
let id = song.id();
|
|
||||||
let song_weak = song.downgrade();
|
|
||||||
let scale_factor = window.scale_factor() as u32; // NOTE: assumed constant
|
|
||||||
song.imp()
|
|
||||||
.thumbnail_loading
|
|
||||||
.replace(Some(glib::spawn_future_local(async move {
|
|
||||||
let _permit = SEM.acquire().await.unwrap();
|
|
||||||
|
|
||||||
let bytes = match api
|
|
||||||
.cover_art(&id, Some(50 * scale_factor)) // see pixel-size in
|
|
||||||
// play_queue_song.blp
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(bytes) => bytes,
|
|
||||||
Err(err) => {
|
|
||||||
event!(
|
|
||||||
Level::ERROR,
|
|
||||||
"could not fetch thumbnail for song {id}: {err}"
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let song = match song_weak.upgrade() {
|
|
||||||
None => return,
|
|
||||||
Some(song) => song,
|
|
||||||
};
|
|
||||||
song.set_thumbnail(
|
|
||||||
gdk::Texture::from_bytes(&glib::Bytes::from_owned(bytes)).unwrap(),
|
|
||||||
);
|
|
||||||
})));
|
|
||||||
}
|
|
||||||
|
|
||||||
song
|
song
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn need_thumbnail(&self, window: &crate::ui::Window) {
|
||||||
|
let api = window.api();
|
||||||
|
let mut thumbnail_loading = self.imp().thumbnail_loading.borrow_mut();
|
||||||
|
if thumbnail_loading.is_none() {
|
||||||
|
let id = self.id();
|
||||||
|
let song_weak = self.downgrade();
|
||||||
|
let scale_factor = window.scale_factor() as u32; // NOTE: assumed constant
|
||||||
|
*thumbnail_loading = Some(glib::spawn_future_local(async move {
|
||||||
|
let _permit = SEM.acquire().await.unwrap();
|
||||||
|
|
||||||
|
let bytes = match api
|
||||||
|
.cover_art(&id, Some(50 * scale_factor)) // see pixel-size in
|
||||||
|
// play_queue_song.blp
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(bytes) => bytes,
|
||||||
|
Err(err) => {
|
||||||
|
event!(
|
||||||
|
Level::ERROR,
|
||||||
|
"could not fetch thumbnail for song {id}: {err}"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let song = match song_weak.upgrade() {
|
||||||
|
None => return,
|
||||||
|
Some(song) => song,
|
||||||
|
};
|
||||||
|
song.set_thumbnail(
|
||||||
|
gdk::Texture::from_bytes(&glib::Bytes::from_owned(bytes)).unwrap(),
|
||||||
|
);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,6 +200,8 @@ impl Song {
|
||||||
self.set_song(&song);
|
self.set_song(&song);
|
||||||
self.set_position(position);
|
self.set_position(position);
|
||||||
self.set_playlist_pos(window.playlist_pos());
|
self.set_playlist_pos(window.playlist_pos());
|
||||||
|
|
||||||
|
song.need_thumbnail(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unbind(&self) {}
|
pub fn unbind(&self) {}
|
||||||
|
|
|
@ -394,7 +394,7 @@ mod imp {
|
||||||
Rc::clone(api.as_ref().unwrap())
|
Rc::clone(api.as_ref().unwrap())
|
||||||
};
|
};
|
||||||
for song in api.random_songs(500).await.unwrap().into_iter() {
|
for song in api.random_songs(500).await.unwrap().into_iter() {
|
||||||
let song = Song::from_child(&self.obj(), &song, true);
|
let song = Song::from_child(&self.obj(), &song);
|
||||||
self.mpv
|
self.mpv
|
||||||
.command(["loadfile", &song.stream_url(), "append-play"])
|
.command(["loadfile", &song.stream_url(), "append-play"])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
Loading…
Reference in a new issue