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;
|
||||
halign: center;
|
||||
hexpand: false;
|
||||
|
||||
styles [
|
||||
"frame"
|
||||
]
|
||||
}
|
||||
|
||||
Label {
|
||||
|
|
|
@ -75,11 +75,7 @@ glib::wrapper! {
|
|||
}
|
||||
|
||||
impl Song {
|
||||
pub fn from_child(
|
||||
window: &crate::ui::Window,
|
||||
song: &subsonic::schema::Child,
|
||||
load_thumbnail: bool,
|
||||
) -> Self {
|
||||
pub fn from_child(window: &crate::ui::Window, song: &subsonic::schema::Child) -> Self {
|
||||
let api = window.api();
|
||||
let song: Song = Object::builder()
|
||||
.property("id", &song.id)
|
||||
|
@ -92,13 +88,17 @@ impl Song {
|
|||
.property("stream-url", api.stream_url(&song.id).as_str())
|
||||
.build();
|
||||
|
||||
if load_thumbnail {
|
||||
let id = song.id();
|
||||
let song_weak = song.downgrade();
|
||||
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
|
||||
song.imp()
|
||||
.thumbnail_loading
|
||||
.replace(Some(glib::spawn_future_local(async move {
|
||||
*thumbnail_loading = Some(glib::spawn_future_local(async move {
|
||||
let _permit = SEM.acquire().await.unwrap();
|
||||
|
||||
let bytes = match api
|
||||
|
@ -122,9 +122,7 @@ impl Song {
|
|||
song.set_thumbnail(
|
||||
gdk::Texture::from_bytes(&glib::Bytes::from_owned(bytes)).unwrap(),
|
||||
);
|
||||
})));
|
||||
}
|
||||
|
||||
song
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -200,6 +200,8 @@ impl Song {
|
|||
self.set_song(&song);
|
||||
self.set_position(position);
|
||||
self.set_playlist_pos(window.playlist_pos());
|
||||
|
||||
song.need_thumbnail(window);
|
||||
}
|
||||
|
||||
pub fn unbind(&self) {}
|
||||
|
|
|
@ -394,7 +394,7 @@ mod imp {
|
|||
Rc::clone(api.as_ref().unwrap())
|
||||
};
|
||||
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
|
||||
.command(["loadfile", &song.stream_url(), "append-play"])
|
||||
.unwrap();
|
||||
|
|
Loading…
Reference in a new issue