From d0861460fd6f0937fc593e8a0aa45ee587a3efe7 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Sun, 9 Jan 2022 00:40:24 +1100 Subject: [PATCH] Fix crashes when batch downloading The callbacks from AdapterManager.batch_download_songs happen on a separate thread, which means any GTK-related functions must be avoided. --- sublime_music/ui/artists.py | 16 ++++++++++------ sublime_music/ui/browse.py | 2 +- sublime_music/ui/common/album_with_songs.py | 6 +++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/sublime_music/ui/artists.py b/sublime_music/ui/artists.py index 599a688..1499efa 100644 --- a/sublime_music/ui/artists.py +++ b/sublime_music/ui/artists.py @@ -465,13 +465,17 @@ class ArtistDetailPanel(Gtk.Box): def on_download_all_click(self, _): AdapterManager.batch_download_songs( self.get_artist_song_ids(), - before_download=lambda _: self.update_artist_view( - self.artist_id, - order_token=self.update_order_token, + before_download=lambda _: GLib.idle_add( + lambda: self.update_artist_view( + self.artist_id, + order_token=self.update_order_token, + ) ), - on_song_download_complete=lambda _: self.update_artist_view( - self.artist_id, - order_token=self.update_order_token, + on_song_download_complete=lambda _: GLib.idle_add( + lambda: self.update_artist_view( + self.artist_id, + order_token=self.update_order_token, + ) ), ) diff --git a/sublime_music/ui/browse.py b/sublime_music/ui/browse.py index f42c660..8b6d238 100644 --- a/sublime_music/ui/browse.py +++ b/sublime_music/ui/browse.py @@ -440,7 +440,7 @@ class MusicDirectoryList(Gtk.Box): self.loading_indicator.hide() def on_download_state_change(self, _): - self.update() + GLib.idle_add(self.update) # Create Element Helper Functions # ================================================================================== diff --git a/sublime_music/ui/common/album_with_songs.py b/sublime_music/ui/common/album_with_songs.py index a3d416b..2b8fe72 100644 --- a/sublime_music/ui/common/album_with_songs.py +++ b/sublime_music/ui/common/album_with_songs.py @@ -206,7 +206,7 @@ class AlbumWithSongs(Gtk.Box): allow_deselect = False def on_download_state_change(song_id: str): - self.update_album_songs(self.album.id) + GLib.idle_add(lambda: self.update_album_songs(self.album.id)) # Use the new selection instead of the old one for calculating what # to do the right click on. @@ -238,8 +238,8 @@ class AlbumWithSongs(Gtk.Box): def on_download_all_click(self, btn: Any): AdapterManager.batch_download_songs( [x[-1] for x in self.album_song_store], - before_download=lambda _: self.update(), - on_song_download_complete=lambda _: self.update(), + before_download=lambda _: GLib.idle_add(self.update), + on_song_download_complete=lambda _: GLib.idle_add(self.update), ) def play_btn_clicked(self, btn: Any):