From 7be67f223d008e8b77b1ae1c8e583777fb805ee4 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Thu, 15 Aug 2024 09:28:49 +0200 Subject: [PATCH] Fix playlist deletion error Caused by the notification system still notifying the playlist view, as it did not unsubscribe from the notifications The register callback now returns a shorthand function to unsubscribe from the call. As long as the screen can only be opened once, this can be called multiple times. --- melon/models/callbacks.py | 1 + melon/playlist/__init__.py | 10 +++++++++- melon/widgets/feeditem.py | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/melon/models/callbacks.py b/melon/models/callbacks.py index a28976b..2ea2c7b 100644 --- a/melon/models/callbacks.py +++ b/melon/models/callbacks.py @@ -34,6 +34,7 @@ def register_callback(target: str, callback_id: str, function): if not target in callbacks: return callbacks[target][callback_id] = function + return lambda: unregister_callback(target, callback_id) def unregister_callback(target: str, callback_id: str): diff --git a/melon/playlist/__init__.py b/melon/playlist/__init__.py index c0a1b4a..c64b8c1 100644 --- a/melon/playlist/__init__.py +++ b/melon/playlist/__init__.py @@ -37,10 +37,16 @@ class LocalPlaylistScreen(Adw.NavigationPage): self.playlist_id = playlist_id # register update listener - register_callback("playlists_changed", "playlist-view", self.do_update) + self.unregister = register_callback( + "playlists_changed", "playlist-view", self.do_update + ) + self.connect("hidden", self.on_close) # draw frame self.do_update() + def on_close(self, k): + self.unregister() + def do_update(self): # load playlist data self.playlist = get_local_playlist(self.playlist_id) @@ -320,6 +326,8 @@ class LocalPlaylistScreen(Adw.NavigationPage): self.dlt_diag.show() def delete(self): + # make sure that this widget does not receive an update notification + self.unregister() # go home and delete afterwards # so that the reload/callback doesn't trigger self.activate_action("win.home", None) diff --git a/melon/widgets/feeditem.py b/melon/widgets/feeditem.py index 7678028..1f73d50 100644 --- a/melon/widgets/feeditem.py +++ b/melon/widgets/feeditem.py @@ -18,6 +18,7 @@ from melon.utils import pass_me, many # [url]: texture preview_cache = {} + class AdaptiveFeedItem(Adw.ActionRow): """ FeedItem with automatic adjustment to resource type -- 2.38.5