From d91f9453757418b1b17c834dd07961a3709598e9 Mon Sep 17 00:00:00 2001 From: Erica Z Date: Thu, 17 Oct 2024 22:36:29 +0200 Subject: [PATCH] fix cover art --- src/ui/window.vala | 48 ++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/src/ui/window.vala b/src/ui/window.vala index 3fe17d1..6ba084d 100644 --- a/src/ui/window.vala +++ b/src/ui/window.vala @@ -57,6 +57,29 @@ class Ui.Window : Adw.ApplicationWindow { this.playbin.now_playing.connect (() => { api.scrobble.begin (playbin.song.id); this.play_queue.selection.playbin_select (playbin.play_queue_position); + + if (this.cancel_loading_art != null) { + this.cancel_loading_art.cancel (); + } + this.cancel_loading_art = new GLib.Cancellable (); + + this.playing_cover_art = Gdk.Paintable.empty (1, 1); + if (playbin.song != null) { + this.cover_art_loading = true; + + string song_id = playbin.song.id; + this.api.cover_art.begin (song_id, this.cancel_loading_art, (obj, res) => { + try { + this.playing_cover_art = Gdk.Texture.for_pixbuf (this.api.cover_art.end (res)); + this.cover_art_loading = false; + } catch (Error e) { + if (!(e is IOError.CANCELLED)) { + warning ("could not load cover for %s: %s", song_id, e.message); + this.cover_art_loading = false; + } + } + }); + } }); this.play_queue.selection.user_selected.connect ((position) => { @@ -84,31 +107,6 @@ class Ui.Window : Adw.ApplicationWindow { this.setup.load (); this.sidebar.select_row (this.sidebar.get_row_at_index (0)); - - this.playbin.notify["current-song"].connect (() => { - if (this.cancel_loading_art != null) { - this.cancel_loading_art.cancel (); - } - this.cancel_loading_art = new GLib.Cancellable (); - - this.playing_cover_art = Gdk.Paintable.empty (1, 1); - if (playbin.song != null) { - this.cover_art_loading = true; - - string song_id = playbin.song.id; - this.api.cover_art.begin (song_id, this.cancel_loading_art, (obj, res) => { - try { - this.playing_cover_art = Gdk.Texture.for_pixbuf (this.api.cover_art.end (res)); - this.cover_art_loading = false; - } catch (Error e) { - if (!(e is IOError.CANCELLED)) { - warning ("could not load cover for %s: %s", song_id, e.message); - this.cover_art_loading = false; - } - } - }); - } - }); } [GtkCallback] private void on_sidebar_row_activated (Gtk.ListBoxRow row) {