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,13 +88,17 @@ 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 {
|
song
|
||||||
let id = song.id();
|
}
|
||||||
let song_weak = song.downgrade();
|
|
||||||
|
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
|
let scale_factor = window.scale_factor() as u32; // NOTE: assumed constant
|
||||||
song.imp()
|
*thumbnail_loading = Some(glib::spawn_future_local(async move {
|
||||||
.thumbnail_loading
|
|
||||||
.replace(Some(glib::spawn_future_local(async move {
|
|
||||||
let _permit = SEM.acquire().await.unwrap();
|
let _permit = SEM.acquire().await.unwrap();
|
||||||
|
|
||||||
let bytes = match api
|
let bytes = match api
|
||||||
|
@ -122,9 +122,7 @@ impl Song {
|
||||||
song.set_thumbnail(
|
song.set_thumbnail(
|
||||||
gdk::Texture::from_bytes(&glib::Bytes::from_owned(bytes)).unwrap(),
|
gdk::Texture::from_bytes(&glib::Bytes::from_owned(bytes)).unwrap(),
|
||||||
);
|
);
|
||||||
})));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
song
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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