deblur thumbnails

This commit is contained in:
Erica Z 2024-11-13 16:58:31 +01:00
parent d37ec6a19a
commit 418cf01884
2 changed files with 6 additions and 5 deletions

View file

@ -64,7 +64,6 @@ use crate::subsonic;
use adw::{prelude::*, subclass::prelude::*};
use glib::Object;
use gtk::{gdk, glib};
use std::rc::Rc;
glib::wrapper! {
pub struct Song(ObjectSubclass<imp::Song>);
@ -72,10 +71,11 @@ glib::wrapper! {
impl Song {
pub fn from_child(
api: &Rc<subsonic::Client>,
window: &crate::ui::Window,
song: &subsonic::schema::Child,
load_thumbnail: bool,
) -> Self {
let api = window.api();
let song: Song = Object::builder()
.property("id", &song.id)
.property("title", &song.title)
@ -88,14 +88,15 @@ impl Song {
.build();
if load_thumbnail {
let api = Rc::clone(api);
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 bytes = api
.cover_art(&id, Some(50)) // TODO: WidgetExt::scale_factor
.cover_art(&id, Some(50 * scale_factor)) // see pixel-size in
// play_queue_song.blp
.await
.unwrap();
let song = match song_weak.upgrade() {

View file

@ -301,7 +301,7 @@ mod imp {
Rc::clone(api.as_ref().unwrap())
};
for song in api.random_songs(10).await.unwrap().into_iter() {
let song = Song::from_child(&api, &song, true);
let song = Song::from_child(&self.obj(), &song, true);
self.mpv
.command(["loadfile", &song.stream_url(), "append-play"])
.unwrap();